Skip to content

Commit

Permalink
Refactor package walk code
Browse files Browse the repository at this point in the history
Don't pass mutable vecs around
  • Loading branch information
sourcefrog committed Jan 4, 2025
1 parent 2005a6d commit 8d8cfa0
Showing 1 changed file with 9 additions and 14 deletions.
23 changes: 9 additions & 14 deletions src/visit.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright 2021-2024 Martin Pool
// Copyright 2021 - 2025 Martin Pool

//! Visit all the files in a source tree, and then the AST of each file,
//! to discover mutation opportunities.
Expand Down Expand Up @@ -69,15 +69,10 @@ pub fn walk_tree(
let error_exprs = options.parsed_error_exprs()?;
let progress = console.start_walk_tree();
for package in packages {
walk_package(
workspace_dir,
package,
&error_exprs,
&mut mutants,
&mut files,
&progress,
options,
)?;
let (mut package_mutants, mut package_files) =
walk_package(workspace_dir, package, &error_exprs, &progress, options)?;
mutants.append(&mut package_mutants);
files.append(&mut package_files);
}
progress.finish();
Ok(Discovered { mutants, files })
Expand All @@ -90,11 +85,11 @@ fn walk_package(
workspace_dir: &Utf8Path,
package: &Package,
error_exprs: &[Expr],
mutants: &mut Vec<Mutant>,
files: &mut Vec<SourceFile>,
progress: &WalkProgress,
options: &Options,
) -> Result<()> {
) -> Result<(Vec<Mutant>, Vec<SourceFile>)> {
let mut mutants = Vec::new();
let mut files = Vec::new();
let mut filename_queue =
VecDeque::from_iter(package.top_sources.iter().map(|p| (p.to_owned(), true)));
while let Some((path, package_top)) = filename_queue.pop_front() {
Expand Down Expand Up @@ -129,7 +124,7 @@ fn walk_package(
mutants.append(&mut file_mutants);
files.push(source_file);
}
Ok(())
Ok((mutants, files))
}

/// Find all possible mutants in a source file.
Expand Down

0 comments on commit 8d8cfa0

Please sign in to comment.