Skip to content

Commit f116061

Browse files
committed
use "t[#t +1] = v" instead "table.insert(t, v)"
1 parent d9b59f3 commit f116061

12 files changed

Lines changed: 69 additions & 84 deletions

File tree

‎CSharp.lua/CoreSystem.Lua/CoreSystem/Collection.lua‎

Lines changed: 13 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -133,23 +133,23 @@ function Collection.setArray(t, index, v)
133133
end
134134

135135
function Collection.pushArray(t, v)
136-
tinsert(t, wrap(v))
136+
t[#t + 1] = wrap(v)
137137
changeVersion(t)
138138
end
139139

140140
function Collection.buildArray(t, size, ...)
141141
local len = select("#", ...)
142142
for i = 1, len do
143-
local v = select(i, ...)
144-
tinsert(t, wrap(v))
143+
local v = select(i, ...)
144+
t[#t + 1] = wrap(v)
145145
end
146146
if len < size then
147147
local default = t.__genericT__:__default__()
148148
if default == nil then
149149
default = null
150150
end
151151
for i = len + 1, size do
152-
tinsert(t, default)
152+
t[#t +1] = default
153153
end
154154
end
155155
end
@@ -468,7 +468,7 @@ local function sortArray(t, index, count, comparer)
468468
checkIndexAndCount(t, index, count)
469469
local arr = {}
470470
for i = index + 1, index + count do
471-
tinsert(arr, t[i])
471+
arr[#arr + 1] = t[i]
472472
end
473473
tsort(arr, comp)
474474
for i = index + 1, index + count do
@@ -616,11 +616,11 @@ function Collection.toArray(t)
616616
local array = {}
617617
if isArrayLike(t) then
618618
for _, v in ipairs(t) do
619-
tinsert(array, v)
619+
array[#array + 1] = v
620620
end
621621
else
622622
for _, v in each(t) do
623-
tinsert(array, wrap(v))
623+
array[#array + 1] = wrap(v)
624624
end
625625
end
626626
return System.arrayFromTable(array, t.__genericT__)
@@ -649,17 +649,16 @@ KeyValuePair = System.defStc("System.KeyValuePair", {
649649
return this.Key, this.Value
650650
end,
651651
ToString = function (this)
652-
local t = {}
653-
tinsert(t, "[")
652+
local t = { "[" }
654653
local k, v = this.Key, this.Value
655654
if k ~= nil then
656-
tinsert(t, k:ToString())
655+
t[#t + 1] = k:ToString()
657656
end
658-
tinsert(t, ", ")
657+
t[#t + 1] = ", "
659658
if v ~= nil then
660-
tinsert(t, v:ToString())
659+
t[#t + 1] = v:ToString()
661660
end
662-
tinsert(t, "]")
661+
t[#t + 1] = "]"
663662
return tconcat(t)
664663
end
665664
})
@@ -747,7 +746,7 @@ local function yieldCoroutineCreate(f)
747746
f(...)
748747
while true do
749748
f = nil
750-
tinsert(yieldCoroutinePool, co)
749+
yieldCoroutinePool[#yieldCoroutinePool + 1] = co
751750
f = cyield(yieldCoroutineExit)
752751
f(cyield())
753752
end

‎CSharp.lua/CoreSystem.Lua/CoreSystem/Collections/Linq.lua‎

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,6 @@ local Empty = System.Array.Empty
3535

3636
local assert = assert
3737
local select = select
38-
local tinsert = table.insert
3938
local getmetatable = getmetatable
4039

4140
local InternalEnumerable = System.define("System.Linq.InternalEnumerable", {
@@ -310,7 +309,7 @@ local function addToLookup(this, key, value)
310309
group = this.groups[groupIndex]
311310
assert(group)
312311
end
313-
tinsert(group, wrap(value))
312+
group[#group + 1] = wrap(value)
314313
end
315314

316315
local function createLookup(source, keySelector, elementSelector, comparer, TKey, TElement)
@@ -392,7 +391,7 @@ local function ordered(source, compare)
392391
end,
393392
function()
394393
for _, v in each(source) do
395-
tinsert(t, wrap(v))
394+
t[#t + 1] = wrap(v)
396395
end
397396
sort(t, compare)
398397
end)
@@ -690,7 +689,7 @@ function Enumerable.Reverse(source)
690689
end,
691690
function()
692691
for _, v in each(source) do
693-
tinsert(t, wrap(v))
692+
t[#t + 1] = wrap(v)
694693
end
695694
index = #t + 1
696695
end)
@@ -1121,4 +1120,4 @@ function Enumerable.Max(source, ...)
11211120
return compare(x, y) > 0
11221121
end
11231122
return minOrMax(maxFn, source, ...)
1124-
end
1123+
end

‎CSharp.lua/CoreSystem.Lua/CoreSystem/Core.lua‎

Lines changed: 11 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@ local ipairs = ipairs
2121
local pairs = pairs
2222
local assert = assert
2323
local table = table
24-
local tinsert = table.insert
2524
local tremove = table.remove
2625
local tconcat = table.concat
2726
local tunpack = table.unpack
@@ -139,21 +138,18 @@ local function genericKey(t, k, ...)
139138
end
140139

141140
local function genericName(name, ...)
142-
local t = {}
143-
tinsert(t, name)
144-
tinsert(t, "[")
145-
141+
local t = { name, "[" }
146142
local hascomma
147143
for i = 1, select("#", ...) do
148-
local cls = select(i, ...)
149-
if hascomma then
150-
tinsert(t, ",")
151-
else
152-
hascomma = true
153-
end
154-
tinsert(t, cls.__name__)
144+
local cls = select(i, ...)
145+
if hascomma then
146+
t[#t + 1] = ","
147+
else
148+
hascomma = true
149+
end
150+
t[#t + 1] = cls.__name__
155151
end
156-
tinsert(t, "]")
152+
t[#t + 1] = "]"
157153
return tconcat(t)
158154
end
159155

@@ -1095,14 +1091,14 @@ function System.stackalloc(arrayType, len)
10951091
end
10961092

10971093
function System.usingDeclare(f)
1098-
tinsert(usings, f)
1094+
usings[#usings + 1] = f
10991095
end
11001096

11011097
function System.init(namelist, conf)
11021098
local classes = {}
11031099
for _, name in ipairs(namelist) do
11041100
local cls = assert(modules[name], name)()
1105-
tinsert(classes, cls)
1101+
classes[#classes + 1] = cls
11061102
end
11071103
for _, f in ipairs(usings) do
11081104
f(global)

‎CSharp.lua/CoreSystem.Lua/CoreSystem/Enum.lua‎

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,6 @@ local ArgumentException = System.ArgumentException
2424

2525
local pairs = pairs
2626
local tostring = tostring
27-
local tinsert = table.insert
2827

2928
local Enum = {}
3029

@@ -70,7 +69,7 @@ function Enum.GetNames(enumType)
7069
if not enumType:getIsEnum() then throw(ArgumentException("Arg_MustBeEnum")) end
7170
local t = {}
7271
for k, v in pairs(enumType.c) do
73-
tinsert(t, k)
72+
t[#t + 1] = k
7473
end
7574
return System.arrayFromTable(t, System.String)
7675
end
@@ -80,7 +79,7 @@ function Enum.GetValues(enumType)
8079
if not enumType:getIsEnum() then throw(ArgumentException("Arg_MustBeEnum")) end
8180
local t = {}
8281
for k, v in pairs(enumType.c) do
83-
tinsert(t, v)
82+
t[#t + 1] = v
8483
end
8584
return System.arrayFromTable(t, Int)
8685
end
@@ -124,4 +123,4 @@ function Enum.TryParse(TEnum, value, ignoreCase)
124123
return true, result
125124
end
126125

127-
System.define("System.Enum", Enum)
126+
System.define("System.Enum", Enum)

‎CSharp.lua/CoreSystem.Lua/CoreSystem/Exception.lua‎

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -20,22 +20,20 @@ local Object = System.Object
2020

2121
local traceback = debug.traceback
2222
local tconcat = table.concat
23-
local tinsert = table.insert
2423

2524
local function toString(this)
26-
local t = {}
25+
local t = { this.__name__ }
2726
local message, innerException, stackTrace = this.message, this.innerException, this.errorStack
28-
tinsert(t, this.__name__)
2927
if message ~= nil and #message > 0 then
30-
tinsert(t, ": ")
31-
tinsert(t, message)
28+
t[#t + 1] = ": "
29+
t[#t + 1] = message
3230
end
3331
if innerException then
34-
tinsert(t, "---> ")
35-
tinsert(t, innerException:ToString())
32+
t[#t + 1] = "---> "
33+
t[#t + 1] = innerException:ToString()
3634
end
3735
if stackTrace then
38-
tinsert(t, stackTrace)
36+
t[#t + 1] = stackTrace
3937
end
4038
return tconcat(t)
4139
end
@@ -258,4 +256,4 @@ define("System.TypeLoadException", {
258256
__ctor__ = function(this, message, innerException)
259257
Exception.__ctor__(this, message or "Failed when load type.", innerException)
260258
end
261-
})
259+
})

‎CSharp.lua/CoreSystem.Lua/CoreSystem/IO/File.lua‎

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@ local each = System.each
2020

2121
local io = io
2222
local open = io.open
23-
local tinsert = table.insert
2423

2524
local IOException = System.define("System.IO.IOException", {
2625
__tostring = System.Exception.ToString,
@@ -58,7 +57,7 @@ end
5857
function File.ReadAllLines(path)
5958
local t = {}
6059
for line in io.lines(path) do
61-
tinsert(t, line)
60+
t[#t + 1] = line
6261
end
6362
return System.arrayFromTable(t, System.String)
6463
end
@@ -95,4 +94,4 @@ function File.Exists(path)
9594
return file ~= nil
9695
end
9796

98-
System.define("System.IO.File", File)
97+
System.define("System.IO.File", File)

‎CSharp.lua/CoreSystem.Lua/CoreSystem/Reflection/Assembly.lua‎

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,6 @@ local assert = assert
2929
local unpack = table.unpack
3030
local pairs = pairs
3131
local ipairs = ipairs
32-
local tinsert = table.insert
3332

3433
local Assembly = {}
3534

@@ -60,7 +59,7 @@ function Assembly.GetExportedTypes(this)
6059
for _, cls in ipairs(System.classes) do
6160
local type_ = type(cls)
6261
if type_ == "table" then
63-
tinsert(t, typeof(cls))
62+
t[#t + 1] = typeof(cls)
6463
else
6564
assert(type_ == "function");
6665
end
@@ -188,7 +187,7 @@ function Type.GetMethods(this)
188187
for k, v in pairs(cls) do
189188
if type(v) == "function" then
190189
local methodInfo = buildMethodInfo(cls, k, v)
191-
tinsert(t, methodInfo)
190+
t[#t + 1] = methodInfo
192191
end
193192
end
194193
cls = getmetatable(cls)
@@ -301,11 +300,11 @@ function Type.GetMembers(this)
301300
for k, v in pairs(cls) do
302301
if type(v) == "function" then
303302
local methodInfo = buildMethodInfo(cls, k, v)
304-
tinsert(t, methodInfo)
303+
t[#t + 1] = methodInfo
305304
names[k] = true;
306305
else
307306
local fieldInfo = buildFieldInfo(cls, k)
308-
tinsert(t, fieldInfo)
307+
t[#t + 1] = fieldInfo
309308
names[k] = true;
310309
end
311310
end
@@ -314,7 +313,7 @@ function Type.GetMembers(this)
314313
for k , v in pairs(attributes) do
315314
if not names[k] then
316315
local fieldInfo = buildFieldInfo(cls, k)
317-
tinsert(t, fieldInfo)
316+
t[#t + 1] = fieldInfo
318317
names[k] = true;
319318
end
320319
end

‎CSharp.lua/CoreSystem.Lua/CoreSystem/String.lua‎

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,6 @@ local smatch = string.match
3434
local sgsub = string.gsub
3535

3636
local table = table
37-
local tinsert = table.insert
3837
local tconcat = table.concat
3938
local unpack = table.unpack
4039
local setmetatable = setmetatable
@@ -155,15 +154,15 @@ function String.Concat(...)
155154
local v = ...
156155
if System.isEnumerableLike(v) then
157156
for _, v in System.each(array) do
158-
tinsert(t, v:ToString())
157+
t[#t + 1] = v:ToString()
159158
end
160159
else
161160
return v:ToString()
162161
end
163162
else
164163
for i = 1, len do
165164
local v = select(i, ...)
166-
tinsert(t, v:ToString())
165+
t[#t + 1] = v:ToString()
167166
end
168167
end
169168
return tconcat(t)
@@ -176,14 +175,14 @@ function String.Join(separator, value, startIndex, count)
176175
for i = startIndex + 1, startIndex + count do
177176
local v = value:get(i)
178177
if v ~= nil then
179-
tinsert(t, v)
178+
t[#t + 1] = v
180179
end
181180
end
182181
else
183182
for _, v in System.each(value) do
184183
if v ~= nil then
185-
tinsert(t, v)
186-
end
184+
t[#t + 1] = v
185+
end
187186
end
188187
end
189188
return tconcat(t, separator)
@@ -313,7 +312,7 @@ function String.ToCharArray(str, startIndex, count)
313312
startIndex, count = check(str, startIndex, count)
314313
local t = { }
315314
for i = startIndex + 1, startIndex + count do
316-
tinsert(t, sbyte(str, i))
315+
t[#t + 1] = sbyte(str, i)
317316
end
318317
return System.arrayFromTable(t, System.Char)
319318
end
@@ -389,7 +388,7 @@ function String.Split(this, strings, count, options)
389388
posBegin = posBegin or 0
390389
local subStr = ssub(this, startIndex, posBegin -1)
391390
if options ~= 1 or #subStr > 0 then
392-
tinsert(t, subStr)
391+
t[#t + 1] = subStr
393392
if count then
394393
count = count -1
395394
if count == 0 then
@@ -446,4 +445,4 @@ function String.__inherits__()
446445
end
447446

448447
System.define("System.String", String)
449-
setmetatable(String, { __index = System.Object, __call = ctor })
448+
setmetatable(String, { __index = System.Object, __call = ctor })

0 commit comments

Comments
 (0)