Title: [290349] trunk
Revision
290349
Author
[email protected]
Date
2022-02-22 22:12:31 -0800 (Tue, 22 Feb 2022)

Log Message

Drop StringHasher::hashMemory() and use the modern Hasher instead
https://bugs.webkit.org/show_bug.cgi?id=237049

Source/WebCore:

Reviewed by Sam Weinig and Darin Adler.

* Modules/indexeddb/shared/IDBResourceIdentifier.h:
(WebCore::add):
(WebCore::IDBResourceIdentifierHash::hash):
(WebCore::IDBResourceIdentifier::hash const): Deleted.
* dom/Attribute.h:
(WebCore::add):
* dom/DocumentSharedObjectPool.cpp:
(WebCore::DocumentSharedObjectPool::cachedShareableElementDataWithAttributes):
(WebCore::attributeHash): Deleted.
* dom/QualifiedName.cpp:
(WebCore::QualifiedName::QualifiedNameImpl::computeHash const):
* dom/QualifiedName.h:
(WebCore::add):
(WebCore::hashComponents): Deleted.
* dom/QualifiedNameCache.cpp:
(WebCore::QNameComponentsTranslator::hash):
* page/GlobalWindowIdentifier.h:
(WebCore::add):
(WTF::GlobalWindowIdentifierHash::hash):
(WebCore::GlobalWindowIdentifier::hash const): Deleted.
* page/SecurityOriginHash.h:
(WebCore::SecurityOriginHash::hash):
* platform/ScriptExecutionContextIdentifier.h:
(WebCore::add):
(WebCore::ProcessQualified<UUID>::hash const): Deleted.
(WTF::computeHash): Deleted.
* platform/graphics/cocoa/FontPlatformDataCocoa.mm:
(WebCore::FontPlatformData::hash const):
* platform/graphics/win/FontPlatformDataCGWin.cpp:
(WebCore::FontPlatformData::hash const):
* svg/SVGElementInlines.h:
(WebCore::SVGAttributeHashTranslator::hash):
* workers/service/ServiceWorkerRegistrationKey.cpp:
(WebCore::ServiceWorkerRegistrationKey::hash const): Deleted.
* workers/service/ServiceWorkerRegistrationKey.h:
(WebCore::add):
(WTF::ServiceWorkerRegistrationKeyHash::hash):

Source/WebKitLegacy/mac:

Reviewed by Sam Weinig and Darin Adler.

* History/BinaryPropertyList.cpp:
(add):
(IntegerArrayHash::hash):

Source/WTF:

Reviewed by Sam Weinig and Darin Adler.

* wtf/SchedulePair.h:
(WTF::SchedulePairHash::hash):
* wtf/UUID.cpp:
(WTF::UUID::hash const): Deleted.
* wtf/UUID.h:
(WTF::UUID::isHashTableDeletedValue const):
(WTF::add):
(WTF::UUIDHash::hash):
* wtf/text/StringHasher.h:
(WTF::StringHasher::hashMemory): Deleted.

Tools:

Reviewed by Sam Weinig.

* TestWebKitAPI/Tests/WTF/StringHasher.cpp:

Modified Paths

Diff

Modified: trunk/Source/WTF/ChangeLog (290348 => 290349)


--- trunk/Source/WTF/ChangeLog	2022-02-23 06:01:13 UTC (rev 290348)
+++ trunk/Source/WTF/ChangeLog	2022-02-23 06:12:31 UTC (rev 290349)
@@ -1,3 +1,21 @@
+2022-02-22  Chris Dumez  <[email protected]>
+
+        Drop StringHasher::hashMemory() and use the modern Hasher instead
+        https://bugs.webkit.org/show_bug.cgi?id=237049
+
+        Reviewed by Sam Weinig and Darin Adler.
+
+        * wtf/SchedulePair.h:
+        (WTF::SchedulePairHash::hash):
+        * wtf/UUID.cpp:
+        (WTF::UUID::hash const): Deleted.
+        * wtf/UUID.h:
+        (WTF::UUID::isHashTableDeletedValue const):
+        (WTF::add):
+        (WTF::UUIDHash::hash):
+        * wtf/text/StringHasher.h:
+        (WTF::StringHasher::hashMemory): Deleted.
+
 2022-02-22  Elliott Williams  <[email protected]>
 
         Replace legacy-build-copy-nested-headers.py with an xcodebuild invocation

Modified: trunk/Source/WTF/wtf/Hasher.h (290348 => 290349)


--- trunk/Source/WTF/wtf/Hasher.h	2022-02-23 06:01:13 UTC (rev 290348)
+++ trunk/Source/WTF/wtf/Hasher.h	2022-02-23 06:12:31 UTC (rev 290349)
@@ -22,6 +22,7 @@
 
 #include <optional>
 #include <variant>
+#include <wtf/Int128.h>
 #include <wtf/StdLibExtras.h>
 #include <wtf/URL.h>
 #include <wtf/text/AtomString.h>
@@ -75,6 +76,14 @@
     add(hasher, static_cast<uint32_t>(integer >> 32));
 }
 
+inline void add(Hasher& hasher, UInt128 value)
+{
+    auto high = static_cast<uint64_t>(value >> 64);
+    auto low = static_cast<uint64_t>(value);
+    add(hasher, high);
+    add(hasher, low);
+}
+
 template<typename SignedArithmetic> std::enable_if_t<std::is_signed<SignedArithmetic>::value, void> add(Hasher& hasher, SignedArithmetic number)
 {
     // We overloaded for double and float below, just deal with integers here.

Modified: trunk/Source/WTF/wtf/SchedulePair.h (290348 => 290349)


--- trunk/Source/WTF/wtf/SchedulePair.h	2022-02-23 06:01:13 UTC (rev 290348)
+++ trunk/Source/WTF/wtf/SchedulePair.h	2022-02-23 06:12:31 UTC (rev 290349)
@@ -29,6 +29,7 @@
 #pragma once
 
 #include <wtf/HashSet.h>
+#include <wtf/Hasher.h>
 #include <wtf/RetainPtr.h>
 #include <wtf/ThreadSafeRefCounted.h>
 #include <wtf/text/WTFString.h>
@@ -70,11 +71,16 @@
     RetainPtr<CFStringRef> m_mode;
 };
 
+inline void add(Hasher& hasher, const SchedulePair& pair)
+{
+    // FIXME: Hashing a CFHash here is unfortunate.
+    add(hasher, pair.runLoop(), pair.mode() ? CFHash(pair.mode()) : 0);
+}
+
 struct SchedulePairHash {
     static unsigned hash(const RefPtr<SchedulePair>& pair)
     {
-        uintptr_t hashCodes[2] = { reinterpret_cast<uintptr_t>(pair->runLoop()), pair->mode() ? CFHash(pair->mode()) : 0 };
-        return StringHasher::hashMemory<sizeof(hashCodes)>(hashCodes);
+        return computeHash(*pair);
     }
 
     static bool equal(const RefPtr<SchedulePair>& a, const RefPtr<SchedulePair>& b) { return a == b; }

Modified: trunk/Source/WTF/wtf/UUID.cpp (290348 => 290349)


--- trunk/Source/WTF/wtf/UUID.cpp	2022-02-23 06:01:13 UTC (rev 290348)
+++ trunk/Source/WTF/wtf/UUID.cpp	2022-02-23 06:12:31 UTC (rev 290349)
@@ -57,11 +57,6 @@
     m_data = (static_cast<UInt128>(high) << 64) | low;
 }
 
-unsigned UUID::hash() const
-{
-    return StringHasher::hashMemory(reinterpret_cast<const unsigned char*>(&m_data), 16);
-}
-
 String UUID::toString() const
 {
     auto high = static_cast<uint64_t>(m_data >> 64);

Modified: trunk/Source/WTF/wtf/UUID.h (290348 => 290349)


--- trunk/Source/WTF/wtf/UUID.h	2022-02-23 06:01:13 UTC (rev 290348)
+++ trunk/Source/WTF/wtf/UUID.h	2022-02-23 06:12:31 UTC (rev 290349)
@@ -83,7 +83,6 @@
     }
 
     bool isHashTableDeletedValue() const { return m_data == deletedValue; }
-    WTF_EXPORT_PRIVATE unsigned hash() const;
     WTF_EXPORT_PRIVATE String toString() const;
 
     operator bool() const { return !!m_data; }
@@ -90,12 +89,18 @@
 
 private:
     WTF_EXPORT_PRIVATE UUID();
+    friend void add(Hasher&, UUID);
 
     UInt128 m_data;
 };
 
+inline void add(Hasher& hasher, UUID uuid)
+{
+    add(hasher, uuid.m_data);
+}
+
 struct UUIDHash {
-    static unsigned hash(const UUID& key) { return key.hash(); }
+    static unsigned hash(const UUID& key) { return computeHash(key); }
     static bool equal(const UUID& a, const UUID& b) { return a == b; }
     static const bool safeToCompareToEmptyOrDeleted = true;
 };

Modified: trunk/Source/WTF/wtf/text/StringHasher.h (290348 => 290349)


--- trunk/Source/WTF/wtf/text/StringHasher.h	2022-02-23 06:01:13 UTC (rev 290348)
+++ trunk/Source/WTF/wtf/text/StringHasher.h	2022-02-23 06:12:31 UTC (rev 290349)
@@ -225,23 +225,6 @@
         return computeHashAndMaskTop8Bits<T, DefaultConverter>(characters, charactersCount - 1);
     }
 
-    static unsigned hashMemory(const void* data, unsigned length)
-    {
-        size_t lengthInUChar = length / sizeof(UChar);
-        StringHasher hasher;
-        hasher.addCharactersAssumingAligned(static_cast<const UChar*>(data), lengthInUChar);
-
-        for (size_t i = 0; i < length % sizeof(UChar); ++i)
-            hasher.addCharacter(static_cast<const char*>(data)[lengthInUChar * sizeof(UChar) + i]);
-
-        return hasher.hash();
-    }
-
-    template<size_t length> static unsigned hashMemory(const void* data)
-    {
-        return hashMemory(data, length);
-    }
-
 private:
     ALWAYS_INLINE static constexpr unsigned avalancheBits(unsigned hash)
     {

Modified: trunk/Source/WebCore/ChangeLog (290348 => 290349)


--- trunk/Source/WebCore/ChangeLog	2022-02-23 06:01:13 UTC (rev 290348)
+++ trunk/Source/WebCore/ChangeLog	2022-02-23 06:12:31 UTC (rev 290349)
@@ -1,3 +1,48 @@
+2022-02-22  Chris Dumez  <[email protected]>
+
+        Drop StringHasher::hashMemory() and use the modern Hasher instead
+        https://bugs.webkit.org/show_bug.cgi?id=237049
+
+        Reviewed by Sam Weinig and Darin Adler.
+
+        * Modules/indexeddb/shared/IDBResourceIdentifier.h:
+        (WebCore::add):
+        (WebCore::IDBResourceIdentifierHash::hash):
+        (WebCore::IDBResourceIdentifier::hash const): Deleted.
+        * dom/Attribute.h:
+        (WebCore::add):
+        * dom/DocumentSharedObjectPool.cpp:
+        (WebCore::DocumentSharedObjectPool::cachedShareableElementDataWithAttributes):
+        (WebCore::attributeHash): Deleted.
+        * dom/QualifiedName.cpp:
+        (WebCore::QualifiedName::QualifiedNameImpl::computeHash const):
+        * dom/QualifiedName.h:
+        (WebCore::add):
+        (WebCore::hashComponents): Deleted.
+        * dom/QualifiedNameCache.cpp:
+        (WebCore::QNameComponentsTranslator::hash):
+        * page/GlobalWindowIdentifier.h:
+        (WebCore::add):
+        (WTF::GlobalWindowIdentifierHash::hash):
+        (WebCore::GlobalWindowIdentifier::hash const): Deleted.
+        * page/SecurityOriginHash.h:
+        (WebCore::SecurityOriginHash::hash):
+        * platform/ScriptExecutionContextIdentifier.h:
+        (WebCore::add):
+        (WebCore::ProcessQualified<UUID>::hash const): Deleted.
+        (WTF::computeHash): Deleted.
+        * platform/graphics/cocoa/FontPlatformDataCocoa.mm:
+        (WebCore::FontPlatformData::hash const):
+        * platform/graphics/win/FontPlatformDataCGWin.cpp:
+        (WebCore::FontPlatformData::hash const):
+        * svg/SVGElementInlines.h:
+        (WebCore::SVGAttributeHashTranslator::hash):
+        * workers/service/ServiceWorkerRegistrationKey.cpp:
+        (WebCore::ServiceWorkerRegistrationKey::hash const): Deleted.
+        * workers/service/ServiceWorkerRegistrationKey.h:
+        (WebCore::add):
+        (WTF::ServiceWorkerRegistrationKeyHash::hash):
+
 2022-02-22  Tim Nguyen  <[email protected]>
 
         Create a DOMWindow::printWarningMessage method and start using it in DOMWindow.cpp

Modified: trunk/Source/WebCore/Modules/indexeddb/shared/IDBResourceIdentifier.h (290348 => 290349)


--- trunk/Source/WebCore/Modules/indexeddb/shared/IDBResourceIdentifier.h	2022-02-23 06:01:13 UTC (rev 290348)
+++ trunk/Source/WebCore/Modules/indexeddb/shared/IDBResourceIdentifier.h	2022-02-23 06:12:31 UTC (rev 290349)
@@ -26,7 +26,7 @@
 #pragma once
 
 #include "ProcessIdentifier.h"
-#include <wtf/text/StringHash.h>
+#include <wtf/Hasher.h>
 
 namespace WebCore {
 
@@ -55,12 +55,6 @@
         return !m_resourceNumber && !m_idbConnectionIdentifier;
     }
 
-    unsigned hash() const
-    {
-        uint64_t hashCodes[2] = { m_idbConnectionIdentifier.toUInt64(), m_resourceNumber };
-        return StringHasher::hashMemory<sizeof(hashCodes)>(hashCodes);
-    }
-
     bool operator!=(const IDBResourceIdentifier& other) const { return !(*this == other); }
     bool operator==(const IDBResourceIdentifier& other) const
     {
@@ -83,6 +77,7 @@
 
 private:
     friend struct IDBResourceIdentifierHashTraits;
+    friend void add(Hasher&, const IDBResourceIdentifier&);
 
     IDBResourceIdentifier(IDBConnectionIdentifier, uint64_t resourceIdentifier);
     IDBConnectionIdentifier m_idbConnectionIdentifier;
@@ -89,8 +84,13 @@
     uint64_t m_resourceNumber { 0 };
 };
 
+inline void add(Hasher& hasher, const IDBResourceIdentifier& identifier)
+{
+    add(hasher, identifier.m_idbConnectionIdentifier, identifier.m_resourceNumber);
+}
+
 struct IDBResourceIdentifierHash {
-    static unsigned hash(const IDBResourceIdentifier& a) { return a.hash(); }
+    static unsigned hash(const IDBResourceIdentifier& a) { return computeHash(a); }
     static bool equal(const IDBResourceIdentifier& a, const IDBResourceIdentifier& b) { return a == b; }
     static const bool safeToCompareToEmptyOrDeleted = false;
 };

Modified: trunk/Source/WebCore/dom/Attribute.h (290348 => 290349)


--- trunk/Source/WebCore/dom/Attribute.h	2022-02-23 06:01:13 UTC (rev 290348)
+++ trunk/Source/WebCore/dom/Attribute.h	2022-02-23 06:12:31 UTC (rev 290349)
@@ -25,6 +25,7 @@
 #pragma once
 
 #include "QualifiedName.h"
+#include <wtf/Hasher.h>
 
 namespace WebCore {
 
@@ -74,6 +75,11 @@
     AtomString m_value;
 };
 
+inline void add(Hasher& hasher, const Attribute& attribute)
+{
+    add(hasher, attribute.name(), attribute.value());
+}
+
 inline bool Attribute::nameMatchesFilter(const QualifiedName& name, const AtomString& filterPrefix, const AtomString& filterLocalName, const AtomString& filterNamespaceURI)
 {
     if (filterLocalName != name.localName())

Modified: trunk/Source/WebCore/dom/DocumentSharedObjectPool.cpp (290348 => 290349)


--- trunk/Source/WebCore/dom/DocumentSharedObjectPool.cpp	2022-02-23 06:01:13 UTC (rev 290348)
+++ trunk/Source/WebCore/dom/DocumentSharedObjectPool.cpp	2022-02-23 06:12:31 UTC (rev 290349)
@@ -32,11 +32,6 @@
 
 namespace WebCore {
 
-inline unsigned attributeHash(const Vector<Attribute>& attributes)
-{
-    return StringHasher::hashMemory(attributes.data(), attributes.size() * sizeof(Attribute));
-}
-
 inline bool hasSameAttributes(const Vector<Attribute>& attributes, ShareableElementData& elementData)
 {
     if (attributes.size() != elementData.length())
@@ -48,7 +43,7 @@
 {
     ASSERT(!attributes.isEmpty());
 
-    auto& cachedData = m_shareableElementDataCache.add(attributeHash(attributes), nullptr).iterator->value;
+    auto& cachedData = m_shareableElementDataCache.add(computeHash(attributes), nullptr).iterator->value;
 
     // FIXME: This prevents sharing when there's a hash collision.
     if (cachedData && !hasSameAttributes(attributes, *cachedData))

Modified: trunk/Source/WebCore/dom/QualifiedName.cpp (290348 => 290349)


--- trunk/Source/WebCore/dom/QualifiedName.cpp	2022-02-23 06:01:13 UTC (rev 290348)
+++ trunk/Source/WebCore/dom/QualifiedName.cpp	2022-02-23 06:12:31 UTC (rev 290349)
@@ -69,7 +69,7 @@
 unsigned QualifiedName::QualifiedNameImpl::computeHash() const
 {
     QualifiedNameComponents components = { m_prefix.impl(), m_localName.impl(), m_namespace.impl() };
-    return hashComponents(components);
+    return WTF::computeHash(components);
 }
 
 }

Modified: trunk/Source/WebCore/dom/QualifiedName.h (290348 => 290349)


--- trunk/Source/WebCore/dom/QualifiedName.h	2022-02-23 06:01:13 UTC (rev 290348)
+++ trunk/Source/WebCore/dom/QualifiedName.h	2022-02-23 06:12:31 UTC (rev 290349)
@@ -21,6 +21,7 @@
 #pragma once
 
 #include <wtf/HashTraits.h>
+#include <wtf/Hasher.h>
 #include <wtf/NeverDestroyed.h>
 #include <wtf/text/AtomString.h>
 
@@ -27,11 +28,16 @@
 namespace WebCore {
 
 struct QualifiedNameComponents {
-    StringImpl* m_prefix;
-    StringImpl* m_localName;
-    StringImpl* m_namespace;
+    AtomStringImpl* m_prefix;
+    AtomStringImpl* m_localName;
+    AtomStringImpl* m_namespace;
 };
 
+inline void add(Hasher& hasher, const QualifiedNameComponents& components)
+{
+    add(hasher, components.m_prefix, components.m_localName, components.m_namespace);
+}
+
 DECLARE_ALLOCATOR_WITH_HEAP_IDENTIFIER(QualifiedName);
 DECLARE_ALLOCATOR_WITH_HEAP_IDENTIFIER(QualifiedNameQualifiedNameImpl);
 
@@ -110,6 +116,16 @@
     RefPtr<QualifiedNameImpl> m_impl;
 };
 
+inline void add(Hasher& hasher, const QualifiedName::QualifiedNameImpl& impl)
+{
+    add(hasher, impl.m_prefix, impl.m_localName, impl.m_namespace);
+}
+
+inline void add(Hasher& hasher, const QualifiedName& name)
+{
+    add(hasher, *name.impl());
+}
+
 extern LazyNeverDestroyed<const QualifiedName> anyName;
 inline const QualifiedName& anyQName() { return anyName; }
 
@@ -120,11 +136,6 @@
 inline bool operator==(const QualifiedName& q, const AtomString& a) { return a == q.localName(); }
 inline bool operator!=(const QualifiedName& q, const AtomString& a) { return a != q.localName(); }
 
-inline unsigned hashComponents(const QualifiedNameComponents& buf)
-{
-    return StringHasher::hashMemory<sizeof(QualifiedNameComponents)>(&buf);
-}
-
 struct QualifiedNameHash {
     static unsigned hash(const QualifiedName& name) { return hash(name.impl()); }
 

Modified: trunk/Source/WebCore/dom/QualifiedNameCache.cpp (290348 => 290349)


--- trunk/Source/WebCore/dom/QualifiedNameCache.cpp	2022-02-23 06:01:13 UTC (rev 290348)
+++ trunk/Source/WebCore/dom/QualifiedNameCache.cpp	2022-02-23 06:12:31 UTC (rev 290349)
@@ -32,7 +32,7 @@
 struct QNameComponentsTranslator {
     static unsigned hash(const QualifiedNameComponents& components)
     {
-        return hashComponents(components);
+        return computeHash(components);
     }
     static bool equal(QualifiedName::QualifiedNameImpl* name, const QualifiedNameComponents& c)
     {

Modified: trunk/Source/WebCore/page/GlobalWindowIdentifier.h (290348 => 290349)


--- trunk/Source/WebCore/page/GlobalWindowIdentifier.h	2022-02-23 06:01:13 UTC (rev 290348)
+++ trunk/Source/WebCore/page/GlobalWindowIdentifier.h	2022-02-23 06:12:31 UTC (rev 290349)
@@ -27,6 +27,7 @@
 
 #include "ProcessIdentifier.h"
 #include <wtf/HashTraits.h>
+#include <wtf/Hasher.h>
 #include <wtf/ObjectIdentifier.h>
 
 namespace WebCore {
@@ -39,8 +40,6 @@
     ProcessIdentifier processIdentifier;
     WindowIdentifier windowIdentifier;
 
-    unsigned hash() const;
-
     template<class Encoder> void encode(Encoder&) const;
     template<class Decoder> static std::optional<GlobalWindowIdentifier> decode(Decoder&);
 };
@@ -50,13 +49,9 @@
     return a.processIdentifier == b.processIdentifier &&  a.windowIdentifier == b.windowIdentifier;
 }
 
-inline unsigned GlobalWindowIdentifier::hash() const
+inline void add(Hasher& hasher, const GlobalWindowIdentifier& identifier)
 {
-    uint64_t identifiers[2];
-    identifiers[0] = processIdentifier.toUInt64();
-    identifiers[1] = windowIdentifier.toUInt64();
-
-    return StringHasher::hashMemory(identifiers, sizeof(identifiers));
+    add(hasher, identifier.processIdentifier, identifier.windowIdentifier);
 }
 
 template<class Encoder>
@@ -86,7 +81,7 @@
 namespace WTF {
 
 struct GlobalWindowIdentifierHash {
-    static unsigned hash(const WebCore::GlobalWindowIdentifier& key) { return key.hash(); }
+    static unsigned hash(const WebCore::GlobalWindowIdentifier& key) { return computeHash(key); }
     static bool equal(const WebCore::GlobalWindowIdentifier& a, const WebCore::GlobalWindowIdentifier& b) { return a == b; }
     static const bool safeToCompareToEmptyOrDeleted = true;
 };

Modified: trunk/Source/WebCore/page/SecurityOrigin.h (290348 => 290349)


--- trunk/Source/WebCore/page/SecurityOrigin.h	2022-02-23 06:01:13 UTC (rev 290348)
+++ trunk/Source/WebCore/page/SecurityOrigin.h	2022-02-23 06:12:31 UTC (rev 290349)
@@ -31,6 +31,7 @@
 #include "SecurityOriginData.h"
 #include "StorageBlockingPolicy.h"
 #include <wtf/EnumTraits.h>
+#include <wtf/Hasher.h>
 #include <wtf/ThreadSafeRefCounted.h>
 #include <wtf/text/WTFString.h>
 
@@ -307,4 +308,9 @@
     return origin;
 }
 
+inline void add(Hasher& hasher, const SecurityOrigin& origin)
+{
+    add(hasher, origin.protocol(), origin.host(), origin.port());
+}
+
 } // namespace WebCore

Modified: trunk/Source/WebCore/page/SecurityOriginHash.h (290348 => 290349)


--- trunk/Source/WebCore/page/SecurityOriginHash.h	2022-02-23 06:01:13 UTC (rev 290348)
+++ trunk/Source/WebCore/page/SecurityOriginHash.h	2022-02-23 06:12:31 UTC (rev 290349)
@@ -28,6 +28,7 @@
 
 #pragma once
 
+#include <wtf/Hasher.h>
 #include <wtf/URL.h>
 #include "SecurityOrigin.h"
 #include <wtf/RefPtr.h>
@@ -37,12 +38,7 @@
 struct SecurityOriginHash {
     static unsigned hash(SecurityOrigin* origin)
     {
-        unsigned hashCodes[3] = {
-            origin->protocol().impl() ? origin->protocol().impl()->hash() : 0,
-            origin->host().impl() ? origin->host().impl()->hash() : 0,
-            origin->port().value_or(0)
-        };
-        return StringHasher::hashMemory<sizeof(hashCodes)>(hashCodes);
+        return computeHash(*origin);
     }
     static unsigned hash(const RefPtr<SecurityOrigin>& origin)
     {

Modified: trunk/Source/WebCore/platform/ScriptExecutionContextIdentifier.h (290348 => 290349)


--- trunk/Source/WebCore/platform/ScriptExecutionContextIdentifier.h	2022-02-23 06:01:13 UTC (rev 290348)
+++ trunk/Source/WebCore/platform/ScriptExecutionContextIdentifier.h	2022-02-23 06:12:31 UTC (rev 290349)
@@ -58,7 +58,6 @@
     const UUID& object() const { return m_object; }
     ProcessIdentifier processIdentifier() const { return m_processIdentifier; }
 
-    unsigned hash() const { return m_object.hash(); }
     bool isHashTableDeletedValue() const { return m_processIdentifier.isHashTableDeletedValue(); }
 
     bool operator==(const ProcessQualified& other) const { return m_object == other.m_object && m_processIdentifier == other.m_processIdentifier; }
@@ -74,6 +73,12 @@
     ProcessIdentifier m_processIdentifier;
 };
 
+inline void add(Hasher& hasher, const ProcessQualified<UUID>& uuid)
+{
+    // Since UUIDs are unique on their own, optimize by not hashing the process identifier.
+    add(hasher, uuid.object());
+}
+
 template<typename Decoder> std::optional<ProcessQualified<UUID>> ProcessQualified<UUID>::decode(Decoder& decoder)
 {
     std::optional<UUID> object;
@@ -97,13 +102,3 @@
 using ScriptExecutionContextIdentifier = ProcessQualified<UUID>;
 
 }
-
-namespace WTF {
-
-template<>
-inline uint32_t computeHash(const WebCore::ScriptExecutionContextIdentifier& identifier)
-{
-    return identifier.object().hash();
-}
-
-}

Modified: trunk/Source/WebCore/platform/graphics/cocoa/FontPlatformDataCocoa.mm (290348 => 290349)


--- trunk/Source/WebCore/platform/graphics/cocoa/FontPlatformDataCocoa.mm	2022-02-23 06:01:13 UTC (rev 290348)
+++ trunk/Source/WebCore/platform/graphics/cocoa/FontPlatformDataCocoa.mm	2022-02-23 06:12:31 UTC (rev 290349)
@@ -27,6 +27,7 @@
 #import "FontCacheCoreText.h"
 #import "SharedBuffer.h"
 #import <pal/spi/cf/CoreTextSPI.h>
+#import <wtf/Hasher.h>
 #import <wtf/text/StringConcatenateNumbers.h>
 
 #if PLATFORM(IOS_FAMILY)
@@ -38,16 +39,8 @@
 
 unsigned FontPlatformData::hash() const
 {
-    uintptr_t flags = static_cast<uintptr_t>(static_cast<unsigned>(m_widthVariant) << 6
-        | m_isHashTableDeletedValue << 5
-        | static_cast<unsigned>(m_textRenderingMode) << 3
-        | static_cast<unsigned>(m_orientation) << 2
-        | m_syntheticBold << 1
-        | m_syntheticOblique);
-
-    uintptr_t fontHash = static_cast<uintptr_t>(CFHash(m_font.get()));
-    uintptr_t hashCodes[] = { fontHash, flags };
-    return StringHasher::hashMemory<sizeof(hashCodes)>(hashCodes);
+    // FIXME: Hashing a CFHash is unfortunate here.
+    return computeHash(CFHash(m_font.get()), m_widthVariant, m_isHashTableDeletedValue, m_textRenderingMode, m_orientation, m_orientation, m_syntheticBold, m_syntheticOblique);
 }
 
 bool FontPlatformData::platformIsEqual(const FontPlatformData& other) const

Modified: trunk/Source/WebCore/platform/graphics/win/FontPlatformDataCGWin.cpp (290348 => 290349)


--- trunk/Source/WebCore/platform/graphics/win/FontPlatformDataCGWin.cpp	2022-02-23 06:01:13 UTC (rev 290348)
+++ trunk/Source/WebCore/platform/graphics/win/FontPlatformDataCGWin.cpp	2022-02-23 06:12:31 UTC (rev 290349)
@@ -30,6 +30,7 @@
 #include <pal/spi/cg/CoreGraphicsSPI.h>
 #include <pal/spi/win/CoreTextSPIWin.h>
 #include <wtf/HashMap.h>
+#include <wtf/Hasher.h>
 #include <wtf/RetainPtr.h>
 #include <wtf/Vector.h>
 #include <wtf/text/StringHash.h>
@@ -133,11 +134,11 @@
 
 unsigned FontPlatformData::hash() const
 {
+    // FIXME: Hashing hashes here is unfortunate.
     unsigned fontHash = m_font ? m_font->hash() : 0;
     CFHashCode cgFontHash = safeCFHash(m_cgFont.get());
     CFHashCode ctFontHash = safeCFHash(m_ctFont.get());
-    uintptr_t hashCodes[] = { fontHash, cgFontHash, ctFontHash, m_useGDI };
-    return StringHasher::hashMemory<sizeof(hashCodes)>(hashCodes);
+    return computeHash(fontHash, cgFontHash, ctFontHash, m_useGDI);
 }
 
 bool FontPlatformData::platformIsEqual(const FontPlatformData& other) const

Modified: trunk/Source/WebCore/svg/SVGElementInlines.h (290348 => 290349)


--- trunk/Source/WebCore/svg/SVGElementInlines.h	2022-02-23 06:01:13 UTC (rev 290348)
+++ trunk/Source/WebCore/svg/SVGElementInlines.h	2022-02-23 06:12:31 UTC (rev 290349)
@@ -47,7 +47,7 @@
     {
         if (key.hasPrefix()) {
             QualifiedNameComponents components = { nullAtom().impl(), key.localName().impl(), key.namespaceURI().impl() };
-            return hashComponents(components);
+            return computeHash(components);
         }
         return DefaultHash<QualifiedName>::hash(key);
     }

Modified: trunk/Source/WebCore/workers/service/ServiceWorkerRegistrationKey.cpp (290348 => 290349)


--- trunk/Source/WebCore/workers/service/ServiceWorkerRegistrationKey.cpp	2022-02-23 06:01:13 UTC (rev 290348)
+++ trunk/Source/WebCore/workers/service/ServiceWorkerRegistrationKey.cpp	2022-02-23 06:12:31 UTC (rev 290349)
@@ -46,15 +46,6 @@
     return { };
 }
 
-unsigned ServiceWorkerRegistrationKey::hash() const
-{
-    unsigned hashes[2];
-    hashes[0] = SecurityOriginDataHash::hash(m_topOrigin);
-    hashes[1] = StringHash::hash(m_scope.string());
-
-    return StringHasher::hashMemory(hashes, sizeof(hashes));
-}
-
 bool ServiceWorkerRegistrationKey::operator==(const ServiceWorkerRegistrationKey& other) const
 {
     return m_topOrigin == other.m_topOrigin && m_scope == other.m_scope;

Modified: trunk/Source/WebCore/workers/service/ServiceWorkerRegistrationKey.h (290348 => 290349)


--- trunk/Source/WebCore/workers/service/ServiceWorkerRegistrationKey.h	2022-02-23 06:01:13 UTC (rev 290348)
+++ trunk/Source/WebCore/workers/service/ServiceWorkerRegistrationKey.h	2022-02-23 06:12:31 UTC (rev 290349)
@@ -28,6 +28,7 @@
 #if ENABLE(SERVICE_WORKER)
 
 #include "SecurityOriginData.h"
+#include <wtf/Hasher.h>
 #include <wtf/URL.h>
 
 namespace WebCore {
@@ -38,7 +39,6 @@
     WEBCORE_EXPORT ServiceWorkerRegistrationKey(SecurityOriginData&& topOrigin, URL&& scope);
 
     static ServiceWorkerRegistrationKey emptyKey();
-    unsigned hash() const;
 
     bool operator==(const ServiceWorkerRegistrationKey&) const;
     bool operator!=(const ServiceWorkerRegistrationKey& key) const { return !(*this == key); }
@@ -96,12 +96,17 @@
     return ServiceWorkerRegistrationKey { WTFMove(*topOrigin), WTFMove(scope) };
 }
 
+inline void add(Hasher& hasher, const ServiceWorkerRegistrationKey& key)
+{
+    add(hasher, key.topOrigin(), key.scope());
+}
+
 } // namespace WebCore
 
 namespace WTF {
 
 struct ServiceWorkerRegistrationKeyHash {
-    static unsigned hash(const WebCore::ServiceWorkerRegistrationKey& key) { return key.hash(); }
+    static unsigned hash(const WebCore::ServiceWorkerRegistrationKey& key) { return computeHash(key); }
     static bool equal(const WebCore::ServiceWorkerRegistrationKey& a, const WebCore::ServiceWorkerRegistrationKey& b) { return a == b; }
     static const bool safeToCompareToEmptyOrDeleted = false;
 };

Modified: trunk/Source/WebKitLegacy/mac/ChangeLog (290348 => 290349)


--- trunk/Source/WebKitLegacy/mac/ChangeLog	2022-02-23 06:01:13 UTC (rev 290348)
+++ trunk/Source/WebKitLegacy/mac/ChangeLog	2022-02-23 06:12:31 UTC (rev 290349)
@@ -1,3 +1,14 @@
+2022-02-22  Chris Dumez  <[email protected]>
+
+        Drop StringHasher::hashMemory() and use the modern Hasher instead
+        https://bugs.webkit.org/show_bug.cgi?id=237049
+
+        Reviewed by Sam Weinig and Darin Adler.
+
+        * History/BinaryPropertyList.cpp:
+        (add):
+        (IntegerArrayHash::hash):
+
 2022-02-18  Robert Jenner  <[email protected]>
 
         Unreviewed, reverting r290149.

Modified: trunk/Source/WebKitLegacy/mac/History/BinaryPropertyList.cpp (290348 => 290349)


--- trunk/Source/WebKitLegacy/mac/History/BinaryPropertyList.cpp	2022-02-23 06:01:13 UTC (rev 290348)
+++ trunk/Source/WebKitLegacy/mac/History/BinaryPropertyList.cpp	2022-02-23 06:12:31 UTC (rev 290349)
@@ -27,6 +27,7 @@
 
 #include <limits>
 #include <wtf/HashMap.h>
+#include <wtf/Hasher.h>
 #include <wtf/text/StringHash.h>
 
 static const size_t headerSize = 8;
@@ -73,6 +74,11 @@
     return a.m_integers == b.m_integers &&  a.m_size == b.m_size;
 }
 
+inline void add(Hasher& hasher, const IntegerArray& array)
+{
+    add(hasher, Span { array.integers(), array.size() });
+}
+
 struct IntegerArrayHashTraits : HashTraits<IntegerArray> {
     static void constructDeletedValue(IntegerArray& slot) { HashTraits<size_t>::constructDeletedValue(slot.m_size); }
     static bool isDeletedValue(const IntegerArray& slot) { return HashTraits<size_t>::isDeletedValue(slot.m_size); }
@@ -79,16 +85,11 @@
 };
 
 struct IntegerArrayHash {
-    static unsigned hash(const IntegerArray&);
+    static unsigned hash(const IntegerArray& array) { return computeHash(array); }
     static bool equal(const IntegerArray&, const IntegerArray&);
     static const bool safeToCompareToEmptyOrDeleted = true;
 };
 
-unsigned IntegerArrayHash::hash(const IntegerArray& array)
-{
-    return StringHasher::hashMemory(array.integers(), array.size() * sizeof(int));
-}
-
 bool IntegerArrayHash::equal(const IntegerArray& a, const IntegerArray& b)
 {
     if (a.isDeletedValue() || b.isDeletedValue())

Modified: trunk/Tools/ChangeLog (290348 => 290349)


--- trunk/Tools/ChangeLog	2022-02-23 06:01:13 UTC (rev 290348)
+++ trunk/Tools/ChangeLog	2022-02-23 06:12:31 UTC (rev 290349)
@@ -1,3 +1,12 @@
+2022-02-22  Chris Dumez  <[email protected]>
+
+        Drop StringHasher::hashMemory() and use the modern Hasher instead
+        https://bugs.webkit.org/show_bug.cgi?id=237049
+
+        Reviewed by Sam Weinig.
+
+        * TestWebKitAPI/Tests/WTF/StringHasher.cpp:
+
 2022-02-22  Ryan Haddad  <[email protected]>
 
         REGRESSION(r289580): [ iOS macOS ] TestWebKitAPI.IPCTestingAPI.CanReceiveSharedMemory is a constant timeout

Modified: trunk/Tools/TestWebKitAPI/Tests/WTF/StringHasher.cpp (290348 => 290349)


--- trunk/Tools/TestWebKitAPI/Tests/WTF/StringHasher.cpp	2022-02-23 06:01:13 UTC (rev 290348)
+++ trunk/Tools/TestWebKitAPI/Tests/WTF/StringHasher.cpp	2022-02-23 06:12:31 UTC (rev 290349)
@@ -462,20 +462,4 @@
     ASSERT_EQ(testBHash5 & 0xFFFFFF, StringHasher::computeHashAndMaskTop8Bits(testBUChars, 5));
 }
 
-TEST(WTF, StringHasher_hashMemory)
-{
-    ASSERT_EQ(emptyStringHash, StringHasher::hashMemory(0, 0));
-    ASSERT_EQ(emptyStringHash, StringHasher::hashMemory(nullUChars, 0));
-    ASSERT_EQ(emptyStringHash, StringHasher::hashMemory<0>(0));
-    ASSERT_EQ(emptyStringHash, StringHasher::hashMemory<0>(nullUChars));
-
-    ASSERT_EQ(singleNullCharacterHash, StringHasher::hashMemory(nullUChars, 2));
-    ASSERT_EQ(singleNullCharacterHash, StringHasher::hashMemory<2>(nullUChars));
-
-    ASSERT_EQ(testAHash5, StringHasher::hashMemory(testAUChars, 10));
-    ASSERT_EQ(testAHash5, StringHasher::hashMemory<10>(testAUChars));
-    ASSERT_EQ(testBHash5, StringHasher::hashMemory(testBUChars, 10));
-    ASSERT_EQ(testBHash5, StringHasher::hashMemory<10>(testBUChars));
-}
-
 } // namespace TestWebKitAPI
_______________________________________________
webkit-changes mailing list
[email protected]
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to