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

Side by Side Diff: third_party/WebKit/Source/wtf/text/StringView.cpp

Issue 2597273002: Allow StringView to have the sole reference to a static string (Closed)
Patch Set: Created 3 years, 12 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 unified diff | Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2016 The Chromium Authors. All rights reserved. 1 // Copyright 2016 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "wtf/text/StringView.h" 5 #include "wtf/text/StringView.h"
6 6
7 #include "wtf/text/AtomicString.h" 7 #include "wtf/text/AtomicString.h"
8 #include "wtf/text/StringImpl.h" 8 #include "wtf/text/StringImpl.h"
9 #include "wtf/text/WTFString.h" 9 #include "wtf/text/WTFString.h"
10 10
11 namespace WTF { 11 namespace WTF {
12 12
13 StringView::StringView(const UChar* chars) 13 StringView::StringView(const UChar* chars)
14 : StringView(chars, chars ? lengthOfNullTerminatedString(chars) : 0) {} 14 : StringView(chars, chars ? lengthOfNullTerminatedString(chars) : 0) {}
15 15
16 #if DCHECK_IS_ON() 16 #if DCHECK_IS_ON()
17 StringView::~StringView() { 17 StringView::~StringView() {
18 DCHECK(m_impl); 18 DCHECK(m_impl);
19 DCHECK(!m_impl->hasOneRef()) << "StringView does not own the StringImpl, it " 19 DCHECK(!m_impl->hasOneRef() || m_impl->isStatic())
20 "must not have the last ref."; 20 << "StringView does not own the StringImpl, it "
21 "must not have the last ref.";
21 } 22 }
22 #endif 23 #endif
23 24
24 String StringView::toString() const { 25 String StringView::toString() const {
25 if (isNull()) 26 if (isNull())
26 return String(); 27 return String();
27 if (isEmpty()) 28 if (isEmpty())
28 return emptyString(); 29 return emptyString();
29 if (StringImpl* impl = sharedImpl()) 30 if (StringImpl* impl = sharedImpl())
30 return impl; 31 return impl;
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after
91 return equalIgnoringASCIICase(a.characters8(), b.characters16(), 92 return equalIgnoringASCIICase(a.characters8(), b.characters16(),
92 a.length()); 93 a.length());
93 } 94 }
94 if (b.is8Bit()) 95 if (b.is8Bit())
95 return equalIgnoringASCIICase(a.characters16(), b.characters8(), 96 return equalIgnoringASCIICase(a.characters16(), b.characters8(),
96 a.length()); 97 a.length());
97 return equalIgnoringASCIICase(a.characters16(), b.characters16(), a.length()); 98 return equalIgnoringASCIICase(a.characters16(), b.characters16(), a.length());
98 } 99 }
99 100
100 } // namespace WTF 101 } // namespace WTF
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698