diff options
author | Jo-Philipp Wich <jow@openwrt.org> | 2009-10-08 10:07:51 +0000 |
---|---|---|
committer | Jo-Philipp Wich <jow@openwrt.org> | 2009-10-08 10:07:51 +0000 |
commit | 740bb20850378d5f3c3abd4cbe35720174d2c5e5 (patch) | |
tree | 720482c289bb560d23fc36cdf8d6f4694f4281be /libs/uci/luasrc/model | |
parent | 667e05a8b46068bab16ea36afe17b75a2f2cfd44 (diff) |
libs/uci: optimize get & set performance in luci.model.uci.bind, fix ambiguous case in uciop()
Diffstat (limited to 'libs/uci/luasrc/model')
-rw-r--r-- | libs/uci/luasrc/model/uci/bind.lua | 69 |
1 files changed, 38 insertions, 31 deletions
diff --git a/libs/uci/luasrc/model/uci/bind.lua b/libs/uci/luasrc/model/uci/bind.lua index 7e3085e398..89ad3284c8 100644 --- a/libs/uci/luasrc/model/uci/bind.lua +++ b/libs/uci/luasrc/model/uci/bind.lua @@ -90,49 +90,56 @@ bsection = utl.class() function bsection.uciop(self, op, ...) assert(self.bind and self.bind.uci, - "attempt to use unitialized binding: " .. type(self.sid)) + "attempt to use unitialized binding") - return op and self.bind.uci[op](self.bind.uci, self.bind.cfg, ...) - or self.bind.uci + if op then + return self.bind.uci[op](self.bind.uci, self.bind.cfg, ...) + else + return self.bind.uci + end end function bsection.get(self, k, c) local v - self:uciop("foreach", self.stype, - function(s) - if type(c) == "table" then - local ck, cv - for ck, cv in pairs(c) do - if s[ck] ~= cv then return true end + if type(c) == "string" then + v = self:uciop("get", c, k) + else + self:uciop("foreach", self.stype, + function(s) + if type(c) == "table" then + local ck, cv + for ck, cv in pairs(c) do + if s[ck] ~= cv then return true end + end + end + if k ~= nil then + v = s[k] + else + v = s end - elseif type(c) == "string" and s['.name'] ~= c then - return true - end - if k ~= nil then - v = s[k] - else - v = s - end - return false - end) + return false + end) + end return v end function bsection.set(self, k, v, c) local stat - self:uciop("foreach", self.stype, - function(s) - if type(c) == "table" then - local ck, cv - for ck, cv in pairs(c) do - if s[ck] ~= cv then return true end + if type(c) == "string" then + stat = self:uciop("set", c, k, v) + else + self:uciop("foreach", self.stype, + function(s) + if type(c) == "table" then + local ck, cv + for ck, cv in pairs(c) do + if s[ck] ~= cv then return true end + end end - elseif type(c) == "string" and s['.name'] ~= c then - return true - end - stat = self:uciop("set", c, k, v) - return false - end) + stat = self:uciop("set", c, k, v) + return false + end) + end return stat or false end |