Repository navigation
perf(expand): byte-wise case transform for ASCII pattern-less ops - #912
Merged
Merged
Conversation
lib/sh/casemod.c:99 sh_modcase skips the per-character strmatch when pat is NULL and transforms directly. ASCII case pairs map 1:1, so a byte-wise pass over ASCII input is exactly equivalent and skips UTF-8 decode plus the per-char iterator chain; multibyte input keeps the char path (verified byte-identical vs GNU bash 5.3, including non-ASCII ^^/,,/~~ and patterned forms). Measured on-device (aarch64, best-of-3): 500KB x20 transforms 121ms -> 99ms (-18%); 30k x 36-char loop unchanged (fixed per-expansion dispatch cost dominates there — tracked follow-up, same direction as #608).
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.
Follow-up to #608 (remaining string-expansion gap, see niubash#352 re-test).
GNU basis
lib/sh/casemod.c:99 sh_modcaseskips the per-characterstrmatchwhenpatis NULL and transforms directly. ASCII case pairs map 1:1 in every locale, so a byte-wise pass over ASCII input is exactly equivalent — no matcher, no UTF-8 decode, no per-char iterator chain. Multibyte input keeps the existing char path untouched.Change (
src/executor/parameter_case.rs, +25)Pattern-less
${x^^}/${x,,}/${x~~}on ASCII input take au8byte loop (to_ascii_uppercase/to_ascii_lowercase); everything else (First ops, patterns, multibyte) is byte-identical to before.Verification (Android/Termux aarch64, best-of-3, release builds)
^^/ ,,~~/^/,/\~, non-ASCII (hélloÜßΣ), empty, patterned forms — all byte-identical vs GNU bash 5.3.20 on-device. (Note: pre-existingß→SSUnicode-vs-locale divergence exists on master too, out of scope.)cli_tests466/466, lib 634/634,executor_tests11 pre-existing Android-env failures only (identical set to the pristine-HEAD baseline worktree run).