Skip to content

perf(git): drop intermediate Vec in format_command join (#4153) - #4204

Closed
wuisabel-gif wants to merge 1 commit into
Hmbown:mainfrom
wuisabel-gif:fix/4153-collect-join
Closed

perf(git): drop intermediate Vec in format_command join (#4153)#4204
wuisabel-gif wants to merge 1 commit into
Hmbown:mainfrom
wuisabel-gif:fix/4153-collect-join

Conversation

@wuisabel-gif

Copy link
Copy Markdown
Contributor

Closes #4153 (v0.8.68 §6.7 / B3.3 — remove collect before join allocations).

What

format_command in crates/tui/src/tools/git.rs collected args into a
Vec<&str> purely to .join(" ") it. Since args is &[String],
<[String]>::join(" ") does the same directly with no intermediate
allocation and byte-identical output.

-        args.iter()
-            .map(String::as_str)
-            .collect::<Vec<_>>()
-            .join(" ")
+        args.join(" ")

finance.rs left as-is

The issue also lists finance.rs, but its site maps
AttemptFailure::summary() which returns an owned String. There is no
Iterator::join in std, so joining requires materializing the Vec
first — the allocation is not unnecessary there. Per the acceptance
note ("where type constraints allow it"), that site is unchanged.

Verification

Output is unchanged. Verified the idiom compiles and the new expression
produces identical output to the old one:

args = ["status", "--porcelain"]
new: args.join(" ")                                   == "status --porcelain"
old: args.iter().map(as_str).collect::<Vec<_>>().join(" ") == "status --porcelain"

@wuisabel-gif
wuisabel-gif requested a review from Hmbown as a code owner July 8, 2026 07:00
@github-actions

github-actions Bot commented Jul 8, 2026

Copy link
Copy Markdown
Contributor

Thanks @wuisabel-gif for taking the time to contribute.

This repository is observing a maintainer-managed PR intake gate in dry-run mode, so this pull request is staying open. This note helps maintainers prepare the allowlist before any enforcement is considered.

Please read CONTRIBUTING.md for the expected contribution shape. A maintainer can grant recurring PR access by commenting /lgtm on a pull request.

format_command collected args into a Vec<&str> only to join it. Since
args is &[String], <[String]>::join(" ") does the same with no
intermediate allocation and identical output.

finance.rs (the other candidate site) is left as-is: its summary()
returns owned String, so joining requires materializing the Vec and no
std Iterator::join exists to remove it.
@wuisabel-gif
wuisabel-gif force-pushed the fix/4153-collect-join branch from 2fe3867 to 582f9e4 Compare July 8, 2026 07:12
@Hmbown

Hmbown commented Jul 8, 2026

Copy link
Copy Markdown
Owner

Superseded by PR #4216 (merged). Issue #4153 is already closed.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

v0.9.0 6.7: remove collect before join allocations

2 participants