StringView: Store a StringImpl* rather than a String*.

This commit is contained in:
Andreas Kling 2019-06-08 23:55:13 +02:00
parent 6a51093ab1
commit cdb44be703
Notes: sideshowbarker 2024-07-19 13:40:13 +09:00
3 changed files with 7 additions and 6 deletions

View file

@ -38,8 +38,8 @@ public:
String(const StringView& view) String(const StringView& view)
{ {
if (view.m_string) if (view.m_impl)
*this = String(*view.m_string); m_impl = *view.m_impl;
else else
m_impl = StringImpl::create(view.characters(), view.length()); m_impl = StringImpl::create(view.characters(), view.length());
} }

View file

@ -3,8 +3,8 @@
namespace AK { namespace AK {
StringView::StringView(const AK::String& string) StringView::StringView(const String& string)
: m_string(&string) : m_impl(string.impl())
, m_characters(string.characters()) , m_characters(string.characters())
, m_length(string.length()) , m_length(string.length())
{ {

View file

@ -5,6 +5,7 @@
namespace AK { namespace AK {
class String; class String;
class StringImpl;
class StringView { class StringView {
public: public:
@ -27,7 +28,7 @@ public:
++m_length; ++m_length;
} }
} }
StringView(const AK::String& string); StringView(const String& string);
bool is_null() const { return !m_characters; } bool is_null() const { return !m_characters; }
bool is_empty() const { return m_length == 0; } bool is_empty() const { return m_length == 0; }
@ -59,7 +60,7 @@ public:
private: private:
friend class String; friend class String;
const AK::String* m_string { nullptr }; const StringImpl* m_impl { nullptr };
const char* m_characters { nullptr }; const char* m_characters { nullptr };
int m_length { 0 }; int m_length { 0 };
}; };