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

Unified Diff: third_party/WebKit/Source/wtf/text/StringHash.h

Issue 1611343002: wtf reformat test Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: pydent Created 4 years, 11 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 side-by-side diff with in-line comments
Download patch
Index: third_party/WebKit/Source/wtf/text/StringHash.h
diff --git a/third_party/WebKit/Source/wtf/text/StringHash.h b/third_party/WebKit/Source/wtf/text/StringHash.h
index 7f0fcb2aeddbf5869158f856fc92f0aa1f5f6417..ea83bf799fd43729f573a08fb4995c2d205ec8d5 100644
--- a/third_party/WebKit/Source/wtf/text/StringHash.h
+++ b/third_party/WebKit/Source/wtf/text/StringHash.h
@@ -29,9 +29,8 @@
namespace WTF {
-inline bool HashTraits<String>::isEmptyValue(const String& value)
-{
- return value.isNull();
+inline bool HashTraits<String>::isEmptyValue(const String& value) {
+ return value.isNull();
}
// The hash() functions on StringHash and CaseFoldingHash do not support null
@@ -44,123 +43,106 @@ inline bool HashTraits<String>::isEmptyValue(const String& value)
// place.
struct StringHash {
- STATIC_ONLY(StringHash);
- static unsigned hash(StringImpl* key) { return key->hash(); }
- static inline bool equal(const StringImpl* a, const StringImpl* b)
- {
- return equalNonNull(a, b);
- }
-
- static unsigned hash(const RefPtr<StringImpl>& key) { return key->hash(); }
- static bool equal(const RefPtr<StringImpl>& a, const RefPtr<StringImpl>& b)
- {
- return equal(a.get(), b.get());
- }
-
- static unsigned hash(const String& key) { return key.impl()->hash(); }
- static bool equal(const String& a, const String& b)
- {
- return equal(a.impl(), b.impl());
- }
-
- static const bool safeToCompareToEmptyOrDeleted = false;
+ STATIC_ONLY(StringHash);
+ static unsigned hash(StringImpl* key) { return key->hash(); }
+ static inline bool equal(const StringImpl* a, const StringImpl* b) {
+ return equalNonNull(a, b);
+ }
+
+ static unsigned hash(const RefPtr<StringImpl>& key) { return key->hash(); }
+ static bool equal(const RefPtr<StringImpl>& a, const RefPtr<StringImpl>& b) {
+ return equal(a.get(), b.get());
+ }
+
+ static unsigned hash(const String& key) { return key.impl()->hash(); }
+ static bool equal(const String& a, const String& b) {
+ return equal(a.impl(), b.impl());
+ }
+
+ static const bool safeToCompareToEmptyOrDeleted = false;
};
class CaseFoldingHash {
- STATIC_ONLY(CaseFoldingHash);
-public:
- static unsigned hash(const UChar* data, unsigned length)
- {
- return StringHasher::computeHashAndMaskTop8Bits<UChar, foldCase<UChar>>(data, length);
- }
-
- static unsigned hash(StringImpl* str)
- {
- if (str->is8Bit())
- return hash(str->characters8(), str->length());
- return hash(str->characters16(), str->length());
- }
-
- static unsigned hash(const LChar* data, unsigned length)
- {
- return StringHasher::computeHashAndMaskTop8Bits<LChar, foldCase<LChar>>(data, length);
- }
-
- static inline unsigned hash(const char* data, unsigned length)
- {
- return CaseFoldingHash::hash(reinterpret_cast<const LChar*>(data), length);
- }
-
- static inline bool equal(const StringImpl* a, const StringImpl* b)
- {
- return equalIgnoringCaseNonNull(a, b);
- }
-
- static unsigned hash(const RefPtr<StringImpl>& key)
- {
- return hash(key.get());
- }
-
- static bool equal(const RefPtr<StringImpl>& a, const RefPtr<StringImpl>& b)
- {
- return equal(a.get(), b.get());
- }
-
- static unsigned hash(const String& key)
- {
- return hash(key.impl());
- }
- static unsigned hash(const AtomicString& key)
- {
- return hash(key.impl());
- }
- static bool equal(const String& a, const String& b)
- {
- return equal(a.impl(), b.impl());
- }
- static bool equal(const AtomicString& a, const AtomicString& b)
- {
- return (a == b) || equal(a.impl(), b.impl());
- }
-
- static const bool safeToCompareToEmptyOrDeleted = false;
-
-private:
- // Private so no one uses this in the belief that it will return the
- // correctly-folded code point in all cases (see comment below).
- template<typename T> static inline UChar foldCase(T ch)
- {
- if (std::is_same<T, LChar>::value)
- return StringImpl::latin1CaseFoldTable[ch];
- // It's possible for WTF::Unicode::foldCase() to return a 32-bit value
- // that's not representable as a UChar. However, since this is rare and
- // deterministic, and the result of this is merely used for hashing, go
- // ahead and clamp the value.
- return static_cast<UChar>(WTF::Unicode::foldCase(ch));
- }
+ STATIC_ONLY(CaseFoldingHash);
+
+ public:
+ static unsigned hash(const UChar* data, unsigned length) {
+ return StringHasher::computeHashAndMaskTop8Bits<UChar, foldCase<UChar>>(
+ data, length);
+ }
+
+ static unsigned hash(StringImpl* str) {
+ if (str->is8Bit())
+ return hash(str->characters8(), str->length());
+ return hash(str->characters16(), str->length());
+ }
+
+ static unsigned hash(const LChar* data, unsigned length) {
+ return StringHasher::computeHashAndMaskTop8Bits<LChar, foldCase<LChar>>(
+ data, length);
+ }
+
+ static inline unsigned hash(const char* data, unsigned length) {
+ return CaseFoldingHash::hash(reinterpret_cast<const LChar*>(data), length);
+ }
+
+ static inline bool equal(const StringImpl* a, const StringImpl* b) {
+ return equalIgnoringCaseNonNull(a, b);
+ }
+
+ static unsigned hash(const RefPtr<StringImpl>& key) {
+ return hash(key.get());
+ }
+
+ static bool equal(const RefPtr<StringImpl>& a, const RefPtr<StringImpl>& b) {
+ return equal(a.get(), b.get());
+ }
+
+ static unsigned hash(const String& key) { return hash(key.impl()); }
+ static unsigned hash(const AtomicString& key) { return hash(key.impl()); }
+ static bool equal(const String& a, const String& b) {
+ return equal(a.impl(), b.impl());
+ }
+ static bool equal(const AtomicString& a, const AtomicString& b) {
+ return (a == b) || equal(a.impl(), b.impl());
+ }
+
+ static const bool safeToCompareToEmptyOrDeleted = false;
+
+ private:
+ // Private so no one uses this in the belief that it will return the
+ // correctly-folded code point in all cases (see comment below).
+ template <typename T>
+ static inline UChar foldCase(T ch) {
+ if (std::is_same<T, LChar>::value)
+ return StringImpl::latin1CaseFoldTable[ch];
+ // It's possible for WTF::Unicode::foldCase() to return a 32-bit value
+ // that's not representable as a UChar. However, since this is rare and
+ // deterministic, and the result of this is merely used for hashing, go
+ // ahead and clamp the value.
+ return static_cast<UChar>(WTF::Unicode::foldCase(ch));
+ }
};
// This hash can be used in cases where the key is a hash of a string, but we
// don't want to store the string. It's not really specific to string hashing,
// but all our current uses of it are for strings.
struct AlreadyHashed : IntHash<unsigned> {
- STATIC_ONLY(AlreadyHashed);
- static unsigned hash(unsigned key) { return key; }
-
- // To use a hash value as a key for a hash table, we need to eliminate the
- // "deleted" value, which is negative one. That could be done by changing
- // the string hash function to never generate negative one, but this works
- // and is still relatively efficient.
- static unsigned avoidDeletedValue(unsigned hash)
- {
- ASSERT(hash);
- unsigned newHash = hash | (!(hash + 1) << 31);
- ASSERT(newHash);
- ASSERT(newHash != 0xFFFFFFFF);
- return newHash;
- }
+ STATIC_ONLY(AlreadyHashed);
+ static unsigned hash(unsigned key) { return key; }
+
+ // To use a hash value as a key for a hash table, we need to eliminate the
+ // "deleted" value, which is negative one. That could be done by changing
+ // the string hash function to never generate negative one, but this works
+ // and is still relatively efficient.
+ static unsigned avoidDeletedValue(unsigned hash) {
+ ASSERT(hash);
+ unsigned newHash = hash | (!(hash + 1) << 31);
+ ASSERT(newHash);
+ ASSERT(newHash != 0xFFFFFFFF);
+ return newHash;
+ }
};
-
}
using WTF::AlreadyHashed;
« no previous file with comments | « third_party/WebKit/Source/wtf/text/StringConcatenate.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