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

Unified 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « Source/core/html/parser/HTMLParserIdioms.h ('k') | Source/core/html/parser/HTMLPreloadScanner.cpp » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: Source/core/html/parser/HTMLParserIdioms.cpp
diff --git a/Source/core/html/parser/HTMLParserIdioms.cpp b/Source/core/html/parser/HTMLParserIdioms.cpp
index 2173ef531261f3be7ebcc273d7cee35f4005d787..f538c54cc5bfc600db038025427f6b21559c110a 100644
--- a/Source/core/html/parser/HTMLParserIdioms.cpp
+++ b/Source/core/html/parser/HTMLParserIdioms.cpp
@@ -29,6 +29,7 @@
#include "wtf/MathExtras.h"
#include "wtf/text/AtomicString.h"
#include "wtf/text/StringBuilder.h"
+#include "wtf/text/StringHash.h"
namespace WebCore {
@@ -278,9 +279,31 @@ bool threadSafeMatch(const QualifiedName& a, const QualifiedName& b)
return threadSafeEqual(a.localName().impl(), b.localName().impl());
}
-bool threadSafeMatch(const HTMLIdentifier& localName, const QualifiedName& qName)
+bool threadSafeMatch(const String& localName, const QualifiedName& qName)
{
- return threadSafeEqual(localName.asStringImpl(), qName.localName().impl());
+ return threadSafeEqual(localName.impl(), qName.localName().impl());
+}
+
+StringImpl* findStringIfStatic(const UChar* characters, unsigned length)
+{
+ // We don't need to try hashing if we know the string is too long.
+ if (length > StringImpl::highestStaticStringLength())
+ return 0;
+ // computeHashAndMaskTop8Bits is the function StringImpl::hash() uses.
+ unsigned hash = StringHasher::computeHashAndMaskTop8Bits(characters, length);
+ const WTF::StaticStringsTable& table = StringImpl::allStaticStrings();
+ ASSERT(!table.isEmpty());
+
+ WTF::StaticStringsTable::const_iterator it = table.find(hash);
+ if (it == table.end())
+ return 0;
+ // It's possible to have hash collisions between arbitrary strings and
+ // known identifiers (e.g. "bvvfg" collides with "script").
+ // However ASSERTs in StringImpl::createStatic guard against there ever being collisions
+ // between static strings.
+ if (!equal(it->value, characters, length))
+ return 0;
+ return it->value;
}
}
« 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