bash: build option/subcommand strings directly - #238
Open
haydonryan wants to merge 1 commit into
Open
Conversation
In generate_bash_dispatch, build the opts, cmds, and prev_matches strings by accumulating directly into a String (push/push_str with separators) instead of collecting per-item Strings into a Vec and joining them. Same output; fewer heap allocations and less monomorphized generic code (Vec<String> + SliceConcatExt::join + format! removed from this function). Measured: -2280 bytes text on completion_example (release, default profile).
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Hi there,
I'm experimenting with prompts for LLMs to finding code optimizations (size and speed), and ran it over this crate. It popped up with a few small improvements. This is one.
LLM Generated below here:
In
argh_complete::bash::generate_bash_dispatch, three lists were built bycollecting per-item
Strings into aVec<String>and thenjoin-ing them:the
optslist, thecmdslist, and theprev_matcheslist. This PR buildsall three directly by accumulating into a single
String(push/push_strwith separators).
Why it saves binary space
String(via.to_string()/format!)and no
joinresultString— one buffer filled in place.Vec<String>instantiation and theSliceConcatExt::joinmonomorphization forVec<String>, plus theformat!/Displaymachinery at each call site.Measurement
Release-mode text-size deltas on
completion_example(default profile),Measured with and without LTO (default release profile
has no LTO;
lto=trueis the full/fat LTO the testbed uses):lto=true)Under fat LTO the win roughly halves (−1,272) because LTO already folds much
of the redundant
Vec/join/format!code the change targets. The headlinenumber is the no-LTO case: −2,280 bytes.
Behavior unchanged — verified by the
argh_completeexact-match tests passingand the full workspace suite (13 suites, 0 failures).