You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
perf: detect Latin1-encodable strings at intern time instead of per-c… (boa-dev#4896)
This Pull Request
closesboa-dev#4881
Background-
When the bytecode compiler converts an interned string (`Sym`) to a
`JsString`, it needs to decide whether to store it as Latin1 (1 byte per
character) or UTF-16 (2 bytes per character). Previously, this was done
by scanning every character of the string on each call — even if the
same string was used many times.
What changed-
- The `Interner` now checks once, at the moment a string is first
stored, whether all its characters fit in Latin1 (code point ≤ U+00FF).
The result is saved in a new `latin1_flags` field.
- A new `is_latin1(sym)` method lets callers read that saved result
instantly, without re-scanning the string.
- `ToJsString for Sym` in both `boa_ast` and `boa_engine::bytecompiler`
now calls `is_latin1()` instead of scanning the string's characters
every time.
- `From<&str> for JsString` was also fixed to correctly produce a Latin1
string for characters in the U+0080–U+00FF range, not just plain ASCII.
0 commit comments