From 23d79f65ad0a46c9776d3a0c6290cb1021952223 Mon Sep 17 00:00:00 2001 From: Manuel Simon Hirsig Date: Sun, 6 Nov 2016 22:31:13 +0100 Subject: [PATCH] performance improvements --- aux-addon.lua | 4 ++-- core/scan.lua | 8 ++++---- util.lua | 8 +++++--- 3 files changed, 11 insertions(+), 9 deletions(-) diff --git a/aux-addon.lua b/aux-addon.lua index 6fedd99..89b7d00 100644 --- a/aux-addon.lua +++ b/aux-addon.lua @@ -127,7 +127,7 @@ do do (on_success or nop)() end locked = false end) - thread(when, later(GetTime(), 5), send_signal) + thread(when, later(5), send_signal) event_listener('CHAT_MSG_SYSTEM', function(kill) if arg1 == ERR_AUCTION_BID_PLACED then send_signal() @@ -150,7 +150,7 @@ do do (on_success or nop)() end locked = false end) - thread(when, later(GetTime(), 5), send_signal) + thread(when, later(5), send_signal) event_listener('CHAT_MSG_SYSTEM', function(kill) if arg1 == ERR_AUCTION_REMOVED then send_signal() diff --git a/core/scan.lua b/core/scan.lua index 623091c..6066cbf 100644 --- a/core/scan.lua +++ b/core/scan.lua @@ -156,7 +156,7 @@ function scan_page(i) end function wait_for_results() - local timeout = later(state.last_query_time, 10) + local timeout = later(5, state.last_query_time) local send_signal, signal_received = signal() when(signal_received, function() if timeout() then @@ -181,7 +181,7 @@ function wait_for_results() elseif state.params.type == 'owner' then return wait_for_owner_results(send_signal) elseif state.params.type == 'list' then - return wait_for_list_results(send_signal, signal_received) + return wait_for_list_results(send_signal, signal_received, timeout) end end @@ -193,7 +193,7 @@ function wait_for_owner_results(send_signal) end end -function wait_for_list_results(send_signal, signal_received) +function wait_for_list_results(send_signal, signal_received, timeout) local updated, last_update event_listener('AUCTION_ITEM_LIST_UPDATE', function(kill) kill(signal_received()) @@ -203,7 +203,7 @@ function wait_for_list_results(send_signal, signal_received) local ignore_owner = state.params.ignore_owner or aux_ignore_owner return thread(when, function() -- short circuiting order important, owner_data_complete must be called iif an update has happened. - local ok = updated and (ignore_owner or owner_data_complete()) or last_update and GetTime() - last_update > 5 + local ok = updated and (ignore_owner or owner_data_complete() or timeout()) updated = false return ok end, send_signal) diff --git a/util.lua b/util.lua index af1ad9d..461b255 100644 --- a/util.lua +++ b/util.lua @@ -209,10 +209,12 @@ function M.round(x) return floor(x + .5) end -function M.later(t0, t) +function M.later(t, t0) + t0 = t0 or GetTime() return function() return GetTime() - t0 > t end end -function M.signal() local params - return function(...) params = arg end, function() return params end +function M.signal() + local params + return vararg-function(arg) params = static-arg end, function() return params end end \ No newline at end of file