Commit Graph

3 Commits

Author SHA1 Message Date
Andreas Kling
ce8f92cf6a LibJS: Reuse cached ASCII strings for substrings
Teach the PrimitiveString substring creation path to return the
VM's preallocated single-character ASCII strings instead of always
allocating a deferred Substring.

This keeps one-code-unit ASCII substrings on the same fast path as
direct string creation, including callers like charAt and indexed
string property access.
2026-04-12 19:15:50 +02:00
Andreas Kling
f6f791969d LibJS: Use Substring for regexp results
Return JS::Substring objects from the builtin regexp exec and split
paths instead of eagerly copying UTF-16 slices into new strings.
Matches, captures, and split pieces can now point back at the original
input until someone asks for the string contents.

Add focused runtime coverage for UTF-16 captures and regex split
captures so these lazy slices stay exercised.
2026-04-11 00:35:36 +02:00
Andreas Kling
1182250414 LibJS: Add deferred PrimitiveString substrings
Introduce JS::Substring as a lazily materialized PrimitiveString
variant that stores an originating string plus a UTF-16 offset and
length. This makes substring creation cheap while still reifying to
a normal string when character data is requested.

Track which short strings actually live in the VM caches so lazily
resolved ropes and substrings do not evict unrelated cached strings
when they are finalized. Add focused unit tests for nested ranges,
rope-backed substrings, surrogate boundaries, and cache behavior.
2026-04-11 00:35:36 +02:00