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

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

Issue 2655853003: Replace StringImpl::empty{16Bit}() with a static member (Closed)
Patch Set: annotate race 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/AtomicStringTable.h" 5 #include "wtf/text/AtomicStringTable.h"
6 6
7 #include "wtf/text/StringHash.h" 7 #include "wtf/text/StringHash.h"
8 #include "wtf/text/UTF8.h" 8 #include "wtf/text/UTF8.h"
9 9
10 namespace WTF { 10 namespace WTF {
(...skipping 130 matching lines...) Expand 10 before | Expand all | Expand 10 after
141 location->setHash(hash); 141 location->setHash(hash);
142 location->setIsAtomic(true); 142 location->setIsAtomic(true);
143 } 143 }
144 }; 144 };
145 145
146 PassRefPtr<StringImpl> AtomicStringTable::add(const UChar* s, unsigned length) { 146 PassRefPtr<StringImpl> AtomicStringTable::add(const UChar* s, unsigned length) {
147 if (!s) 147 if (!s)
148 return nullptr; 148 return nullptr;
149 149
150 if (!length) 150 if (!length)
151 return StringImpl::empty(); 151 return StringImpl::empty;
152 152
153 UCharBuffer buffer = {s, length}; 153 UCharBuffer buffer = {s, length};
154 return addToStringTable<UCharBuffer, UCharBufferTranslator>(buffer); 154 return addToStringTable<UCharBuffer, UCharBufferTranslator>(buffer);
155 } 155 }
156 156
157 typedef HashTranslatorCharBuffer<LChar> LCharBuffer; 157 typedef HashTranslatorCharBuffer<LChar> LCharBuffer;
158 struct LCharBufferTranslator { 158 struct LCharBufferTranslator {
159 static unsigned hash(const LCharBuffer& buf) { 159 static unsigned hash(const LCharBuffer& buf) {
160 return StringHasher::computeHashAndMaskTop8Bits(buf.s, buf.length); 160 return StringHasher::computeHashAndMaskTop8Bits(buf.s, buf.length);
161 } 161 }
162 162
163 static bool equal(StringImpl* const& str, const LCharBuffer& buf) { 163 static bool equal(StringImpl* const& str, const LCharBuffer& buf) {
164 return WTF::equal(str, buf.s, buf.length); 164 return WTF::equal(str, buf.s, buf.length);
165 } 165 }
166 166
167 static void translate(StringImpl*& location, 167 static void translate(StringImpl*& location,
168 const LCharBuffer& buf, 168 const LCharBuffer& buf,
169 unsigned hash) { 169 unsigned hash) {
170 location = StringImpl::create(buf.s, buf.length).leakRef(); 170 location = StringImpl::create(buf.s, buf.length).leakRef();
171 location->setHash(hash); 171 location->setHash(hash);
172 location->setIsAtomic(true); 172 location->setIsAtomic(true);
173 } 173 }
174 }; 174 };
175 175
176 PassRefPtr<StringImpl> AtomicStringTable::add(const LChar* s, unsigned length) { 176 PassRefPtr<StringImpl> AtomicStringTable::add(const LChar* s, unsigned length) {
177 if (!s) 177 if (!s)
178 return nullptr; 178 return nullptr;
179 179
180 if (!length) 180 if (!length)
181 return StringImpl::empty(); 181 return StringImpl::empty;
182 182
183 LCharBuffer buffer = {s, length}; 183 LCharBuffer buffer = {s, length};
184 return addToStringTable<LCharBuffer, LCharBufferTranslator>(buffer); 184 return addToStringTable<LCharBuffer, LCharBufferTranslator>(buffer);
185 } 185 }
186 186
187 StringImpl* AtomicStringTable::add(StringImpl* string) { 187 StringImpl* AtomicStringTable::add(StringImpl* string) {
188 if (!string->length()) 188 if (!string->length())
189 return StringImpl::empty(); 189 return StringImpl::empty;
190 190
191 StringImpl* result = *m_table.insert(string).storedValue; 191 StringImpl* result = *m_table.insert(string).storedValue;
192 192
193 if (!result->isAtomic()) 193 if (!result->isAtomic())
194 result->setIsAtomic(true); 194 result->setIsAtomic(true);
195 195
196 DCHECK(!string->isStatic() || result->isStatic()); 196 DCHECK(!string->isStatic() || result->isStatic());
197 return result; 197 return result;
198 } 198 }
199 199
(...skipping 12 matching lines...) Expand all
212 } 212 }
213 213
214 void AtomicStringTable::remove(StringImpl* string) { 214 void AtomicStringTable::remove(StringImpl* string) {
215 DCHECK(string->isAtomic()); 215 DCHECK(string->isAtomic());
216 auto iterator = m_table.find(string); 216 auto iterator = m_table.find(string);
217 RELEASE_ASSERT(iterator != m_table.end()); 217 RELEASE_ASSERT(iterator != m_table.end());
218 m_table.remove(iterator); 218 m_table.remove(iterator);
219 } 219 }
220 220
221 } // namespace WTF 221 } // namespace WTF
OLDNEW
« no previous file with comments | « third_party/WebKit/Source/wtf/ThreadingWin.cpp ('k') | third_party/WebKit/Source/wtf/text/StringImpl.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698