Software /
code /
prosody
Changeset
3500:a49ed9166820
util.events: Create new index on handler change instead of modifying existing one (this makes util.events fully reentrant).
author | Waqas Hussain <waqas20@gmail.com> |
---|---|
date | Fri, 17 Sep 2010 04:09:59 +0500 |
parents | 3499:91c55ae31ef3 |
children | 3501:90c18e0355af |
files | util/events.lua |
diffstat | 1 files changed, 2 insertions(+), 4 deletions(-) [+] |
line wrap: on
line diff
--- a/util/events.lua Fri Sep 17 04:09:58 2010 +0500 +++ b/util/events.lua Fri Sep 17 04:09:59 2010 +0500 @@ -18,14 +18,12 @@ 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];