Skip to content

Commit afda0ae

Browse files
committed
extract benchmark substring matching helper
Extract helper to filter benchmark names according to a predicate.
1 parent 6fd5356 commit afda0ae

File tree

1 file changed

+17
-7
lines changed

1 file changed

+17
-7
lines changed

collector/src/benchmark/mod.rs

Lines changed: 17 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -410,13 +410,7 @@ pub fn get_compile_benchmarks(
410410
let mut skip = false;
411411

412412
let name_matches = |prefixes: &mut HashMap<&str, usize>| {
413-
for (prefix, n) in prefixes.iter_mut() {
414-
if name.as_str().starts_with(prefix) {
415-
*n += 1;
416-
return true;
417-
}
418-
}
419-
false
413+
substring_matches(prefixes, |prefix| name.starts_with(prefix))
420414
};
421415

422416
if let Some(includes) = includes.as_mut() {
@@ -462,3 +456,19 @@ pub fn get_compile_benchmarks(
462456

463457
Ok(benchmarks)
464458
}
459+
460+
/// Helper to verify if a benchmark name matches a given substring, like a prefix or a suffix. The
461+
/// `predicate` closure will be passed each substring from `substrings` until it returns true, and
462+
/// in that case the substring's number of uses in the map will be increased.
463+
fn substring_matches(
464+
substrings: &mut HashMap<&str, usize>,
465+
predicate: impl Fn(&str) -> bool,
466+
) -> bool {
467+
for (substring, n) in substrings.iter_mut() {
468+
if predicate(substring) {
469+
*n += 1;
470+
return true;
471+
}
472+
}
473+
false
474+
}

0 commit comments

Comments
 (0)