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)
{
if (view.m_string)
*this = String(*view.m_string);
if (view.m_impl)
m_impl = *view.m_impl;
else
m_impl = StringImpl::create(view.characters(), view.length());
}

View file

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

View file

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