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
parent 0c3f113e05
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

@@ -1141,7 +1141,7 @@ ThrowCompletionOr<GC::RootVector<Value>> Object::internal_own_property_keys() co
// 2. For each own property key P of O such that P is an array index, in ascending numeric index order, do
for (auto& entry : m_indexed_properties) {
// a. Add P as the last element of keys.
keys.append(PrimitiveString::create(vm, String::number(entry.index())));
keys.append(PrimitiveString::create_from_unsigned_integer(vm, entry.index()));
}
// 3. For each own property key P of O such that Type(P) is String and P is not an array index, in ascending chronological order of property creation, do