libs/uci: optimize get & set performance in luci.model.uci.bind, fix ambiguous case in uciop()

This commit is contained in:
Jo-Philipp Wich 2009-10-08 10:07:51 +00:00
parent 667e05a8b4
commit 740bb20850

View file

@ -90,49 +90,56 @@ bsection = utl.class()
function bsection.uciop(self, op, ...) function bsection.uciop(self, op, ...)
assert(self.bind and self.bind.uci, 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, ...) if op then
or self.bind.uci return self.bind.uci[op](self.bind.uci, self.bind.cfg, ...)
else
return self.bind.uci
end
end end
function bsection.get(self, k, c) function bsection.get(self, k, c)
local v local v
self:uciop("foreach", self.stype, if type(c) == "string" then
function(s) v = self:uciop("get", c, k)
if type(c) == "table" then else
local ck, cv self:uciop("foreach", self.stype,
for ck, cv in pairs(c) do function(s)
if s[ck] ~= cv then return true end 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 end
elseif type(c) == "string" and s['.name'] ~= c then if k ~= nil then
return true v = s[k]
end else
if k ~= nil then v = s
v = s[k] end
else return false
v = s end)
end end
return false
end)
return v return v
end end
function bsection.set(self, k, v, c) function bsection.set(self, k, v, c)
local stat local stat
self:uciop("foreach", self.stype, if type(c) == "string" then
function(s) stat = self:uciop("set", c, k, v)
if type(c) == "table" then else
local ck, cv self:uciop("foreach", self.stype,
for ck, cv in pairs(c) do function(s)
if s[ck] ~= cv then return true end 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 end
elseif type(c) == "string" and s['.name'] ~= c then stat = self:uciop("set", c, k, v)
return true return false
end end)
stat = self:uciop("set", c, k, v) end
return false
end)
return stat or false return stat or false
end end