Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(147)

Unified Diff: third_party/WebKit/Source/wtf/text/StringView.cpp

Issue 2033293002: Implement StringImpl sharing for StringView::toString(). (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Fix preload scanner bug. Created 4 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: third_party/WebKit/Source/wtf/text/StringView.cpp
diff --git a/third_party/WebKit/Source/wtf/text/StringView.cpp b/third_party/WebKit/Source/wtf/text/StringView.cpp
index 8fc2238358b8962926da02415899ce2e60080681..e88703b8ce5ceadd2e0c33696a2aad2cc361e441 100644
--- a/third_party/WebKit/Source/wtf/text/StringView.cpp
+++ b/third_party/WebKit/Source/wtf/text/StringView.cpp
@@ -6,21 +6,15 @@
namespace WTF {
-StringView::StringView(const UChar* chars, unsigned length)
- : m_length(length)
- , m_is8Bit(false)
-{
- m_data.characters16 = chars;
-}
-
StringView::StringView(const UChar* chars)
: StringView(chars, chars ? lengthOfNullTerminatedString(chars) : 0) {}
#if DCHECK_IS_ON()
StringView::~StringView()
{
- // StringView does not own the StringImpl, we must not be the last ref.
- DCHECK(!m_impl || !m_impl->hasOneRef());
+ DCHECK(m_impl);
+ DCHECK(!m_impl->hasOneRef())
+ << "StringView does not own the StringImpl, it must not have the last ref.";
}
#endif
@@ -30,9 +24,11 @@ String StringView::toString() const
return String();
if (isEmpty())
return emptyString();
+ if (StringImpl* impl = sharedImpl())
+ return impl;
if (is8Bit())
- return String(m_data.characters8, m_length);
- return StringImpl::create8BitIfPossible(m_data.characters16, m_length);
+ return String(characters8(), m_length);
+ return StringImpl::create8BitIfPossible(characters16(), m_length);
}
AtomicString StringView::toAtomicString() const
@@ -41,9 +37,11 @@ AtomicString StringView::toAtomicString() const
return nullAtom;
if (isEmpty())
return emptyAtom;
+ if (StringImpl* impl = sharedImpl())
+ return AtomicString(impl);
if (is8Bit())
- return AtomicString(m_data.characters8, m_length);
- return AtomicString(m_data.characters16, m_length);
+ return AtomicString(characters8(), m_length);
+ return AtomicString(characters16(), m_length);
}
bool equalStringView(const StringView& a, const StringView& b)

Powered by Google App Engine
This is Rietveld 408576698