Skip to content

Commit

Permalink
perf: remove redundant reinitialization of policyMap (#137)
Browse files Browse the repository at this point in the history
  • Loading branch information
rushitote authored May 13, 2022
1 parent 2a66ee5 commit 6b4efc4
Showing 1 changed file with 5 additions and 12 deletions.
17 changes: 5 additions & 12 deletions src/persist/Adapter.lua
Original file line number Diff line number Diff line change
Expand Up @@ -24,13 +24,13 @@ function Adapter.loadPolicyLine(line, model)
return
end

if line:sub(1,1) == "#" then
if line:sub(1, 1) == "#" then
return
end

local tokens = Util.split(line, ",")
local key = tokens[1]
local sec = key:sub(1,1)
local sec = key:sub(1, 1)

if model.model[sec] == nil then
return
Expand All @@ -40,19 +40,12 @@ function Adapter.loadPolicyLine(line, model)
end

model.model[sec][key].policy = model.model[sec][key].policy or {}
model.model[sec][key].policyMap={}
for i,policy in pairs(model.model[sec][key].policy) do
model.model[sec][key].policyMap[table.concat(policy,",")]=i
end
local rules = {}
for i = 2, #tokens do
table.insert(rules, tokens[i])
end
table.insert(model.model[sec][key].policy, rules)
model.model[sec][key].policyMap={}
for i,policy in pairs(model.model[sec][key].policy) do
model.model[sec][key].policyMap[table.concat(policy,",")]=i
end
model.model[sec][key].policyMap[table.concat(rules, ",")] = #model.model[sec][key].policy
end

--[[
Expand Down Expand Up @@ -81,7 +74,7 @@ end
* @param ptype the policy type, "p", "p2", .. or "g", "g2", ..
* @param rule the rule, like (sub, obj, act).
]]
function Adapter:addPolicy(sec,ptype,rule)
function Adapter:addPolicy(sec, ptype, rule)

end

Expand All @@ -93,7 +86,7 @@ end
* @param ptype the policy type, "p", "p2", .. or "g", "g2", ..
* @param rule the rule, like (sub, obj, act).
]]
function Adapter:removePolicy(sec,ptype,rule)
function Adapter:removePolicy(sec, ptype, rule)

end

Expand Down

0 comments on commit 6b4efc4

Please sign in to comment.