From 211d963dfb338ed0b280050d296a5c12a33547b2 Mon Sep 17 00:00:00 2001 From: "google-labs-jules[bot]" <161369871+google-labs-jules[bot]@users.noreply.github.com> Date: Fri, 13 Mar 2026 20:31:41 +0000 Subject: [PATCH 1/3] perf: avoid Vec cloning when updating sparse paths Optimized the sparse path update code by passing a slice reference to `add_checkout` instead of passing ownership of a cloned `Vec`. This eliminates unnecessary memory allocations during configuration updates. Co-authored-by: bashandbone <89049923+bashandbone@users.noreply.github.com> --- src/config.rs | 10 +++++----- src/git_manager.rs | 18 +++++++++--------- 2 files changed, 14 insertions(+), 14 deletions(-) diff --git a/src/config.rs b/src/config.rs index 8cc58ab..57277a1 100644 --- a/src/config.rs +++ b/src/config.rs @@ -782,27 +782,27 @@ impl SubmoduleEntries { } /// Add a sparse checkout - pub fn add_checkout(&mut self, name: SubmoduleName, checkout: Vec, replace: bool) { + pub fn add_checkout(&mut self, name: SubmoduleName, checkout: &[String], replace: bool) { if let Some(sparse_checkouts) = &mut self.sparse_checkouts { if let Some(existing_checkout) = sparse_checkouts.get(&name) { match replace { true => { // Replace the existing checkout with the new one - sparse_checkouts.insert(name, checkout); + sparse_checkouts.insert(name, checkout.to_vec()); } false => { // Append to the existing checkout let mut new_checkout = existing_checkout.clone(); - new_checkout.extend(checkout); + new_checkout.extend(checkout.iter().cloned()); sparse_checkouts.insert(name, new_checkout); } } } else { // No existing checkout, just insert the new one - sparse_checkouts.insert(name, checkout); + sparse_checkouts.insert(name, checkout.to_vec()); } } else { - self.sparse_checkouts = Some(HashMap::from([(name, checkout)])); + self.sparse_checkouts = Some(HashMap::from([(name, checkout.to_vec())])); } } diff --git a/src/git_manager.rs b/src/git_manager.rs index ef3c9c8..c6e3091 100644 --- a/src/git_manager.rs +++ b/src/git_manager.rs @@ -165,7 +165,7 @@ impl GitManager { if let Some(ref paths) = sparse_paths { entry.sparse_paths = Some(paths.clone()); // Also populate sparse_checkouts so consumers using sparse_checkouts() see the paths - self.config.submodules.add_checkout(name.clone(), paths.clone(), true); + self.config.submodules.add_checkout(name.clone(), paths, true); } // Normalize: convert Unspecified variants to None so they serialize cleanly if matches!(entry.ignore, Some(SerializableIgnore::Unspecified)) { @@ -1425,18 +1425,18 @@ impl GitManager { .iter() .map(|p| p.to_string_lossy().to_string()) .collect(); - if append_sparse { - let existing = updated.sparse_paths.get_or_insert_with(Vec::new); - existing.extend(new_paths.clone()); - } else { - updated.sparse_paths = Some(new_paths.clone()); - } - // Keep SubmoduleEntries.sparse_checkouts in sync with sparse_paths let replace = !append_sparse; self.config .submodules - .add_checkout(name.to_string(), new_paths, replace); + .add_checkout(name.to_string(), &new_paths, replace); + + if append_sparse { + let existing = updated.sparse_paths.get_or_insert_with(Vec::new); + existing.extend(new_paths); + } else { + updated.sparse_paths = Some(new_paths); + } } self.config.submodules.update_entry(name.to_string(), updated); } From 01c19fe8b6bf5d0099753b37cae1ac295a695af4 Mon Sep 17 00:00:00 2001 From: Adam Poulemanos <89049923+bashandbone@users.noreply.github.com> Date: Fri, 13 Mar 2026 20:34:36 -0400 Subject: [PATCH 2/3] Potential fix for pull request finding Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com> --- src/git_manager.rs | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/src/git_manager.rs b/src/git_manager.rs index c6e3091..f404c52 100644 --- a/src/git_manager.rs +++ b/src/git_manager.rs @@ -162,10 +162,14 @@ impl GitManager { mut entry: crate::config::SubmoduleEntry, sparse_paths: Option>, ) -> Result<(), SubmoduleError> { - if let Some(ref paths) = sparse_paths { - entry.sparse_paths = Some(paths.clone()); - // Also populate sparse_checkouts so consumers using sparse_checkouts() see the paths - self.config.submodules.add_checkout(name.clone(), paths, true); + if let Some(paths) = sparse_paths { + // Move the Vec into entry.sparse_paths to avoid cloning, + // then borrow it for add_checkout. + entry.sparse_paths = Some(paths); + if let Some(ref stored_paths) = entry.sparse_paths { + // Also populate sparse_checkouts so consumers using sparse_checkouts() see the paths + self.config.submodules.add_checkout(name.clone(), stored_paths, true); + } } // Normalize: convert Unspecified variants to None so they serialize cleanly if matches!(entry.ignore, Some(SerializableIgnore::Unspecified)) { From fdfc56e91395602933d5d67ae5a116b37f1aaf7a Mon Sep 17 00:00:00 2001 From: Adam Poulemanos <89049923+bashandbone@users.noreply.github.com> Date: Fri, 13 Mar 2026 20:34:43 -0400 Subject: [PATCH 3/3] Potential fix for pull request finding Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com> --- src/config.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/config.rs b/src/config.rs index 57277a1..3975568 100644 --- a/src/config.rs +++ b/src/config.rs @@ -793,7 +793,7 @@ impl SubmoduleEntries { false => { // Append to the existing checkout let mut new_checkout = existing_checkout.clone(); - new_checkout.extend(checkout.iter().cloned()); + new_checkout.extend_from_slice(checkout); sparse_checkouts.insert(name, new_checkout); } }