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

Side by Side Diff: Source/wtf/text/StringImpl.h

Issue 587173005: Add WTF::String::emptyString16Bit (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: Created 6 years, 3 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 | Source/wtf/text/StringStatics.cpp » ('j') | Source/wtf/text/WTFString.h » ('J')
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 /* 1 /*
2 * Copyright (C) 1999 Lars Knoll (knoll@kde.org) 2 * Copyright (C) 1999 Lars Knoll (knoll@kde.org)
3 * Copyright (C) 2005, 2006, 2007, 2008, 2009, 2010, 2013 Apple Inc. All rights reserved. 3 * Copyright (C) 2005, 2006, 2007, 2008, 2009, 2010, 2013 Apple Inc. All rights reserved.
4 * Copyright (C) 2009 Google Inc. All rights reserved. 4 * Copyright (C) 2009 Google Inc. All rights reserved.
5 * 5 *
6 * This library is free software; you can redistribute it and/or 6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Library General Public 7 * modify it under the terms of the GNU Library General Public
8 * License as published by the Free Software Foundation; either 8 * License as published by the Free Software Foundation; either
9 * version 2 of the License, or (at your option) any later version. 9 * version 2 of the License, or (at your option) any later version.
10 * 10 *
(...skipping 107 matching lines...) Expand 10 before | Expand all | Expand 10 after
118 118
119 private: 119 private:
120 // StringImpls are allocated out of the WTF buffer partition. 120 // StringImpls are allocated out of the WTF buffer partition.
121 void* operator new(size_t); 121 void* operator new(size_t);
122 void* operator new(size_t, void* ptr) { return ptr; }; 122 void* operator new(size_t, void* ptr) { return ptr; };
123 void operator delete(void*); 123 void operator delete(void*);
124 124
125 // Used to construct static strings, which have an special refCount that can never hit zero. 125 // Used to construct static strings, which have an special refCount that can never hit zero.
126 // This means that the static string will never be destroyed, which is impor tant because 126 // This means that the static string will never be destroyed, which is impor tant because
127 // static strings will be shared across threads & ref-counted in a non-threa dsafe manner. 127 // static strings will be shared across threads & ref-counted in a non-threa dsafe manner.
128 enum ConstructEmptyStringTag { ConstructEmptyString }; 128 enum ConstructEmptyStringTag { ConstructEmpty8BitString, ConstructEmpty16Bit String };
129 explicit StringImpl(ConstructEmptyStringTag) 129 explicit StringImpl(ConstructEmptyStringTag tag)
130 : m_refCount(1) 130 : m_refCount(1)
131 , m_length(0) 131 , m_length(0)
132 , m_hash(0) 132 , m_hash(0)
133 , m_isAtomic(false) 133 , m_isAtomic(false)
134 , m_is8Bit(true) 134 , m_is8Bit(tag == ConstructEmpty8BitString)
Mikhail 2014/09/23 09:48:10 think this is not enough, see below there is: STRI
135 , m_isStatic(true) 135 , m_isStatic(true)
136 { 136 {
137 // Ensure that the hash is computed so that AtomicStringHash can call ex istingHash() 137 // Ensure that the hash is computed so that AtomicStringHash can call ex istingHash()
138 // with impunity. The empty string is special because it is never entere d into 138 // with impunity. The empty string is special because it is never entere d into
139 // AtomicString's HashKey, but still needs to compare correctly. 139 // AtomicString's HashKey, but still needs to compare correctly.
140 STRING_STATS_ADD_8BIT_STRING(m_length); 140 STRING_STATS_ADD_8BIT_STRING(m_length);
141 hash(); 141 hash();
142 } 142 }
143 143
144 // FIXME: there has to be a less hacky way to do this. 144 // FIXME: there has to be a less hacky way to do this.
(...skipping 138 matching lines...) Expand 10 before | Expand all | Expand 10 after
283 ALWAYS_INLINE void deref() 283 ALWAYS_INLINE void deref()
284 { 284 {
285 if (hasOneRef()) { 285 if (hasOneRef()) {
286 destroyIfNotStatic(); 286 destroyIfNotStatic();
287 return; 287 return;
288 } 288 }
289 289
290 --m_refCount; 290 --m_refCount;
291 } 291 }
292 292
293 enum Force16Bit { Force16BitEmpty };
293 static StringImpl* empty(); 294 static StringImpl* empty();
295 static StringImpl* empty(Force16Bit);
294 296
295 // FIXME: Does this really belong in StringImpl? 297 // FIXME: Does this really belong in StringImpl?
296 template <typename T> static void copyChars(T* destination, const T* source, unsigned numCharacters) 298 template <typename T> static void copyChars(T* destination, const T* source, unsigned numCharacters)
297 { 299 {
298 memcpy(destination, source, numCharacters * sizeof(T)); 300 memcpy(destination, source, numCharacters * sizeof(T));
299 } 301 }
300 302
301 ALWAYS_INLINE static void copyChars(UChar* destination, const LChar* source, unsigned numCharacters) 303 ALWAYS_INLINE static void copyChars(UChar* destination, const LChar* source, unsigned numCharacters)
302 { 304 {
303 for (unsigned i = 0; i < numCharacters; ++i) 305 for (unsigned i = 0; i < numCharacters; ++i)
(...skipping 427 matching lines...) Expand 10 before | Expand all | Expand 10 after
731 } 733 }
732 734
733 using WTF::StringImpl; 735 using WTF::StringImpl;
734 using WTF::equal; 736 using WTF::equal;
735 using WTF::equalNonNull; 737 using WTF::equalNonNull;
736 using WTF::TextCaseSensitivity; 738 using WTF::TextCaseSensitivity;
737 using WTF::TextCaseSensitive; 739 using WTF::TextCaseSensitive;
738 using WTF::TextCaseInsensitive; 740 using WTF::TextCaseInsensitive;
739 741
740 #endif 742 #endif
OLDNEW
« no previous file with comments | « no previous file | Source/wtf/text/StringStatics.cpp » ('j') | Source/wtf/text/WTFString.h » ('J')

Powered by Google App Engine
This is Rietveld 408576698