From db39a692049215bd85ceda462de6d8744f828ce0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Miguel=20Raz=20Guzm=C3=A1n=20Macedo?= Date: Mon, 17 Aug 2026 11:55:48 -0600 Subject: [PATCH] Remove wasted clones of loop-invariant values Found by a new deep_clone_in_loop dylint modeled on the accidentally quadratic search fix (#62658). None of these were quadratic in practice, but each paid an avoidable copy: - collab: take() the S3 pagination marker instead of cloning it; it is overwritten or the loop breaks before the next read. - project: build Arc directly from the borrowed path in path_trie, avoiding a clone-then-copy double allocation. - context_server: move the notification payload into the last handler instead of cloning it for every handler. - editor: mem::replace the rewrap accumulators instead of cloning them on every range boundary. --- crates/collab/src/api/extensions.rs | 2 +- crates/context_server/src/client.rs | 11 ++++++++--- crates/editor/src/rewrap.rs | 9 +++++---- crates/project/src/manifest_tree/path_trie.rs | 6 +++--- 4 files changed, 17 insertions(+), 11 deletions(-) diff --git a/crates/collab/src/api/extensions.rs b/crates/collab/src/api/extensions.rs index c350895ff4543f..627948b2678b0f 100644 --- a/crates/collab/src/api/extensions.rs +++ b/crates/collab/src/api/extensions.rs @@ -217,7 +217,7 @@ async fn fetch_extensions_from_blob_store( .list_objects() .bucket(blob_store_bucket) .prefix("extensions/") - .set_marker(next_marker.clone()) + .set_marker(next_marker.take()) .send() .await?; let objects = list.contents.unwrap_or_default(); diff --git a/crates/context_server/src/client.rs b/crates/context_server/src/client.rs index 4e41ed98e250f1..b88bc301db72a2 100644 --- a/crates/context_server/src/client.rs +++ b/crates/context_server/src/client.rs @@ -592,9 +592,14 @@ impl NotificationSubscriptionSet { return; }; - for handler_id in handler_ids { - if let Some(handler) = self.handlers.get_mut(*handler_id) { - handler(payload.clone(), cx.clone()); + if let Some((last_handler_id, handler_ids)) = handler_ids.split_last() { + for handler_id in handler_ids { + if let Some(handler) = self.handlers.get_mut(*handler_id) { + handler(payload.clone(), cx.clone()); + } + } + if let Some(handler) = self.handlers.get_mut(*last_handler_id) { + handler(payload, cx.clone()); } } } diff --git a/crates/editor/src/rewrap.rs b/crates/editor/src/rewrap.rs index 9f39af1fcc06f1..e8df9d7cc4eeb6 100644 --- a/crates/editor/src/rewrap.rs +++ b/crates/editor/src/rewrap.rs @@ -191,13 +191,14 @@ impl Editor { Point::new(current_range_start, 0) ..Point::new(prev_row, buffer.line_len(MultiBufferRow(prev_row))), current_range_indent, - current_range_comment_delimiters.clone(), - current_range_rewrap_prefix.clone(), + std::mem::replace( + &mut current_range_comment_delimiters, + row_comment_delimiters, + ), + std::mem::replace(&mut current_range_rewrap_prefix, row_rewrap_prefix), )); current_range_start = row; current_range_indent = row_indent; - current_range_comment_delimiters = row_comment_delimiters; - current_range_rewrap_prefix = row_rewrap_prefix; } prev_row = row; } diff --git a/crates/project/src/manifest_tree/path_trie.rs b/crates/project/src/manifest_tree/path_trie.rs index ba0a3619e7d967..a3c763331d6b1f 100644 --- a/crates/project/src/manifest_tree/path_trie.rs +++ b/crates/project/src/manifest_tree/path_trie.rs @@ -64,9 +64,9 @@ impl RootPathTrie