Skip to content

Commit 8d8cfa0

Browse files
committed
Refactor package walk code
Don't pass mutable vecs around
1 parent 2005a6d commit 8d8cfa0

File tree

1 file changed

+9
-14
lines changed

1 file changed

+9
-14
lines changed

src/visit.rs

Lines changed: 9 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// Copyright 2021-2024 Martin Pool
1+
// Copyright 2021 - 2025 Martin Pool
22

33
//! Visit all the files in a source tree, and then the AST of each file,
44
//! to discover mutation opportunities.
@@ -69,15 +69,10 @@ pub fn walk_tree(
6969
let error_exprs = options.parsed_error_exprs()?;
7070
let progress = console.start_walk_tree();
7171
for package in packages {
72-
walk_package(
73-
workspace_dir,
74-
package,
75-
&error_exprs,
76-
&mut mutants,
77-
&mut files,
78-
&progress,
79-
options,
80-
)?;
72+
let (mut package_mutants, mut package_files) =
73+
walk_package(workspace_dir, package, &error_exprs, &progress, options)?;
74+
mutants.append(&mut package_mutants);
75+
files.append(&mut package_files);
8176
}
8277
progress.finish();
8378
Ok(Discovered { mutants, files })
@@ -90,11 +85,11 @@ fn walk_package(
9085
workspace_dir: &Utf8Path,
9186
package: &Package,
9287
error_exprs: &[Expr],
93-
mutants: &mut Vec<Mutant>,
94-
files: &mut Vec<SourceFile>,
9588
progress: &WalkProgress,
9689
options: &Options,
97-
) -> Result<()> {
90+
) -> Result<(Vec<Mutant>, Vec<SourceFile>)> {
91+
let mut mutants = Vec::new();
92+
let mut files = Vec::new();
9893
let mut filename_queue =
9994
VecDeque::from_iter(package.top_sources.iter().map(|p| (p.to_owned(), true)));
10095
while let Some((path, package_top)) = filename_queue.pop_front() {
@@ -129,7 +124,7 @@ fn walk_package(
129124
mutants.append(&mut file_mutants);
130125
files.push(source_file);
131126
}
132-
Ok(())
127+
Ok((mutants, files))
133128
}
134129

135130
/// Find all possible mutants in a source file.

0 commit comments

Comments
 (0)