mirror of
https://github.com/RGBCube/serenity
synced 2025-05-28 19:45:10 +00:00
LibJS: Let the VM cache an empty ("") PrimitiveString
Empty string is extremely common and we can avoid a lot of heap churn by simply caching one in the VM. Primitive strings are immutable anyway so there is no observable behavior change outside of fewer collections.
This commit is contained in:
parent
d1b58ee9ad
commit
69bbf0285b
3 changed files with 8 additions and 0 deletions
|
@ -41,6 +41,8 @@ PrimitiveString::~PrimitiveString()
|
|||
|
||||
PrimitiveString* js_string(Heap& heap, String string)
|
||||
{
|
||||
if (string.is_empty())
|
||||
return &heap.vm().empty_string();
|
||||
return heap.allocate_without_global_object<PrimitiveString>(move(string));
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue