mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2024-11-21 23:20:20 +00:00
StringView: Make construction of String from a StringView containing a String cheaper
... at the cost of an additional pointer per view.
This commit is contained in:
parent
8fecc0eaee
commit
f9ba7adae2
Notes:
sideshowbarker
2024-07-19 13:45:40 +09:00
Author: https://github.com/rburchell Commit: https://github.com/SerenityOS/serenity/commit/f9ba7adae2e Pull-request: https://github.com/SerenityOS/serenity/pull/170 Reviewed-by: https://github.com/awesomekling
3 changed files with 9 additions and 3 deletions
|
@ -36,9 +36,12 @@ public:
|
|||
|
||||
String() {}
|
||||
|
||||
String(StringView view)
|
||||
: m_impl(StringImpl::create(view.characters(), view.length()))
|
||||
String(const StringView& view)
|
||||
{
|
||||
if (view.m_string)
|
||||
*this = String(*view.m_string);
|
||||
else
|
||||
m_impl = StringImpl::create(view.characters(), view.length());
|
||||
}
|
||||
|
||||
String(const String& other)
|
||||
|
|
|
@ -4,7 +4,8 @@
|
|||
namespace AK {
|
||||
|
||||
StringView::StringView(const AK::String& string)
|
||||
: m_characters(string.characters())
|
||||
: m_string(&string)
|
||||
, m_characters(string.characters())
|
||||
, m_length(string.length())
|
||||
{
|
||||
}
|
||||
|
|
|
@ -44,6 +44,8 @@ public:
|
|||
bool operator==(const String&) const;
|
||||
|
||||
private:
|
||||
friend class String;
|
||||
const AK::String* m_string { nullptr };
|
||||
const char* m_characters { nullptr };
|
||||
int m_length { 0 };
|
||||
};
|
||||
|
|
Loading…
Reference in a new issue