Skip to content

Commit b27b9d1

Browse files
authored
feat: enhance performance by checking before allocation in default role manager (#398)
1 parent 2bf5287 commit b27b9d1

1 file changed

Lines changed: 8 additions & 9 deletions

File tree

src/rbac/default_role_manager.rs

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -173,16 +173,15 @@ impl DefaultRoleManager {
173173
// return the list of affected domain names (immutable) to avoid nested
174174
// mutable borrows when performing operations across domains
175175
fn affected_domain_names(&self, domain: &str) -> Vec<String> {
176-
let mut res = Vec::new();
177-
if let Some(domain_matching_fn) = self.domain_matching_fn {
178-
let keys: Vec<String> = self.all_domains.keys().cloned().collect();
179-
for d in keys {
180-
if d != domain && (domain_matching_fn)(&d, domain) {
181-
res.push(d);
182-
}
183-
}
176+
if let Some(matcher) = self.domain_matching_fn {
177+
self.all_domains
178+
.keys()
179+
.filter(|d| *d != domain && matcher(d, domain))
180+
.cloned()
181+
.collect()
182+
} else {
183+
Vec::new()
184184
}
185-
res
186185
}
187186

188187
// copy all role links and nodes from `src_domain` graph into `dst_domain` graph

0 commit comments

Comments
 (0)