Skip to content

Commit

Permalink
fix: optimize the deleteRole method (casbin#272)
Browse files Browse the repository at this point in the history
Signed-off-by: imp2002 <[email protected]>
  • Loading branch information
imp2002 authored May 27, 2022
1 parent 79ff3ff commit 24826bc
Showing 1 changed file with 3 additions and 4 deletions.
7 changes: 3 additions & 4 deletions src/main/java/org/casbin/jcasbin/rbac/Role.java
Original file line number Diff line number Diff line change
Expand Up @@ -44,13 +44,12 @@ void addRole(Role role) {
}

void deleteRole(Role role) {
List<Role> toRemove = new ArrayList<>();
for (Role r : roles) {
if (r.name.equals(role.name)) {
toRemove.add(r);
roles.remove(r);
return;
}
}
roles.removeAll(toRemove);
}

boolean hasRole(String name, int hierarchyLevel) {
Expand Down Expand Up @@ -83,7 +82,7 @@ public String toString() {
if (i == 0) {
names.append(role.name);
} else {
names.append(", " + role.name);
names.append(", ").append(role.name);
}
}
return name + " < " + names;
Expand Down

0 comments on commit 24826bc

Please sign in to comment.