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

Side by Side Diff: Source/core/html/parser/HTMLParserIdioms.cpp

Issue 110843004: Replaced HTMLIdentifier with an atomized string factory function (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: Review fixes Created 7 years 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) 2010 Apple Inc. All rights reserved. 2 * Copyright (C) 2010 Apple Inc. All rights reserved.
3 * 3 *
4 * Redistribution and use in source and binary forms, with or without 4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions 5 * modification, are permitted provided that the following conditions
6 * are met: 6 * are met:
7 * 1. Redistributions of source code must retain the above copyright 7 * 1. Redistributions of source code must retain the above copyright
8 * notice, this list of conditions and the following disclaimer. 8 * notice, this list of conditions and the following disclaimer.
9 * 2. Redistributions in binary form must reproduce the above copyright 9 * 2. Redistributions in binary form must reproduce the above copyright
10 * notice, this list of conditions and the following disclaimer in the 10 * notice, this list of conditions and the following disclaimer in the
(...skipping 11 matching lines...) Expand all
22 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 22 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
23 */ 23 */
24 24
25 #include "config.h" 25 #include "config.h"
26 #include "core/html/parser/HTMLParserIdioms.h" 26 #include "core/html/parser/HTMLParserIdioms.h"
27 27
28 #include <limits> 28 #include <limits>
29 #include "wtf/MathExtras.h" 29 #include "wtf/MathExtras.h"
30 #include "wtf/text/AtomicString.h" 30 #include "wtf/text/AtomicString.h"
31 #include "wtf/text/StringBuilder.h" 31 #include "wtf/text/StringBuilder.h"
32 #include "wtf/text/StringHash.h"
32 33
33 namespace WebCore { 34 namespace WebCore {
34 35
35 template <typename CharType> 36 template <typename CharType>
36 static String stripLeadingAndTrailingHTMLSpaces(String string, const CharType* c haracters, unsigned length) 37 static String stripLeadingAndTrailingHTMLSpaces(String string, const CharType* c haracters, unsigned length)
37 { 38 {
38 unsigned numLeadingSpaces = 0; 39 unsigned numLeadingSpaces = 0;
39 unsigned numTrailingSpaces = 0; 40 unsigned numTrailingSpaces = 0;
40 41
41 for (; numLeadingSpaces < length; ++numLeadingSpaces) { 42 for (; numLeadingSpaces < length; ++numLeadingSpaces) {
(...skipping 229 matching lines...) Expand 10 before | Expand all | Expand 10 after
271 if (a->hash() != b->hash()) 272 if (a->hash() != b->hash())
272 return false; 273 return false;
273 return equalNonNull(a, b); 274 return equalNonNull(a, b);
274 } 275 }
275 276
276 bool threadSafeMatch(const QualifiedName& a, const QualifiedName& b) 277 bool threadSafeMatch(const QualifiedName& a, const QualifiedName& b)
277 { 278 {
278 return threadSafeEqual(a.localName().impl(), b.localName().impl()); 279 return threadSafeEqual(a.localName().impl(), b.localName().impl());
279 } 280 }
280 281
281 bool threadSafeMatch(const HTMLIdentifier& localName, const QualifiedName& qName ) 282 bool threadSafeMatch(const String& localName, const QualifiedName& qName)
282 { 283 {
283 return threadSafeEqual(localName.asStringImpl(), qName.localName().impl()); 284 return threadSafeEqual(localName.impl(), qName.localName().impl());
285 }
286
287 StringImpl* findStringIfStatic(const UChar* characters, unsigned length)
288 {
289 // We don't need to try hashing if we know the string is too long.
290 if (length > StringImpl::highestStaticStringLength())
291 return 0;
292 // computeHashAndMaskTop8Bits is the function StringImpl::hash() uses.
293 unsigned hash = StringHasher::computeHashAndMaskTop8Bits(characters, length) ;
294 const WTF::StaticStringsTable& table = StringImpl::allStaticStrings();
295 ASSERT(!table.isEmpty());
296
297 WTF::StaticStringsTable::const_iterator it = table.find(hash);
298 if (it == table.end())
299 return 0;
300 // It's possible to have hash collisions between arbitrary strings and
301 // known identifiers (e.g. "bvvfg" collides with "script").
302 // However ASSERTs in StringImpl::createStatic guard against there ever bein g collisions
303 // between static strings.
304 if (!equal(it->value, characters, length))
305 return 0;
306 return it->value;
284 } 307 }
285 308
286 } 309 }
OLDNEW
« no previous file with comments | « Source/core/html/parser/HTMLParserIdioms.h ('k') | Source/core/html/parser/HTMLPreloadScanner.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698