mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2025-07-28 11:49:44 +00:00
LibJS: Don't convert to UTF-8 in order to compare two UTF-16 strings
If we have two PrimitiveString objects that are both backed by UTF-16 data, we don't have to convert them to UTF-8 for equality checking. Just compare the underlying UTF-16 data. :^)
This commit is contained in:
parent
e80d1c1a86
commit
d78e3590d5
Notes:
github-actions[bot]
2025-04-12 09:08:53 +00:00
Author: https://github.com/awesomekling
Commit: d78e3590d5
Pull-request: https://github.com/LadybirdBrowser/ladybird/pull/4328
3 changed files with 14 additions and 1 deletions
|
@ -106,6 +106,17 @@ Utf16View PrimitiveString::utf16_string_view() const
|
|||
return m_utf16_string->view();
|
||||
}
|
||||
|
||||
bool PrimitiveString::operator==(PrimitiveString const& other) const
|
||||
{
|
||||
if (this == &other)
|
||||
return true;
|
||||
if (m_utf8_string.has_value() && other.m_utf8_string.has_value())
|
||||
return m_utf8_string->bytes_as_string_view() == other.m_utf8_string->bytes_as_string_view();
|
||||
if (m_utf16_string.has_value() && other.m_utf16_string.has_value())
|
||||
return m_utf16_string->string() == other.m_utf16_string->string();
|
||||
return utf8_string_view() == other.utf8_string_view();
|
||||
}
|
||||
|
||||
ThrowCompletionOr<Optional<Value>> PrimitiveString::get(VM& vm, PropertyKey const& property_key) const
|
||||
{
|
||||
if (property_key.is_symbol())
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue