Revert "LibJS: Use HashMap::ensure() in VM string cache helpers"

This reverts commit 5810ddf339.

Appears to have introduced flakiness on WPT.
This commit is contained in:
Andreas Kling 2025-10-06 12:15:23 +02:00
parent 0d62803f15
commit 7a2fe53c65
Notes: github-actions[bot] 2025-10-06 10:18:09 +00:00
2 changed files with 13 additions and 10 deletions

View file

@ -35,9 +35,12 @@ GC::Ref<PrimitiveString> PrimitiveString::create(VM& vm, Utf16String const& stri
}
auto& string_cache = vm.utf16_string_cache();
return *string_cache.ensure(string, [&] {
return vm.heap().allocate<PrimitiveString>(string);
});
if (auto it = string_cache.find(string); it != string_cache.end())
return *it->value;
auto new_string = vm.heap().allocate<PrimitiveString>(string);
string_cache.set(move(string), new_string);
return *new_string;
}
GC::Ref<PrimitiveString> PrimitiveString::create(VM& vm, Utf16View const& string)
@ -64,9 +67,9 @@ GC::Ref<PrimitiveString> PrimitiveString::create(VM& vm, String const& string)
if (auto it = string_cache.find(string); it != string_cache.end())
return *it->value;
return string_cache.ensure(string, [&] {
return vm.heap().allocate<PrimitiveString>(string);
});
auto new_string = vm.heap().allocate<PrimitiveString>(string);
string_cache.set(move(string), new_string);
return *new_string;
}
GC::Ref<PrimitiveString> PrimitiveString::create(VM& vm, StringView string)

View file

@ -75,12 +75,12 @@ public:
JS_ENUMERATE_WELL_KNOWN_SYMBOLS
#undef __JS_ENUMERATE
HashMap<String, GC::Ref<PrimitiveString>>& string_cache()
HashMap<String, GC::Ptr<PrimitiveString>>& string_cache()
{
return m_string_cache;
}
HashMap<Utf16String, GC::Ref<PrimitiveString>>& utf16_string_cache()
HashMap<Utf16String, GC::Ptr<PrimitiveString>>& utf16_string_cache()
{
return m_utf16_string_cache;
}
@ -323,8 +323,8 @@ private:
void run_queued_promise_jobs_impl();
HashMap<String, GC::Ref<PrimitiveString>> m_string_cache;
HashMap<Utf16String, GC::Ref<PrimitiveString>> m_utf16_string_cache;
HashMap<String, GC::Ptr<PrimitiveString>> m_string_cache;
HashMap<Utf16String, GC::Ptr<PrimitiveString>> m_utf16_string_cache;
static constexpr size_t numeric_string_cache_size = 1000;
AK::Array<GC::Ptr<PrimitiveString>, numeric_string_cache_size> m_numeric_string_cache;