mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2025-05-19 17:42:52 +00:00
AK: Try to avoid String allocation in FlyString(StringView)
If we're constructing a FlyString from a StringView, and we already have a matching StringImpl in the table, use HashTable::find() to locate the existing string without creating a temporary String.
This commit is contained in:
parent
0f35dfc694
commit
a4099fc756
Notes:
sideshowbarker
2024-07-18 18:06:58 +09:00
Author: https://github.com/awesomekling
Commit: a4099fc756
1 changed files with 15 additions and 2 deletions
|
@ -55,9 +55,22 @@ FlyString::FlyString(const String& string)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
FlyString::FlyString(const StringView& string)
|
FlyString::FlyString(StringView const& string)
|
||||||
: FlyString(static_cast<String>(string))
|
|
||||||
{
|
{
|
||||||
|
if (string.is_null())
|
||||||
|
return;
|
||||||
|
auto it = fly_impls().find(string.hash(), [&](auto& candidate) {
|
||||||
|
return string == candidate;
|
||||||
|
});
|
||||||
|
if (it == fly_impls().end()) {
|
||||||
|
auto new_string = string.to_string();
|
||||||
|
fly_impls().set(new_string.impl());
|
||||||
|
new_string.impl()->set_fly({}, true);
|
||||||
|
m_impl = new_string.impl();
|
||||||
|
} else {
|
||||||
|
VERIFY((*it)->is_fly());
|
||||||
|
m_impl = *it;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
FlyString::FlyString(const char* string)
|
FlyString::FlyString(const char* string)
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue