Skip to content

Commit 6b4efc4

Browse files
authored
perf: remove redundant reinitialization of policyMap (#137)
1 parent 2a66ee5 commit 6b4efc4

1 file changed

Lines changed: 5 additions & 12 deletions

File tree

src/persist/Adapter.lua

Lines changed: 5 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -24,13 +24,13 @@ function Adapter.loadPolicyLine(line, model)
2424
return
2525
end
2626

27-
if line:sub(1,1) == "#" then
27+
if line:sub(1, 1) == "#" then
2828
return
2929
end
3030

3131
local tokens = Util.split(line, ",")
3232
local key = tokens[1]
33-
local sec = key:sub(1,1)
33+
local sec = key:sub(1, 1)
3434

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

4242
model.model[sec][key].policy = model.model[sec][key].policy or {}
43-
model.model[sec][key].policyMap={}
44-
for i,policy in pairs(model.model[sec][key].policy) do
45-
model.model[sec][key].policyMap[table.concat(policy,",")]=i
46-
end
4743
local rules = {}
4844
for i = 2, #tokens do
4945
table.insert(rules, tokens[i])
5046
end
5147
table.insert(model.model[sec][key].policy, rules)
52-
model.model[sec][key].policyMap={}
53-
for i,policy in pairs(model.model[sec][key].policy) do
54-
model.model[sec][key].policyMap[table.concat(policy,",")]=i
55-
end
48+
model.model[sec][key].policyMap[table.concat(rules, ",")] = #model.model[sec][key].policy
5649
end
5750

5851
--[[
@@ -81,7 +74,7 @@ end
8174
* @param ptype the policy type, "p", "p2", .. or "g", "g2", ..
8275
* @param rule the rule, like (sub, obj, act).
8376
]]
84-
function Adapter:addPolicy(sec,ptype,rule)
77+
function Adapter:addPolicy(sec, ptype, rule)
8578

8679
end
8780

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

9891
end
9992

0 commit comments

Comments
 (0)