diff options
author | Waqas Hussain <waqas20@gmail.com> | 2009-05-17 02:06:35 +0500 |
---|---|---|
committer | Waqas Hussain <waqas20@gmail.com> | 2009-05-17 02:06:35 +0500 |
commit | ec51346b511ba986e6904603406e68e8f5b635f3 (patch) | |
tree | fe78f53442fc49280b6dcf79675e13a77df1e464 /util/events.lua | |
parent | 75ef8cbd13ea774e2b48582ec9e37fff4faf090f (diff) | |
download | prosody-ec51346b511ba986e6904603406e68e8f5b635f3.tar.gz prosody-ec51346b511ba986e6904603406e68e8f5b635f3.zip |
util.events: Much more efficient index building
Diffstat (limited to 'util/events.lua')
-rw-r--r-- | util/events.lua | 23 |
1 files changed, 11 insertions, 12 deletions
diff --git a/util/events.lua b/util/events.lua index 54816271..dc294a55 100644 --- a/util/events.lua +++ b/util/events.lua @@ -11,17 +11,16 @@ function new() local dispatchers = {};
local handlers = {};
local event_map = {};
- local function _rebuild_index() -- TODO optimize index rebuilding
- for event, _handlers in pairs(event_map) do
- local index = handlers[event];
- if index then
- for i=#index,1,-1 do index[i] = nil; end
- else index = {}; handlers[event] = index; end
- for handler in pairs(_handlers) do
- t_insert(index, handler);
- end
- t_sort(index, function(a, b) return _handlers[a] > _handlers[b]; end);
+ local function _rebuild_index(event) -- TODO optimize index rebuilding
+ local _handlers = event_map[event];
+ local index = handlers[event];
+ if index then
+ for i=#index,1,-1 do index[i] = nil; end
+ else index = {}; handlers[event] = index; end
+ for handler in pairs(_handlers) do
+ t_insert(index, handler);
end
+ t_sort(index, function(a, b) return _handlers[a] > _handlers[b]; end);
end;
local function add_handler(event, handler, priority)
local map = event_map[event];
@@ -31,13 +30,13 @@ function new() map = {[handler] = priority or 0};
event_map[event] = map;
end
- _rebuild_index();
+ _rebuild_index(event);
end;
local function remove_handler(event, handler)
local map = event_map[event];
if map then
map[handler] = nil;
- _rebuild_index();
+ _rebuild_index(event);
end
end;
local function add_plugin(plugin)
|