mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2024-11-25 00:50: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)
|
||||
{
|
||||
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());
|
||||
}
|
||||
|
|
|
@ -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())
|
||||
{
|
||||
|
|
|
@ -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 };
|
||||
};
|
||||
|
|
Loading…
Reference in a new issue