@@ -371,11 +371,10 @@ end
371371
372372local function binarySearch (t , ...)
373373 if t == nil then throw (ArgumentNullException (" array" )) end
374- local len = # t
375374 local index , count , v , comparer
376375 local n = select (" #" , ... )
377376 if n == 1 or n == 2 then
378- index , count , v , comparer = 0 , len , ...
377+ index , count , v , comparer = 0 , # t , ...
379378 else
380379 index , count , v , comparer = ...
381380 end
@@ -385,7 +384,7 @@ local function binarySearch(t, ...)
385384 compare = comparer
386385 elseif comparer == nil then
387386 comparer = Comparer_1 (t .__genericT__ ).getDefault ()
388- compare = comparer .Compare
387+ compare = comparer .Compare
389388 else
390389 compare = comparer .Compare
391390 end
@@ -424,7 +423,7 @@ local function getSortComp(t, comparer)
424423 local Compare = comparer .Compare
425424 compare = function (x , y ) return Compare (comparer , x , y ) end
426425 end
427- return function (x , y )
426+ return function (x , y )
428427 if x == null then x = nil end
429428 if y == null then y = nil end
430429 return compare (x , y ) < 0
@@ -466,24 +465,25 @@ end
466465
467466local function exceptWithOrder (t , other )
468467 if other == nil then throw (ArgumentNullException (" other" )) end
469- if # t == 0 then return end
468+ local n = # t
469+ if n == 0 then return end
470470 if t == other then
471471 clear (t )
472472 return
473473 end
474- local comparer , n = t .comparer , # t
474+ local comparer = t .comparer
475475 if other .GetEnumerator == arrayEnumerator then
476- for i = 1 , n do
477- local v = t [i ]
476+ for i = 1 , # other do
477+ local v = other [i ]
478478 if v == null then v = nil end
479- local i = binarySearch (t , v , comparer )
480- if i >= 0 then
481- tremove (t , i + 1 )
479+ local j = binarySearch (t , 0 , n , v , comparer )
480+ if j >= 0 then
481+ tremove (t , j + 1 )
482482 end
483483 end
484484 else
485485 for _ , v in each (other ) do
486- local i = binarySearch (t , v , comparer )
486+ local i = binarySearch (t , 0 , n , v , comparer )
487487 if i >= 0 then
488488 tremove (t , i + 1 )
489489 end
@@ -496,12 +496,13 @@ end
496496
497497local function intersectWithOrder (t , other )
498498 if other == nil then throw (ArgumentNullException (" other" )) end
499- if # t == 0 then return end
499+ local n = # t
500+ if n == 0 then return end
500501 if t == other then return end
501502 local comparer = t .comparer
502503 local array = arrayFromTable ({}, t .__genericT__ )
503504 for _ , v in each (other ) do
504- local i = binarySearch (t , v , comparer )
505+ local i = binarySearch (t , 0 , n , v , comparer )
505506 if i >= 0 then
506507 array [# array + 1 ] = v == nil and null or v
507508 end
@@ -510,11 +511,12 @@ local function intersectWithOrder(t, other)
510511 addOrderRange (t , array )
511512end
512513
513- local function isSubsetOfOrderWithSameEC (t , n , comparer , set )
514+ local function isSubsetOfOrderWithSameEC (t , n , comparer , t1 )
515+ local n1 = # t1
514516 for i = 1 , n do
515517 local v = t [i ]
516518 if v == null then v = nil end
517- local j = binarySearch (set , v , comparer )
519+ local j = binarySearch (t1 , 0 , n1 , v , comparer )
518520 if j < 0 then
519521 return false
520522 end
@@ -556,7 +558,7 @@ local function isProperSubsetOfOrder(t, other)
556558 if System .is (other , System .SortedSet (t .__genericT__ )) then
557559 if comparer == other .comparer then
558560 if n >= # other then return false end
559- return isSubsetOfOrderWithSameEC (t , n , comparer , set )
561+ return isSubsetOfOrderWithSameEC (t , n , comparer , other )
560562 end
561563 end
562564 local uniqueCount , unfoundCount = checkOrderUniqueAndUnfoundElements (t , n , comparer , other )
@@ -676,6 +678,7 @@ local function symmetricExceptWithOrder(t, other)
676678 clear (t )
677679 return
678680 end
681+ local comparer = t .comparer
679682 for _ , v in each (other ) do
680683 local i = binarySearch (t , v , comparer )
681684 if i >= 0 then
@@ -701,11 +704,11 @@ local function checkOrderDictKeyValueObj(t, k, v)
701704 local TValue = t .__genericTValue__
702705 if v == nil and TValue :default () ~= nil then throw (ArgumentNullException (" value" )) end
703706 local TKey = t .__genericTKey__
704- if not System .is (k , TKey ) then
705- throw (ArgumentException (er .Arg_WrongType (k , TKey .__name__ ), " key" ))
707+ if not System .is (k , TKey ) then
708+ throw (ArgumentException (er .Arg_WrongType (k , TKey .__name__ ), " key" ))
706709 end
707710 if not System .is (v , TValue ) then
708- throw (ArgumentException (er .Arg_WrongType (v , TValue .__name__ ), " value" ))
711+ throw (ArgumentException (er .Arg_WrongType (v , TValue .__name__ ), " value" ))
709712 end
710713end
711714
@@ -757,15 +760,15 @@ local function getViewBetweenOrder(t, lowerValue, upperValue)
757760 local n = # t
758761 local i = binarySearch (t , lowerValue , comparer )
759762 if i < 0 then i = bnot (i ) end
760- local set = { comparer = comparer }
763+ local s = { comparer = comparer }
761764 if i < n then
762765 local j = binarySearch (t , upperValue , comparer )
763766 if j < 0 then j = bnot (j ) - 1 end
764767 if i <= j then
765- tmove (t , i + 1 , j + 1 , 1 , set )
768+ tmove (t , i + 1 , j + 1 , 1 , s )
766769 end
767770 end
768- return setmetatable (set , System .SortedSet (t .__genericT__ ))
771+ return setmetatable (s , System .SortedSet (t .__genericT__ ))
769772end
770773
771774local function heapDown (t , k , n , c )
801804local function heapify (t , c )
802805 local n = # t
803806 for i = div (n , 2 ), 1 , - 1 do
804- heapDown (t , i , n , c )
807+ heapDown (t , i , n , c )
805808 end
806809end
807810
@@ -828,16 +831,16 @@ local SortedSetEqualityComparer = {
828831 this .comparer = comparer or Comparer_1 (T ).getDefault ()
829832 this .equalityComparer = equalityComparer or EqualityComparer (T ).getDefault ()
830833 end ,
831- EqualsOf = function (this , x , y )
834+ EqualsOf = function (_ , x , y )
832835 if x == nil then return y == nil end
833836 if y == nil then return false end
834837 return equalsOrder (x , y )
835838 end ,
836- GetHashCodeOf = function (this , set )
839+ GetHashCodeOf = function (this , t )
837840 local hashCode = 0
838- if set ~= nil then
839- for i = 1 , # set do
840- local v = set [i ]
841+ if t ~= nil then
842+ for i = 1 , # t do
843+ local v = t [i ]
841844 if v == null then v = nil end
842845 hashCode = System .xor (hashCode , System .band (this .equalityComparer :GetHashCodeOf (v ), 0x7FFFFFFF ))
843846 end
@@ -867,7 +870,7 @@ local ArrayEnumerator = define("System.ArrayEnumerator", function (T)
867870 base = { IEnumerator_1 (T ) }
868871 }
869872end , {
870- getCurrent = System .getCurrent ,
873+ getCurrent = System .getCurrent ,
871874 Dispose = System .emptyFn ,
872875 Reset = function (this )
873876 this .index = 1
@@ -899,7 +902,7 @@ arrayEnumerator = function (t, T)
899902 return setmetatable ({ list = t , index = 1 , version = versions [t ], currnet = T :default () }, ArrayEnumerator (T ))
900903end
901904
902- local ArrayReverseEnumerable
905+ local ArrayReverseEnumerable
903906
904907local function reverseEnumerator (t )
905908 local T = t .__genericT__
@@ -911,7 +914,7 @@ ArrayReverseEnumerable = define("System.ArrayReverseEnumerable", function (T)
911914 base = { IEnumerable_1 (T ), IEnumerator_1 (T ) }
912915 }
913916end , {
914- getCurrent = System .getCurrent ,
917+ getCurrent = System .getCurrent ,
915918 Dispose = System .emptyFn ,
916919 GetEnumerator = function (this )
917920 return reverseEnumerator (this .list )
@@ -1030,7 +1033,7 @@ Array = {
10301033 addPairOrderDict = function (t , ...)
10311034 local k , v
10321035 if select (" #" , ... ) == 1 then
1033- local pair = ...
1036+ local pair = ...
10341037 k , v = pair [1 ], pair [2 ]
10351038 else
10361039 k , v = ...
@@ -1080,7 +1083,7 @@ Array = {
10801083 tinsert (t , index + 1 , v == nil and null or v )
10811084 versions [t ] = (versions [t ] or 0 ) + 1
10821085 end ,
1083- insertRange = function (t , index , collection )
1086+ insertRange = function (t , index , collection )
10841087 if collection == nil then throw (ArgumentNullException (" collection" )) end
10851088 local len = # t
10861089 if index < 0 or index > len then
@@ -1226,9 +1229,9 @@ Array = {
12261229 local i = getOrderDictIndex (t , p [1 ])
12271230 if i >= 0 then
12281231 local v = t [i + 1 ][2 ]
1229- local comparer = EqualityComparer (this .__genericTValue__ ).getDefault ()
1232+ local comparer = EqualityComparer (t .__genericTValue__ ).getDefault ()
12301233 if comparer :EqualsOf (p [2 ], v ) then
1231- tremove (this , i )
1234+ tremove (t , i )
12321235 return true
12331236 end
12341237 end
@@ -1264,7 +1267,7 @@ Array = {
12641267 local i = getOrderDictIndex (t , k )
12651268 if i < 0 then i = - 1 end
12661269 return i
1267- end ,
1270+ end ,
12681271 indexOfValue = function (t , v )
12691272 local len = # t
12701273 if len > 0 then
@@ -1307,11 +1310,11 @@ Array = {
13071310 return indexOf (t , v ) ~= - 1
13081311 end ,
13091312 Copy = function (t , ...)
1310- local len = select (" #" , ... )
1313+ local len = select (" #" , ... )
13111314 if len == 2 then
13121315 local array , length = ...
13131316 copy (t , 0 , array , 0 , length )
1314- else
1317+ else
13151318 copy (t , ... )
13161319 end
13171320 end ,
@@ -1497,7 +1500,7 @@ Array = {
14971500 end
14981501 end ,
14991502 toArray = function (t )
1500- local array = {}
1503+ local array = {}
15011504 if t .GetEnumerator == arrayEnumerator then
15021505 tmove (t , 1 , # t , 1 , array )
15031506 else
@@ -1563,7 +1566,7 @@ Array = {
15631566 if dimension ~= 0 then throw (IndexOutOfRangeException ()) end
15641567 return # this
15651568 end ,
1566- GetLowerBound = function (this , dimension )
1569+ GetLowerBound = function (_ , dimension )
15671570 if dimension ~= 0 then throw (IndexOutOfRangeException ()) end
15681571 return 0
15691572 end ,
@@ -1578,11 +1581,6 @@ Array = {
15781581 SetValue = function (this , value , index1 , index2 )
15791582 if index1 == nil then throw (ArgumentNullException (" indices" )) end
15801583 set (this , checkArrayIndex (index1 , index2 ), System .castWithNullable (this .__genericT__ , value ))
1581- end ,
1582- Clone = function (this )
1583- local array = {}
1584- tmove (this , 1 , # this , 1 , array )
1585- return arrayFromTable (array , this .__genericT__ )
15861584 end
15871585}
15881586
@@ -1630,7 +1628,7 @@ local function checkMultiArrayIndex(t, index1, ...)
16301628 return getIndex (t , index1 , ... )
16311629end
16321630
1633- local MultiArray = {
1631+ local MultiArray = {
16341632 set = function (this , ...)
16351633 local index , len = getIndex (this , ... )
16361634 set (this , index , select (len + 1 , ... ))
@@ -1680,9 +1678,9 @@ function MultiArray.__call(T, rank, t)
16801678 return t
16811679end
16821680
1683- System .defArray (" System.Array" , function (T )
1684- return {
1685- base = { System .ICloneable , System .IList_1 (T ), System .IReadOnlyList_1 (T ), System .IList },
1681+ System .defArray (" System.Array" , function (T )
1682+ return {
1683+ base = { System .ICloneable , System .IList_1 (T ), System .IReadOnlyList_1 (T ), System .IList },
16861684 __genericT__ = T
16871685 }
16881686end , Array , MultiArray )
@@ -1718,7 +1716,7 @@ YieldEnumerable = define("System.YieldEnumerable", function (T)
17181716 __genericT__ = T
17191717 }
17201718end , {
1721- getCurrent = System .getCurrent ,
1719+ getCurrent = System .getCurrent ,
17221720 Dispose = System .emptyFn ,
17231721 GetEnumerator = function (this )
17241722 return setmetatable ({ f = this .f , args = this .args }, YieldEnumerable (this .__genericT__ ))
@@ -1728,7 +1726,7 @@ end, {
17281726 if c == false then
17291727 return false
17301728 end
1731-
1729+
17321730 local ok , v
17331731 if c == nil then
17341732 c = createCoroutine (this .f )
@@ -1739,7 +1737,7 @@ end, {
17391737 else
17401738 ok , v = cresume (c )
17411739 end
1742-
1740+
17431741 if ok then
17441742 if v == cpool then
17451743 this .c = false
@@ -1791,8 +1789,8 @@ local ReadOnlyCollection = {
17911789}
17921790
17931791define (" System.ReadOnlyCollection" , function (T )
1794- return {
1795- base = { System .IList_1 (T ), System .IList , System .IReadOnlyList_1 (T ) },
1792+ return {
1793+ base = { System .IList_1 (T ), System .IList , System .IReadOnlyList_1 (T ) },
17961794 __genericT__ = T
17971795 }
17981796end , ReadOnlyCollection , 1 )
0 commit comments