Improve performance of std.stripChars and std.trim functions#555
Merged
stephenamar-db merged 1 commit intomasterfrom Nov 24, 2025
Merged
Improve performance of std.stripChars and std.trim functions#555stephenamar-db merged 1 commit intomasterfrom
stephenamar-db merged 1 commit intomasterfrom
Conversation
abd85a9 to
ae243d0
Compare
He-Pin
reviewed
Nov 21, 2025
ae243d0 to
ba30c98
Compare
…using regular expressions
ba30c98 to
31447e7
Compare
stephenamar-db
pushed a commit
that referenced
this pull request
Dec 4, 2025
#560) This is a followup to #555 and the subsequent fix in #557. Even after that fix, there are two remaining bugs related to stripping from the right side of a string: 1. Stripping emoji from end: `std.rstripChars("hello🎉🎉🎉", "🎉")` returned `"hello🎉🎉🎉"` instead of `"hello"` (nothing stripped) 2. Stripping ASCII after emoji: `std.trim("🌍 ")` returned `"?"` instead of`"🌍"` (i.e. the emoji was corrupted) The root cause (explained by Claude) is that when iterating from the right of a string, `codePointAt(str.length - 1)` points to a low surrogate and it gets treated as an unpaired surrogate rather than seeking backwards to find the full code point. The fix: use `codePointBefore(end)` (where `end` ranges from `string.length` down to `1`) for right-to-left iteration. Unlike `codePointAt()`, `codePointBefore()` correctly reads surrogate pairs when scanning backwards. Fix + test are authored by Claude Code. Co-authored-by: Claude <noreply@anthropic.com>
stephenamar-db
added a commit
that referenced
this pull request
Dec 4, 2025
Remove regular expressions usage - it's an overkill. Before: ``` [1-113] Java HotSpot(TM) 64-Bit Server VM warning: -XX:ThreadPriorityPolicy=1 may require system level permission, e.g., being the root user. If the necessary permission is not possessed, changes to priority will be silently ignored. 0.943 ms/op 0.761 ms/op ``` After: ``` [1-113] Java HotSpot(TM) 64-Bit Server VM warning: -XX:ThreadPriorityPolicy=1 may require system level permission, e.g., being the root user. If the necessary permission is not possessed, changes to priority will be silently ignored. 0.790 ms/op 0.674 ms/op ```
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.
Remove regular expressions usage - it's an overkill.
Before:
After: