mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2025-07-28 19:59:17 +00: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
Notes:
github-actions[bot]
2025-06-01 16:27:18 +00:00
Author: https://github.com/jlebras 🔰
Commit: 3ba6d129df
Pull-request: https://github.com/LadybirdBrowser/ladybird/pull/4932
Reviewed-by: https://github.com/kalenikaliaksandr ✅
2 changed files with 7 additions and 0 deletions
|
@ -1344,6 +1344,12 @@ ScopedOperand Generator::add_constant(Value value)
|
||||||
return append_new_constant();
|
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();
|
return append_new_constant();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -397,6 +397,7 @@ private:
|
||||||
mutable Optional<ScopedOperand> m_undefined_constant;
|
mutable Optional<ScopedOperand> m_undefined_constant;
|
||||||
mutable Optional<ScopedOperand> m_empty_constant;
|
mutable Optional<ScopedOperand> m_empty_constant;
|
||||||
mutable HashMap<i32, ScopedOperand> m_int32_constants;
|
mutable HashMap<i32, ScopedOperand> m_int32_constants;
|
||||||
|
mutable HashMap<String, ScopedOperand> m_string_constants;
|
||||||
|
|
||||||
ScopedOperand m_accumulator;
|
ScopedOperand m_accumulator;
|
||||||
ScopedOperand m_this_value;
|
ScopedOperand m_this_value;
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue