mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2024-11-25 09:00:22 +00:00
StringView: Store a StringImpl* rather than a String*.
This commit is contained in:
parent
6a51093ab1
commit
cdb44be703
Notes:
sideshowbarker
2024-07-19 13:40:13 +09:00
Author: https://github.com/awesomekling Commit: https://github.com/SerenityOS/serenity/commit/cdb44be7033
3 changed files with 7 additions and 6 deletions
|
@ -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());
|
||||||
}
|
}
|
||||||
|
|
|
@ -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())
|
||||||
{
|
{
|
||||||
|
|
|
@ -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 };
|
||||||
};
|
};
|
||||||
|
|
Loading…
Reference in a new issue