mirror of
https://github.com/zebrajr/ladybird.git
synced 2025-12-06 00:19:53 +01:00
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:
parent
9bf836e6c4
commit
3ba6d129df
|
|
@ -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();
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -397,6 +397,7 @@ private:
|
|||
mutable Optional<ScopedOperand> m_undefined_constant;
|
||||
mutable Optional<ScopedOperand> m_empty_constant;
|
||||
mutable HashMap<i32, ScopedOperand> m_int32_constants;
|
||||
mutable HashMap<String, ScopedOperand> m_string_constants;
|
||||
|
||||
ScopedOperand m_accumulator;
|
||||
ScopedOperand m_this_value;
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user