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:
Andreas Kling 2020-05-05 10:08:14 +02:00
parent 2a29e668bd
commit e4b9cf9b6c
Notes: sideshowbarker 2024-07-19 06:57:32 +09:00
2 changed files with 24 additions and 0 deletions

View file

@ -63,6 +63,10 @@ FlyString::FlyString(const String& string)
{
if (string.is_null())
return;
if (string.impl()->is_fly()) {
m_impl = string.impl();
return;
}
auto it = fly_impls().find(const_cast<StringImpl*>(string.impl()));
if (it == fly_impls().end()) {
fly_impls().set(const_cast<StringImpl*>(string.impl()));

View file

@ -33,10 +33,30 @@ namespace AK {
class FlyString {
public:
FlyString() {}
FlyString(const FlyString& other)
: m_impl(other.impl())
{
}
FlyString(FlyString&& other)
: m_impl(move(other.m_impl))
{
}
FlyString(const String&);
FlyString(const StringView&);
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_null() const { return !m_impl; }