mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2024-11-25 17:10:23 +00:00
AK: Some FlyString improvements
We're now clever enough to notice when we're constructing a FlyString from a String that is actually already a FlyString. :^)
This commit is contained in:
parent
2a29e668bd
commit
e4b9cf9b6c
Notes:
sideshowbarker
2024-07-19 06:57:32 +09:00
Author: https://github.com/awesomekling Commit: https://github.com/SerenityOS/serenity/commit/e4b9cf9b6ca
2 changed files with 24 additions and 0 deletions
|
@ -63,6 +63,10 @@ FlyString::FlyString(const String& string)
|
||||||
{
|
{
|
||||||
if (string.is_null())
|
if (string.is_null())
|
||||||
return;
|
return;
|
||||||
|
if (string.impl()->is_fly()) {
|
||||||
|
m_impl = string.impl();
|
||||||
|
return;
|
||||||
|
}
|
||||||
auto it = fly_impls().find(const_cast<StringImpl*>(string.impl()));
|
auto it = fly_impls().find(const_cast<StringImpl*>(string.impl()));
|
||||||
if (it == fly_impls().end()) {
|
if (it == fly_impls().end()) {
|
||||||
fly_impls().set(const_cast<StringImpl*>(string.impl()));
|
fly_impls().set(const_cast<StringImpl*>(string.impl()));
|
||||||
|
|
|
@ -33,10 +33,30 @@ namespace AK {
|
||||||
class FlyString {
|
class FlyString {
|
||||||
public:
|
public:
|
||||||
FlyString() {}
|
FlyString() {}
|
||||||
|
FlyString(const FlyString& other)
|
||||||
|
: m_impl(other.impl())
|
||||||
|
{
|
||||||
|
}
|
||||||
|
FlyString(FlyString&& other)
|
||||||
|
: m_impl(move(other.m_impl))
|
||||||
|
{
|
||||||
|
}
|
||||||
FlyString(const String&);
|
FlyString(const String&);
|
||||||
FlyString(const StringView&);
|
FlyString(const StringView&);
|
||||||
FlyString(const char*);
|
FlyString(const char*);
|
||||||
|
|
||||||
|
FlyString& operator=(const FlyString& other)
|
||||||
|
{
|
||||||
|
m_impl = other.m_impl;
|
||||||
|
return *this;
|
||||||
|
}
|
||||||
|
|
||||||
|
FlyString& operator=(FlyString&& other)
|
||||||
|
{
|
||||||
|
m_impl = move(other.m_impl);
|
||||||
|
return *this;
|
||||||
|
}
|
||||||
|
|
||||||
bool is_empty() const { return !m_impl || !m_impl->length(); }
|
bool is_empty() const { return !m_impl || !m_impl->length(); }
|
||||||
bool is_null() const { return !m_impl; }
|
bool is_null() const { return !m_impl; }
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue