From 2ff2c99c8e97a7709431b6a2bcbb8c356ecd6a84 Mon Sep 17 00:00:00 2001 From: Yozzaxia1311 Date: Wed, 4 Aug 2021 16:45:14 -0700 Subject: [PATCH 1/4] fast indexing --- deep.lua | 28 ++++++++++++++-------------- 1 file changed, 14 insertions(+), 14 deletions(-) diff --git a/deep.lua b/deep.lua index ffd545c..648723b 100644 --- a/deep.lua +++ b/deep.lua @@ -26,8 +26,6 @@ local deep = { } local execQueue = {} -local maxIndex = 1 -local minIndex = 1 -- for compatibility with Lua 5.1/5.2 local unpack = rawget(table, "unpack") or unpack @@ -44,13 +42,7 @@ deep.queue = function(i, fun, ...) end local arg = { ... } - - if i < minIndex then - minIndex = i - elseif i > maxIndex then - maxIndex = i - end - + if arg and #arg > 0 then local t = function() return fun(unpack(arg)) end @@ -69,15 +61,23 @@ deep.queue = function(i, fun, ...) end deep.execute = function() - for i = minIndex, maxIndex do - if execQueue[i] then - for _, fun in pairs(execQueue[i]) do + if next(execQueue) then + local keys = {} + + for k, v in pairs(execQueue) do + keys[#keys + 1] = k + end + + table.sort(keys) + + for k = 1, #keys do + for _, fun in ipairs(execQueue[keys[k]]) do fun() end end + + execQueue = {} end - - execQueue = {} end return deep From 59f303f421192bdbc0d715d77b8db95fa3772ca9 Mon Sep 17 00:00:00 2001 From: Yozzaxia1311 Date: Wed, 4 Aug 2021 17:15:58 -0700 Subject: [PATCH 2/4] Update deep.lua --- deep.lua | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/deep.lua b/deep.lua index 648723b..6e2492f 100644 --- a/deep.lua +++ b/deep.lua @@ -71,8 +71,8 @@ deep.execute = function() table.sort(keys) for k = 1, #keys do - for _, fun in ipairs(execQueue[keys[k]]) do - fun() + for i = 1, #execQueue[keys[k]] do + execQueue[keys[k]][i]() end end From ac630ac32df99e90df74f507be265a306e4fe4fc Mon Sep 17 00:00:00 2001 From: Yozzaxia1311 Date: Wed, 4 Aug 2021 17:18:48 -0700 Subject: [PATCH 3/4] more specific --- deep.lua | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/deep.lua b/deep.lua index 6e2492f..e790bdc 100644 --- a/deep.lua +++ b/deep.lua @@ -61,7 +61,7 @@ deep.queue = function(i, fun, ...) end deep.execute = function() - if next(execQueue) then + if next(execQueue) ~= nil then local keys = {} for k, v in pairs(execQueue) do From 42d0dabc74f9ab04a72d3bc81a22fc63621a9ae9 Mon Sep 17 00:00:00 2001 From: Yozzaxia1311 Date: Wed, 4 Aug 2021 18:14:12 -0700 Subject: [PATCH 4/4] better key collection --- deep.lua | 18 ++++++++---------- 1 file changed, 8 insertions(+), 10 deletions(-) diff --git a/deep.lua b/deep.lua index e790bdc..89f6a3d 100644 --- a/deep.lua +++ b/deep.lua @@ -26,6 +26,7 @@ local deep = { } local execQueue = {} +local execKeys = {} -- for compatibility with Lua 5.1/5.2 local unpack = rawget(table, "unpack") or unpack @@ -58,25 +59,22 @@ deep.queue = function(i, fun, ...) table.insert(execQueue[i], fun) end end + + table.insert(execKeys, i) end deep.execute = function() if next(execQueue) ~= nil then - local keys = {} - - for k, v in pairs(execQueue) do - keys[#keys + 1] = k - end - - table.sort(keys) + table.sort(execKeys) - for k = 1, #keys do - for i = 1, #execQueue[keys[k]] do - execQueue[keys[k]][i]() + for k = 1, #execKeys do + for i = 1, #execQueue[execKeys[k]] do + execQueue[execKeys[k]][i]() end end execQueue = {} + execKeys = {} end end