Software /
code /
prosody
Comparison
util/events.lua @ 1417:b02b22f77326
util.events: Replaced ipairs with slightly faster numeric for loop - #optimization
author | Waqas Hussain <waqas20@gmail.com> |
---|---|
date | Fri, 26 Jun 2009 08:52:26 +0500 |
parent | 1181:dffbb7d1da4b |
child | 1507:92357dffe743 |
comparison
equal
deleted
inserted
replaced
1416:f916f0ff90e5 | 1417:b02b22f77326 |
---|---|
51 end; | 51 end; |
52 local function _create_dispatcher(event) -- FIXME duplicate code in fire_event | 52 local function _create_dispatcher(event) -- FIXME duplicate code in fire_event |
53 local h = handlers[event]; | 53 local h = handlers[event]; |
54 if not h then h = {}; handlers[event] = h; end | 54 if not h then h = {}; handlers[event] = h; end |
55 local dispatcher = function(...) | 55 local dispatcher = function(...) |
56 for _, handler in ipairs(h) do | 56 for i=1,#h do |
57 local ret = handler(...); | 57 local ret = h[i](...); |
58 if ret ~= nil then return ret; end | 58 if ret ~= nil then return ret; end |
59 end | 59 end |
60 end; | 60 end; |
61 dispatchers[event] = dispatcher; | 61 dispatchers[event] = dispatcher; |
62 return dispatcher; | 62 return dispatcher; |
65 return dispatchers[event] or _create_dispatcher(event); | 65 return dispatchers[event] or _create_dispatcher(event); |
66 end; | 66 end; |
67 local function fire_event(event, ...) -- FIXME duplicates dispatcher code | 67 local function fire_event(event, ...) -- FIXME duplicates dispatcher code |
68 local h = handlers[event]; | 68 local h = handlers[event]; |
69 if h then | 69 if h then |
70 for _, handler in ipairs(h) do | 70 for i=1,#h do |
71 local ret = handler(...); | 71 local ret = h[i](...); |
72 if ret ~= nil then return ret; end | 72 if ret ~= nil then return ret; end |
73 end | 73 end |
74 end | 74 end |
75 end; | 75 end; |
76 local function get_named_arg_dispatcher(event, ...) | 76 local function get_named_arg_dispatcher(event, ...) |