From 4b5158b1685900ba38ca0603ae5291b2572eba53 Mon Sep 17 00:00:00 2001 From: tidely <43219534+tidely@users.noreply.github.com> Date: Thu, 8 May 2025 12:59:56 +0200 Subject: [PATCH] indexed_docs: Remove some unnecessary cloning (#30236) Other small patch to reduce allocations. `.iter().cloned().collect()` calls `Clone` per element, whereas `.into_iter().collect()` preallocates the `Vec`. The Zed repo for example has up to 1700 packages on some build configurations, meaning this change theoretically saves up to 1699 allocations. It's likely the compiler has already optimized this away, but it's good to be explicit. Release Notes: - N/A --- crates/indexed_docs/src/providers/rustdoc.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/crates/indexed_docs/src/providers/rustdoc.rs b/crates/indexed_docs/src/providers/rustdoc.rs index 75c522c6ca..3fac966a4a 100644 --- a/crates/indexed_docs/src/providers/rustdoc.rs +++ b/crates/indexed_docs/src/providers/rustdoc.rs @@ -79,7 +79,7 @@ impl IndexedDocsProvider for LocalRustdocProvider { *WORKSPACE_CRATES.write() = Some((workspace_crates.clone(), Instant::now())); - Ok(workspace_crates.iter().cloned().collect()) + Ok(workspace_crates.into_iter().collect()) } async fn index(&self, package: PackageName, database: Arc) -> Result<()> {