From 9bc005a3bf9787c09c1857a7b6ab51cf7fb95898 Mon Sep 17 00:00:00 2001 From: Johann Hemmann Date: Thu, 4 Jan 2024 15:13:26 +0100 Subject: [PATCH] Only iterate through runnables once --- crates/ide/src/runnables.rs | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/crates/ide/src/runnables.rs b/crates/ide/src/runnables.rs index 851375ce81..7d06032baf 100644 --- a/crates/ide/src/runnables.rs +++ b/crates/ide/src/runnables.rs @@ -567,13 +567,15 @@ mod tests { let mut runnables = analysis.runnables(position.file_id).unwrap(); runnables.sort_by_key(|it| (it.nav.full_range.start(), it.nav.name.clone())); - let navigation_targets = runnables.iter().map(|a| a.nav.clone()).collect::>(); - expect.assert_debug_eq(&navigation_targets); + let mut navigation_targets = Vec::with_capacity(runnables.len()); + let mut test_kinds = Vec::with_capacity(runnables.len()); + for runnable in runnables { + test_kinds.push(runnable.test_kind()); + navigation_targets.push(runnable.nav); + } - assert_eq!( - actions, - runnables.into_iter().map(|it| it.test_kind()).collect::>().as_slice() - ); + expect.assert_debug_eq(&navigation_targets); + assert_eq!(actions, test_kinds.as_slice()); } fn check_tests(ra_fixture: &str, expect: Expect) {