summaryrefslogtreecommitdiff
path: root/src/bindings
diff options
context:
space:
mode:
authorDaniel Kolesa <d.kolesa@samsung.com>2015-03-06 14:25:29 +0000
committerDaniel Kolesa <d.kolesa@samsung.com>2015-03-06 14:25:29 +0000
commitbcc5ba83b320924ded614ee722c08b8d68a08a44 (patch)
tree5fa9ccdd95e1b4df6e315f44bd4c0e3b67f25801 /src/bindings
parent374fa09f4821e06396b20014b95b9138e63ab0ee (diff)
elua: a func-to-idx cache for eo callbacks
Diffstat (limited to 'src/bindings')
-rw-r--r--src/bindings/luajit/eo.lua25
1 files changed, 12 insertions, 13 deletions
diff --git a/src/bindings/luajit/eo.lua b/src/bindings/luajit/eo.lua
index 22f9094c06..bbb8d9e26c 100644
--- a/src/bindings/luajit/eo.lua
+++ b/src/bindings/luajit/eo.lua
@@ -131,14 +131,14 @@ local eo_classes = {}
131 131
132-- event system 132-- event system
133 133
134local eo_callbacks = {} 134local eo_callbacks, eo_cbidcache = {}, {}
135 135
136local eo_event_del, eo_event_cb 136local eo_event_del, eo_event_cb
137 137
138local eo_event_del_fun = function(data, obj, desc, einfo) 138local eo_event_del_fun = function(data, obj, desc, einfo)
139 local addr = eo_obj_addr_get(obj) 139 local addr = eo_obj_addr_get(obj)
140 if eo_callbacks[addr] then 140 if eo_callbacks[addr] then
141 eo_callbacks[addr] = nil 141 eo_callbacks[addr], eo_cbidcache[addr] = nil, nil
142 end 142 end
143end 143end
144 144
@@ -162,13 +162,14 @@ local connect = function(self, ename, func, priority)
162 local cdel = false 162 local cdel = false
163 local addr = eo_obj_addr_get(self) 163 local addr = eo_obj_addr_get(self)
164 local cbs = eo_callbacks[addr] 164 local cbs = eo_callbacks[addr]
165 local cbi = eo_cbidcache[addr]
165 if not cbs then 166 if not cbs then
166 cbs = {} 167 cbs, cbi = {}, {}
167 eo_callbacks[addr] = cbs 168 eo_callbacks[addr], eo_cbidcache[addr] = cbs, cbi
168 cdel = true 169 cdel = true
169 end 170 end
170 local cidx = #cbs + 1 171 local cidx = #cbs + 1
171 cbs[cidx] = func 172 cbs[cidx], cbi[func] = func, cidx
172 M.__do_start(self, cl) 173 M.__do_start(self, cl)
173 eo.eo_event_callback_priority_add(ev, priority or 0, 174 eo.eo_event_callback_priority_add(ev, priority or 0,
174 eo_event_cb, ffi.cast("void *", cidx)) 175 eo_event_cb, ffi.cast("void *", cidx))
@@ -191,17 +192,14 @@ local disconnect = function(self, ename, func)
191 return false 192 return false
192 end 193 end
193 -- TODO: make a hash table for func-to-index conversions 194 -- TODO: make a hash table for func-to-index conversions
194 local cidx = -1 195 local cbi = eo_cbidcache[addr]
195 for i = 1, #cbs do 196 assert(cbi)
196 if cbs[i] == func then 197 local cidx = cbi[func]
197 cidx = i 198 if not cidx then
198 break
199 end
200 end
201 if cidx < 0 then
202 return false 199 return false
203 end 200 end
204 cbs[cidx] = nil 201 cbs[cidx] = nil
202 cbi[func] = nil
205 M.__do_start(self, cl) 203 M.__do_start(self, cl)
206 eo.eo_event_callback_del(ev, eo_event_cb, ffi.cast("void *", cidx)) 204 eo.eo_event_callback_del(ev, eo_event_cb, ffi.cast("void *", cidx))
207 M.__do_end() 205 M.__do_end()
@@ -234,6 +232,7 @@ local shutdown = function()
234 eo_event_del = nil 232 eo_event_del = nil
235 eo_event_cb = nil 233 eo_event_cb = nil
236 eo_callbacks = {} 234 eo_callbacks = {}
235 eo_cbidcache = {}
237 util.lib_unload("eo") 236 util.lib_unload("eo")
238end 237end
239 238