From 191c3849e27a658df2d21efe581d22a9db6623f6 Mon Sep 17 00:00:00 2001 From: Waqas Hussain Date: Fri, 17 Sep 2010 04:09:59 +0500 Subject: util.events: Create new index on handler change instead of modifying existing one (this makes util.events fully reentrant). --- util/events.lua | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) (limited to 'util') diff --git a/util/events.lua b/util/events.lua index a1da4d8a..81bea639 100644 --- a/util/events.lua +++ b/util/events.lua @@ -18,14 +18,12 @@ function new() local event_map = {}; 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 + local index = {}; for handler in pairs(_handlers) do t_insert(index, handler); end t_sort(index, function(a, b) return _handlers[a] > _handlers[b]; end); + handlers[event] = index; end; local function add_handler(event, handler, priority) local map = event_map[event]; -- cgit v1.2.3