diff --git a/actix-router/benches/router.rs b/actix-router/benches/router.rs index 6f6b67b48..5b4c53cfa 100644 --- a/actix-router/benches/router.rs +++ b/actix-router/benches/router.rs @@ -1,6 +1,6 @@ //! Based on https://github.com/ibraheemdev/matchit/blob/master/benches/bench.rs -use criterion::{black_box, criterion_group, criterion_main, Criterion}; +use criterion::{black_box, Criterion, criterion_group, criterion_main}; macro_rules! register { (colon) => {{ @@ -150,7 +150,7 @@ macro_rules! register { }}; } -fn call() -> impl Iterator { +fn call() -> impl Iterator { let arr = [ "/authorizations", "/user/repos", @@ -179,6 +179,15 @@ fn compare_routers(c: &mut Criterion) { }); }); + group.bench_function("actix_guard_failures", |b| { + b.iter(|| { + for route in call() { + let mut path = actix_router::Path::new(route); + black_box(actix.recognize_fn(&mut path, |_, _| false)); + } + }); + }); + let regex_set = regex::RegexSet::new(register!(regex)).unwrap(); group.bench_function("regex", |b| { b.iter(|| { diff --git a/actix-router/src/router.rs b/actix-router/src/router.rs index 1557146cf..0c9e726ba 100644 --- a/actix-router/src/router.rs +++ b/actix-router/src/router.rs @@ -52,18 +52,18 @@ impl Router { R: Resource, F: FnMut(&R, &U) -> bool, { - let mut matches = 0; + let mut next_match_count = 1; for (rdef, val, ctx) in self.routes.iter() { match rdef.capture_match_info(resource) { None => {} Some(match_info) => { - matches += 1; if check_fn(resource, ctx) { rdef.resolve_resource(resource, match_info); return Some((val, ResourceId(rdef.id()))); - } else if matches == self.max_path_conflicts { + } else if next_match_count == self.max_path_conflicts { return None; } + next_match_count += 1; } } }