LibJS: Add number-to-string cache for numbers < 1000

We are often forced to convert numbers to strings inside LibJS, e.g when
iterating over the property names of an array, but it's also just a very
common operation in general.

This patch adds a 1000-entry string cache for the numbers 0-999 since
those appear to be by far the most common ones we convert.
This commit is contained in:
Andreas Kling 2025-10-04 11:00:20 +02:00 committed by Andreas Kling
commit b691f4c7af
Notes: github-actions[bot] 2025-10-05 19:45:30 +00:00
12 changed files with 33 additions and 8 deletions

View file

@ -245,7 +245,7 @@ JS::ThrowCompletionOr<GC::RootVector<JS::Value>> WindowProxy::internal_own_prope
// 5. Repeat while index < maxProperties,
for (size_t i = 0; i < max_properties; ++i) {
// 1. Add ! ToString(index) as the last element of keys.
keys.append(JS::PrimitiveString::create(vm, ByteString::number(i)));
keys.append(JS::PrimitiveString::create_from_unsigned_integer(vm, i));
// 2. Increment index by 1.
}