Skip to content

perf(expand): byte-wise case transform for ASCII pattern-less ops - #912

Merged
caomengxuan666 merged 1 commit into
masterfrom
fix/ascii-case-transform
Oct 20, 2026
Merged

caomengxuan666 merged 1 commit into
masterfrom
fix/ascii-case-transform

Conversation

@caomengxuan666

Copy link
Copy Markdown
Member

Follow-up to #608 (remaining string-expansion gap, see niubash#352 re-test).

GNU basis

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 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 a u8 byte 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)

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).
@caomengxuan666
caomengxuan666 merged commit d5cc34d into master Oct 20, 2026
7 of 8 checks passed
@caomengxuan666
caomengxuan666 deleted the fix/ascii-case-transform branch October 20, 2026 08:04
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.

1 participant