Skip to content

Commit

Permalink
don't collect found paths into BTreeSet:
Browse files Browse the repository at this point in the history
keeping order of inserted Paths having high cost on hot path, collect into HashSet instead and sort afterward.

from 1,858,963,938 to 1,448,975,825 I refs.
  • Loading branch information
klensy committed Jan 23, 2024
1 parent e78d685 commit 0710ebb
Showing 1 changed file with 6 additions and 5 deletions.
11 changes: 6 additions & 5 deletions src/tools/compiletest/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ use build_helper::git::{get_git_modified_files, get_git_untracked_files};
use core::panic;
use getopts::Options;
use lazycell::AtomicLazyCell;
use std::collections::BTreeSet;
use std::collections::HashSet;
use std::ffi::OsString;
use std::fs;
use std::io::{self, ErrorKind};
Expand Down Expand Up @@ -415,7 +415,7 @@ pub fn run_tests(config: Arc<Config>) {

let mut tests = Vec::new();
for c in configs {
let mut found_paths = BTreeSet::new();
let mut found_paths = HashSet::new();
make_tests(c, &mut tests, &mut found_paths);
check_overlapping_tests(&found_paths);
}
Expand Down Expand Up @@ -550,7 +550,7 @@ pub fn test_opts(config: &Config) -> test::TestOpts {
pub fn make_tests(
config: Arc<Config>,
tests: &mut Vec<test::TestDescAndFn>,
found_paths: &mut BTreeSet<PathBuf>,
found_paths: &mut HashSet<PathBuf>,
) {
debug!("making tests from {:?}", config.src_base.display());
let inputs = common_inputs_stamp(&config);
Expand Down Expand Up @@ -646,7 +646,7 @@ fn collect_tests_from_dir(
relative_dir_path: &Path,
inputs: &Stamp,
tests: &mut Vec<test::TestDescAndFn>,
found_paths: &mut BTreeSet<PathBuf>,
found_paths: &mut HashSet<PathBuf>,
modified_tests: &Vec<PathBuf>,
poisoned: &mut bool,
) -> io::Result<()> {
Expand Down Expand Up @@ -1128,7 +1128,7 @@ fn not_a_digit(c: char) -> bool {
!c.is_digit(10)
}

fn check_overlapping_tests(found_paths: &BTreeSet<PathBuf>) {
fn check_overlapping_tests(found_paths: &HashSet<PathBuf>) {
let mut collisions = Vec::new();
for path in found_paths {
for ancestor in path.ancestors().skip(1) {
Expand All @@ -1138,6 +1138,7 @@ fn check_overlapping_tests(found_paths: &BTreeSet<PathBuf>) {
}
}
if !collisions.is_empty() {
collisions.sort();
let collisions: String = collisions
.into_iter()
.map(|(path, check_parent)| format!("test {path:?} clashes with {check_parent:?}\n"))
Expand Down

0 comments on commit 0710ebb

Please sign in to comment.