LibJS: Cache string constants in Generator::add_constant

This mirrors the existing caching logic for int32 constants.
Avoids duplication of string constants in m_constants which could
result in stack overflows for large scripts with a lot of similar
strings.
This commit is contained in:
Julien Le Bras 2025-05-24 15:28:46 +02:00 committed by Alexander Kalenik
parent 9bf836e6c4
commit 3ba6d129df
Notes: github-actions[bot] 2025-06-01 16:27:18 +00:00
2 changed files with 7 additions and 0 deletions

View file

@ -1344,6 +1344,12 @@ ScopedOperand Generator::add_constant(Value value)
return append_new_constant();
});
}
if (value.is_string()) {
auto as_string = value.as_string().utf8_string();
return m_string_constants.ensure(as_string, [&] {
return append_new_constant();
});
}
return append_new_constant();
}