summaryrefslogtreecommitdiffhomepage
path: root/libs
diff options
context:
space:
mode:
authorJo-Philipp Wich <jow@openwrt.org>2009-07-23 03:21:18 +0000
committerJo-Philipp Wich <jow@openwrt.org>2009-07-23 03:21:18 +0000
commita4f6748205c6afd17811c9548aaae6b17476e6d8 (patch)
treeabf822ed42b17b62c82607d077e826e930f439a4 /libs
parent3f1393006eadecf0068156c20a9e36ad9abd50f7 (diff)
libs/core: util.lua optimize get() and set() accessors of threadlocals
Diffstat (limited to 'libs')
-rw-r--r--libs/core/luasrc/util.lua18
1 files changed, 7 insertions, 11 deletions
diff --git a/libs/core/luasrc/util.lua b/libs/core/luasrc/util.lua
index f83cac5763..94b5ce67f1 100644
--- a/libs/core/luasrc/util.lua
+++ b/libs/core/luasrc/util.lua
@@ -122,21 +122,17 @@ function threadlocal()
local tbl = {}
local function get(self, key)
- local c = coroutine.running()
- local thread = coxpt[c] or c or 0
- if not rawget(self, thread) then
- return nil
- end
- return rawget(self, thread)[key]
+ local t = rawget(self, coxpt[coroutine.running()] or coroutine.running() or 0)
+ return t and t[key]
end
local function set(self, key, value)
- local c = coroutine.running()
- local thread = coxpt[c] or c or 0
- if not rawget(self, thread) then
- rawset(self, thread, {})
+ local c = coxpt[coroutine.running()] or coroutine.running() or 0
+ if not rawget(self, c) then
+ rawset(self, c, { [key] = value })
+ else
+ rawget(self, c)[key] = value
end
- rawget(self, thread)[key] = value
end
setmetatable(tbl, {__index = get, __newindex = set, __mode = "k"})