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

Side by Side Diff: third_party/WebKit/Source/wtf/text/AtomicString.h

Issue 2110813003: Move all the AtomicString table into AtomicStringTable. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: fix comments. Created 4 years, 5 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 /* 1 /*
2 * Copyright (C) 2004, 2005, 2006, 2008 Apple Inc. All rights reserved. 2 * Copyright (C) 2004, 2005, 2006, 2008 Apple Inc. All rights reserved.
3 * 3 *
4 * This library is free software; you can redistribute it and/or 4 * This library is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU Library General Public 5 * modify it under the terms of the GNU Library General Public
6 * License as published by the Free Software Foundation; either 6 * License as published by the Free Software Foundation; either
7 * version 2 of the License, or (at your option) any later version. 7 * version 2 of the License, or (at your option) any later version.
8 * 8 *
9 * This library is distributed in the hope that it will be useful, 9 * This library is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of 10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
(...skipping 19 matching lines...) Expand all
30 #include <iosfwd> 30 #include <iosfwd>
31 31
32 namespace WTF { 32 namespace WTF {
33 33
34 struct AtomicStringHash; 34 struct AtomicStringHash;
35 35
36 class WTF_EXPORT AtomicString { 36 class WTF_EXPORT AtomicString {
37 USING_FAST_MALLOC(AtomicString); 37 USING_FAST_MALLOC(AtomicString);
38 public: 38 public:
39 static void init(); 39 static void init();
40 static void reserveTableCapacity(size_t);
41 40
42 AtomicString() { } 41 AtomicString() {}
43 AtomicString(const LChar* s) : m_string(add(s)) { } 42 AtomicString(const LChar* chars)
44 AtomicString(const char* s) : m_string(add(s)) { } 43 : AtomicString(chars, chars ? strlen(reinterpret_cast<const char*>(chars )) : 0) {}
45 AtomicString(const LChar* s, unsigned length) : m_string(add(s, length)) { } 44 AtomicString(const char* chars)
46 AtomicString(const UChar* s, unsigned length) : m_string(add(s, length)) { } 45 : AtomicString(reinterpret_cast<const LChar*>(chars)) {}
47 AtomicString(const UChar* s, unsigned length, unsigned existingHash) : m_str ing(add(s, length, existingHash)) { } 46 AtomicString(const LChar* chars, unsigned length);
48 AtomicString(const UChar* s) : m_string(add(s)) { } 47 AtomicString(const UChar* chars, unsigned length);
48 AtomicString(const UChar* chars, unsigned length, unsigned existingHash);
49 AtomicString(const UChar* chars);
49 50
50 template<size_t inlineCapacity> 51 template<size_t inlineCapacity>
51 explicit AtomicString(const Vector<UChar, inlineCapacity>& characters) 52 explicit AtomicString(const Vector<UChar, inlineCapacity>& vector)
52 : m_string(add(characters.data(), characters.size())) 53 : AtomicString(vector.data(), vector.size()) {}
53 {
54 }
55 54
56 // Constructing an AtomicString from a String / StringImpl can be expensive if 55 // Constructing an AtomicString from a String / StringImpl can be expensive if
57 // the StringImpl is not already atomic. 56 // the StringImpl is not already atomic.
58 explicit AtomicString(StringImpl* impl) : m_string(add(impl)) { } 57 explicit AtomicString(StringImpl* impl) : m_string(add(impl)) { }
59 explicit AtomicString(const String& s) : m_string(add(s.impl())) { } 58 explicit AtomicString(const String& s) : m_string(add(s.impl())) { }
60 59
61 AtomicString(StringImpl* baseString, unsigned start, unsigned length) : m_st ring(add(baseString, start, length)) { } 60 AtomicString(StringImpl* baseString, unsigned start, unsigned length);
62 61
63 // Hash table deleted values, which are only constructed and never copied or destroyed. 62 // Hash table deleted values, which are only constructed and never copied or destroyed.
64 AtomicString(WTF::HashTableDeletedValueType) : m_string(WTF::HashTableDelete dValue) { } 63 AtomicString(WTF::HashTableDeletedValueType) : m_string(WTF::HashTableDelete dValue) { }
65 bool isHashTableDeletedValue() const { return m_string.isHashTableDeletedVal ue(); } 64 bool isHashTableDeletedValue() const { return m_string.isHashTableDeletedVal ue(); }
66 65
67 static StringImpl* find(const StringImpl*);
68
69 operator const String&() const { return m_string; } 66 operator const String&() const { return m_string; }
70 const String& getString() const { return m_string; } 67 const String& getString() const { return m_string; }
71 68
72 StringImpl* impl() const { return m_string.impl(); } 69 StringImpl* impl() const { return m_string.impl(); }
73 70
74 bool is8Bit() const { return m_string.is8Bit(); } 71 bool is8Bit() const { return m_string.is8Bit(); }
75 const LChar* characters8() const { return m_string.characters8(); } 72 const LChar* characters8() const { return m_string.characters8(); }
76 const UChar* characters16() const { return m_string.characters16(); } 73 const UChar* characters16() const { return m_string.characters16(); }
77 unsigned length() const { return m_string.length(); } 74 unsigned length() const { return m_string.length(); }
78 75
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after
121 static AtomicString number(long); 118 static AtomicString number(long);
122 static AtomicString number(unsigned long); 119 static AtomicString number(unsigned long);
123 static AtomicString number(long long); 120 static AtomicString number(long long);
124 static AtomicString number(unsigned long long); 121 static AtomicString number(unsigned long long);
125 122
126 static AtomicString number(double, unsigned precision = 6, TrailingZerosTrun catingPolicy = TruncateTrailingZeros); 123 static AtomicString number(double, unsigned precision = 6, TrailingZerosTrun catingPolicy = TruncateTrailingZeros);
127 124
128 bool isNull() const { return m_string.isNull(); } 125 bool isNull() const { return m_string.isNull(); }
129 bool isEmpty() const { return m_string.isEmpty(); } 126 bool isEmpty() const { return m_string.isEmpty(); }
130 127
131 static void remove(StringImpl*);
132
133 #ifdef __OBJC__ 128 #ifdef __OBJC__
134 AtomicString(NSString* s) : m_string(add((CFStringRef)s)) { } 129 AtomicString(NSString* s) : m_string(add((CFStringRef)s)) { }
135 operator NSString*() const { return m_string; } 130 operator NSString*() const { return m_string; }
136 #endif 131 #endif
137 // AtomicString::fromUTF8 will return a null string if 132 // AtomicString::fromUTF8 will return a null string if
138 // the input data contains invalid UTF-8 sequences. 133 // the input data contains invalid UTF-8 sequences.
139 static AtomicString fromUTF8(const char*, size_t); 134 // NOTE: Passing a zero size means use the whole string.
135 static AtomicString fromUTF8(const char*, size_t length);
140 static AtomicString fromUTF8(const char*); 136 static AtomicString fromUTF8(const char*);
141 137
142 CString ascii() const { return m_string.ascii(); } 138 CString ascii() const { return m_string.ascii(); }
143 CString latin1() const { return m_string.latin1(); } 139 CString latin1() const { return m_string.latin1(); }
144 CString utf8(UTF8ConversionMode mode = LenientUTF8Conversion) const { return m_string.utf8(mode); } 140 CString utf8(UTF8ConversionMode mode = LenientUTF8Conversion) const { return m_string.utf8(mode); }
145 141
146 #ifndef NDEBUG 142 #ifndef NDEBUG
147 void show() const; 143 void show() const;
148 #endif 144 #endif
149 145
150 private: 146 private:
151 String m_string; 147 String m_string;
152 148
153 ALWAYS_INLINE static PassRefPtr<StringImpl> add(const LChar* characters)
154 {
155 if (!characters)
156 return nullptr;
157 return add(characters, strlen(reinterpret_cast<const char*>(characters)) );
158 }
159 ALWAYS_INLINE static PassRefPtr<StringImpl> add(const char* s) { return add( reinterpret_cast<const LChar*>(s)); }
160 static PassRefPtr<StringImpl> add(const LChar*, unsigned length);
161 static PassRefPtr<StringImpl> add(const UChar*, unsigned length);
162 ALWAYS_INLINE static PassRefPtr<StringImpl> add(const char* s, unsigned leng th) { return add(reinterpret_cast<const LChar*>(s), length); }
163 static PassRefPtr<StringImpl> add(const UChar*, unsigned length, unsigned ex istingHash);
164 static PassRefPtr<StringImpl> add(const UChar*);
165 static PassRefPtr<StringImpl> add(StringImpl*, unsigned offset, unsigned len gth);
166 ALWAYS_INLINE static PassRefPtr<StringImpl> add(StringImpl* r) 149 ALWAYS_INLINE static PassRefPtr<StringImpl> add(StringImpl* r)
167 { 150 {
168 if (!r || r->isAtomic()) 151 if (!r || r->isAtomic())
169 return r; 152 return r;
170 return addSlowCase(r); 153 return addSlowCase(r);
171 } 154 }
172 static PassRefPtr<StringImpl> addSlowCase(StringImpl*); 155 static PassRefPtr<StringImpl> addSlowCase(StringImpl*);
173 #if OS(MACOSX) 156 #if OS(MACOSX)
174 static PassRefPtr<StringImpl> add(CFStringRef); 157 static PassRefPtr<StringImpl> add(CFStringRef);
175 #endif 158 #endif
176
177 static AtomicString fromUTF8Internal(const char*, const char*);
178 }; 159 };
179 160
180 inline bool operator==(const AtomicString& a, const AtomicString& b) { return a. impl() == b.impl(); } 161 inline bool operator==(const AtomicString& a, const AtomicString& b) { return a. impl() == b.impl(); }
181 WTF_EXPORT bool operator==(const AtomicString&, const LChar*); 162 WTF_EXPORT bool operator==(const AtomicString&, const LChar*);
182 inline bool operator==(const AtomicString& a, const char* b) { return WTF::equal (a.impl(), reinterpret_cast<const LChar*>(b)); } 163 inline bool operator==(const AtomicString& a, const char* b) { return WTF::equal (a.impl(), reinterpret_cast<const LChar*>(b)); }
183 inline bool operator==(const AtomicString& a, const Vector<UChar>& b) { return a .impl() && equal(a.impl(), b.data(), b.size()); } 164 inline bool operator==(const AtomicString& a, const Vector<UChar>& b) { return a .impl() && equal(a.impl(), b.data(), b.size()); }
184 inline bool operator==(const AtomicString& a, const String& b) { return equal(a. impl(), b.impl()); } 165 inline bool operator==(const AtomicString& a, const String& b) { return equal(a. impl(), b.impl()); }
185 inline bool operator==(const LChar* a, const AtomicString& b) { return b == a; } 166 inline bool operator==(const LChar* a, const AtomicString& b) { return b == a; }
186 inline bool operator==(const char* a, const AtomicString& b) { return b == a; } 167 inline bool operator==(const char* a, const AtomicString& b) { return b == a; }
187 inline bool operator==(const String& a, const AtomicString& b) { return equal(a. impl(), b.impl()); } 168 inline bool operator==(const String& a, const AtomicString& b) { return equal(a. impl(), b.impl()); }
(...skipping 22 matching lines...) Expand all
210 191
211 // Define external global variables for the commonly used atomic strings. 192 // Define external global variables for the commonly used atomic strings.
212 // These are only usable from the main thread. 193 // These are only usable from the main thread.
213 WTF_EXPORT extern const AtomicString& nullAtom; 194 WTF_EXPORT extern const AtomicString& nullAtom;
214 WTF_EXPORT extern const AtomicString& emptyAtom; 195 WTF_EXPORT extern const AtomicString& emptyAtom;
215 WTF_EXPORT extern const AtomicString& starAtom; 196 WTF_EXPORT extern const AtomicString& starAtom;
216 WTF_EXPORT extern const AtomicString& xmlAtom; 197 WTF_EXPORT extern const AtomicString& xmlAtom;
217 WTF_EXPORT extern const AtomicString& xmlnsAtom; 198 WTF_EXPORT extern const AtomicString& xmlnsAtom;
218 WTF_EXPORT extern const AtomicString& xlinkAtom; 199 WTF_EXPORT extern const AtomicString& xlinkAtom;
219 200
220 inline AtomicString AtomicString::fromUTF8(const char* characters, size_t length )
221 {
222 if (!characters)
223 return nullAtom;
224 if (!length)
225 return emptyAtom;
226 return fromUTF8Internal(characters, characters + length);
227 }
228
229 inline AtomicString AtomicString::fromUTF8(const char* characters)
230 {
231 if (!characters)
232 return nullAtom;
233 if (!*characters)
234 return emptyAtom;
235 return fromUTF8Internal(characters, 0);
236 }
237 201
238 // AtomicStringHash is the default hash for AtomicString 202 // AtomicStringHash is the default hash for AtomicString
239 template<typename T> struct DefaultHash; 203 template<typename T> struct DefaultHash;
240 template<> struct DefaultHash<AtomicString> { 204 template<> struct DefaultHash<AtomicString> {
241 typedef AtomicStringHash Hash; 205 typedef AtomicStringHash Hash;
242 }; 206 };
243 207
244 // Pretty printer for gtest and base/logging.*. It prepends and appends 208 // Pretty printer for gtest and base/logging.*. It prepends and appends
245 // double-quotes, and escapes chracters other than ASCII printables. 209 // double-quotes, and escapes chracters other than ASCII printables.
246 WTF_EXPORT std::ostream& operator<<(std::ostream&, const AtomicString&); 210 WTF_EXPORT std::ostream& operator<<(std::ostream&, const AtomicString&);
247 211
248 } // namespace WTF 212 } // namespace WTF
249 213
250 WTF_ALLOW_MOVE_INIT_AND_COMPARE_WITH_MEM_FUNCTIONS(AtomicString); 214 WTF_ALLOW_MOVE_INIT_AND_COMPARE_WITH_MEM_FUNCTIONS(AtomicString);
251 215
252 using WTF::AtomicString; 216 using WTF::AtomicString;
253 using WTF::nullAtom; 217 using WTF::nullAtom;
254 using WTF::emptyAtom; 218 using WTF::emptyAtom;
255 using WTF::starAtom; 219 using WTF::starAtom;
256 using WTF::xmlAtom; 220 using WTF::xmlAtom;
257 using WTF::xmlnsAtom; 221 using WTF::xmlnsAtom;
258 using WTF::xlinkAtom; 222 using WTF::xlinkAtom;
259 223
260 #include "wtf/text/StringConcatenate.h" 224 #include "wtf/text/StringConcatenate.h"
261 #endif // AtomicString_h 225 #endif // AtomicString_h
OLDNEW
« no previous file with comments | « third_party/WebKit/Source/wtf/WTFThreadData.cpp ('k') | third_party/WebKit/Source/wtf/text/AtomicString.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698