Skip to content

Commit

Permalink
move _ count check outside of loop
Browse files Browse the repository at this point in the history
  • Loading branch information
Cheng JIANG committed May 10, 2020
1 parent f43bb84 commit edb35cb
Showing 1 changed file with 12 additions and 12 deletions.
24 changes: 12 additions & 12 deletions src/model/assertion.rs
Original file line number Diff line number Diff line change
Expand Up @@ -47,13 +47,13 @@ impl Assertion {

pub fn build_role_links(&mut self, rm: Arc<RwLock<dyn RoleManager>>) -> Result<()> {
let count = self.value.chars().filter(|&c| c == '_').count();
if count < 2 {
return Err(ModelError::P(
r#"the number of "_" in role definition should be at least 2"#.to_owned(),
)
.into());
}
for rule in &self.policy {
if count < 2 {
return Err(ModelError::P(
r#"the number of "_" in role definition should be at least 2"#.to_owned(),
)
.into());
}
if rule.len() < count {
return Err(PolicyError::UnmatchPolicyDefinition(count, rule.len()).into());
}
Expand All @@ -78,6 +78,12 @@ impl Assertion {
d: EventData,
) -> Result<()> {
let count = self.value.chars().filter(|&c| c == '_').count();
if count < 2 {
return Err(ModelError::P(
r#"the number of "_" in role definition should be at least 2"#.to_owned(),
)
.into());
}

if let Some((insert, rules)) = match d {
EventData::AddPolicy(_, _, rule) => Some((true, vec![rule])),
Expand All @@ -88,12 +94,6 @@ impl Assertion {
_ => None,
} {
for rule in rules {
if count < 2 {
return Err(ModelError::P(
r#"the number of "_" in role definition should be at least 2"#.to_owned(),
)
.into());
}
if rule.len() < count {
return Err(PolicyError::UnmatchPolicyDefinition(count, rule.len()).into());
}
Expand Down

1 comment on commit edb35cb

@GopherJ
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Rust Benchmark

Benchmark suite Current: edb35cb Previous: f43bb84 Ratio
b_benchmark_abac_model 7365 ns/iter (± 5415) 7296 ns/iter (± 734) 1.01
b_benchmark_basic_model 7779 ns/iter (± 2086) 7619 ns/iter (± 486) 1.02
b_benchmark_key_match 25842 ns/iter (± 2251) 26698 ns/iter (± 1130) 0.97
b_benchmark_priority_model 9009 ns/iter (± 964) 9119 ns/iter (± 670) 0.99
b_benchmark_raw 8 ns/iter (± 2) 8 ns/iter (± 0) 1
b_benchmark_rbac_model 22233 ns/iter (± 14057) 22340 ns/iter (± 2439) 1.00
b_benchmark_rbac_model_large 70838101 ns/iter (± 5314903) 71028620 ns/iter (± 4060730) 1.00
b_benchmark_rbac_model_medium 6651449 ns/iter (± 833509) 6731653 ns/iter (± 524153) 0.99
b_benchmark_rbac_model_small 647565 ns/iter (± 62181) 662061 ns/iter (± 35882) 0.98
b_benchmark_rbac_model_with_domains 13125 ns/iter (± 2928) 12793 ns/iter (± 867) 1.03
b_benchmark_rbac_with_deny 37197 ns/iter (± 2004) 37453 ns/iter (± 1646) 0.99
b_benchmark_rbac_with_resource_roles 10076 ns/iter (± 816) 10015 ns/iter (± 515) 1.01

This comment was automatically generated by workflow using github-action-benchmark.

Please sign in to comment.