Performance optimisations:
authorSteven Barth <steven@midlink.org>
Tue, 9 Sep 2008 12:44:41 +0000 (12:44 +0000)
committerSteven Barth <steven@midlink.org>
Tue, 9 Sep 2008 12:44:41 +0000 (12:44 +0000)
In-line expressions are faster than function calls

libs/core/luasrc/ltn12.lua
libs/core/luasrc/util.lua
libs/uci/luasrc/model/uci.lua
libs/web/luasrc/template.lua

index c9b663463f0e990a2381e48711b8939ce9692f79..9371290c61778ee4f3e5bb23c46d9796190e89b3 100644 (file)
@@ -190,7 +190,7 @@ function source.rewind(src)
             if not chunk then return src()
             else return chunk end
         else
-            table.insert(t, chunk)
+            t[#t+1] = chunk
         end
     end
 end
@@ -277,7 +277,7 @@ end
 function sink.table(t)
     t = t or {}
     local f = function(chunk, err)
-        if chunk then table.insert(t, chunk) end
+        if chunk then t[#t+1] = chunk end
         return 1
     end
     return f, t
index 235b0c22c2db59c61148988098d7046fbcc9e9f0..5f9c609f65c8da89b462dbb7326ceea9259faaa9 100644 (file)
@@ -249,9 +249,9 @@ function split(str, pat, max, regex)
                local s, e = str:find(pat, c, not regex)
                max = max - 1
                if s and max < 0 then
-                       table.insert(t, str:sub(c))
+                       t[#t+1] = str:sub(c)
                else
-                       table.insert(t, str:sub(c, s and s - 1))
+                       t[#t+1] = str:sub(c, s and s - 1)
                end
                c = e and e + 1 or #str + 1
        until not s or max < 0
@@ -334,7 +334,7 @@ function combine(...)
        local result = {}
        for i, a in ipairs(arg) do
                for j, v in ipairs(a) do
-                       table.insert(result, v)
+                       result[#result+1] = v
                end
        end
        return result
@@ -371,7 +371,7 @@ function keys(t)
        local keys = { }
        if t then
                for k, _ in kspairs(t) do
-                       table.insert( keys, k )
+                       keys[#keys+1] = k
                end
        end
        return keys
@@ -568,7 +568,7 @@ function _sortiter( t, f )
        local keys = { }
 
        for k, v in pairs(t) do
-               table.insert( keys, k )
+               keys[#keys+1] = k
        end
 
        local _pos = 0
@@ -657,7 +657,7 @@ function execl(command)
        while true do
                line = pp:read()
                if (line == nil) then break end
-               table.insert(data, line)
+               data[#data+1] = line
        end
        pp:close()
 
index 8852d1e5fb181c00a79dd030c9d5ce90c082d88b..2385cc37ca3f3312773069947fdafed717d3847c 100644 (file)
@@ -88,7 +88,7 @@ function Cursor.delete_all(self, config, stype, comparator)
        local function helper (section)
 
                if not comparator or comparator(section) then
-                       table.insert(del, section[".name"])
+                       del[#del+1] = section[".name"]
                end
        end
 
@@ -201,14 +201,14 @@ function Cursor._affected(self, configlist)
                        function(section)
                                if section.affects then
                                        for i, aff in ipairs(section.affects) do
-                                               table.insert(deps, aff)
+                                               deps[#deps+1] = aff
                                        end
                                end
                        end)
                
                for i, dep in ipairs(deps) do
                        for j, add in ipairs(_resolve_deps(dep)) do
-                               table.insert(reload, add)
+                               reload[#reload+1] = add
                        end
                end
                
@@ -219,7 +219,7 @@ function Cursor._affected(self, configlist)
        for j, config in ipairs(configlist) do
                for i, e in ipairs(_resolve_deps(config)) do
                        if not util.contains(reloadlist, e) then
-                               table.insert(reloadlist, e)
+                               reloadlist[#reloadlist+1] = e
                        end
                end
        end
index 4aa9b0933ab6f41bc130c9063a5caa6ccb42c971..dc6e5bb7ddc9417f54bd281da10cb09ad69228c9 100644 (file)
@@ -63,7 +63,7 @@ function compile(template)
 
        -- Search all <% %> expressions
        local function expr_add(ws1, skip1, command, skip2, ws2)
-               table.insert(expr, command)
+               expr[#expr+1] = command
                return ( #skip1 > 0 and "" or ws1 ) .. 
                       "<%" .. tostring(#expr) .. "%>" ..
                       ( #skip2 > 0 and "" or ws2 )