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

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

Issue 2668903003: Replace WTF::emptyString{16Bit}() with a static global (Closed)
Patch Set: Replace WTF::emptyString{16Bit}() with a static global Created 3 years, 10 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
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() || m_impl->isStatic()) 19 DCHECK(!m_impl->hasOneRef() || m_impl->isStatic())
20 << "StringView does not own the StringImpl, it " 20 << "StringView does not own the StringImpl, it "
21 "must not have the last ref."; 21 "must not have the last ref.";
22 } 22 }
23 #endif 23 #endif
24 24
25 String StringView::toString() const { 25 String StringView::toString() const {
26 if (isNull()) 26 if (isNull())
27 return String(); 27 return String();
28 if (isEmpty()) 28 if (isEmpty())
29 return emptyString(); 29 return emptyString;
30 if (StringImpl* impl = sharedImpl()) 30 if (StringImpl* impl = sharedImpl())
31 return impl; 31 return impl;
32 if (is8Bit()) 32 if (is8Bit())
33 return String(characters8(), m_length); 33 return String(characters8(), m_length);
34 return StringImpl::create8BitIfPossible(characters16(), m_length); 34 return StringImpl::create8BitIfPossible(characters16(), m_length);
35 } 35 }
36 36
37 AtomicString StringView::toAtomicString() const { 37 AtomicString StringView::toAtomicString() const {
38 if (isNull()) 38 if (isNull())
39 return nullAtom; 39 return nullAtom;
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after
92 return equalIgnoringASCIICase(a.characters8(), b.characters16(), 92 return equalIgnoringASCIICase(a.characters8(), b.characters16(),
93 a.length()); 93 a.length());
94 } 94 }
95 if (b.is8Bit()) 95 if (b.is8Bit())
96 return equalIgnoringASCIICase(a.characters16(), b.characters8(), 96 return equalIgnoringASCIICase(a.characters16(), b.characters8(),
97 a.length()); 97 a.length());
98 return equalIgnoringASCIICase(a.characters16(), b.characters16(), a.length()); 98 return equalIgnoringASCIICase(a.characters16(), b.characters16(), a.length());
99 } 99 }
100 100
101 } // namespace WTF 101 } // namespace WTF
OLDNEW
« no previous file with comments | « third_party/WebKit/Source/wtf/text/StringStatics.cpp ('k') | third_party/WebKit/Source/wtf/text/StringViewTest.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698