Changeset 275650 in webkit


Ignore:
Timestamp:
Apr 7, 2021 7:19:20 PM (3 years ago)
Author:
Darin Adler
Message:

Use Hasher more, remove IntegerHasher, fix hashing-related mistakes
https://bugs.webkit.org/show_bug.cgi?id=224138

Reviewed by Chris Dumez.

Source/JavaScriptCore:

  • bytecode/BytecodeIndex.h:

(JSC::BytecodeIndex::hash const): Remove unneeded WTF prefix on call
to intHash.

  • ftl/FTLAbstractHeap.h: Use HashTraits instead of WTF::GenericHashTraits.
  • ftl/FTLLowerDFGToB3.cpp:

(JSC::FTL::DFG::LowerDFGToB3::validateAIState): Remove unneeded WTF
prefix on call to intHash.

  • wasm/WasmLLIntGenerator.cpp: Use HashTraits instead of WTF::GenericHashTraits.

Source/WebCore:

  • contentextensions/ContentExtensionRule.h:

(WebCore::ContentExtensions::TriggerHash::hash): Use computeHash to
hash all the fields instead of a custom-written algorithm. The custom
algorithm had some magic numbers, repeatedly hashed hashes, and combined
hashes using exclusive or. The new one is almost certainly better.

  • contentextensions/Term.h:

(WebCore::ContentExtensions::Term::CharacterSet::hash const):
Use computeHash to hash the boolean and the characters rather than
using intHash and pairIntHash.

  • css/parser/CSSParserContext.cpp:

(WebCore::add): Moved the hashing here from the header. Fixed the
mistake where this was using & instead of | and so none of the booleans
were having any effect on the hash value.

  • css/parser/CSSParserContext.h: Use WTF_MAKE_STRUCT_FAST_ALLOCATED so

we don't have to say public: explicitly. Also moved all the function
members to the bottom of the struct. This is typically preferred style
for structures as opposed to classes. Since the data members are the
primary interface, they are first, and all function members are secondary
and so they come after.
(WebCore::CSSParserContextHash::hash): Use convertHash instead of
a custom written hash function. The custom written function was combining
hahes using exclusive or, not a best practice, and also had a mistake
where it used & instead of | and so the "bits" local variable was always 0.

  • html/FormController.cpp: Use HashTraits instead of WTF::GenericHashTraits.
  • platform/encryptedmedia/CDMProxy.h: Removed unneedes includes.
  • platform/graphics/Font.cpp: Changed CharacterFallbackMapKey into a

simple struct with no additional function members or static data members.
Changed CharacterFallbackMapKeyHash to use computeHash to calculate the
hash, instead of IntegerHasher. Probably better to hash the pointer of
the AtomString rather than hashing the hash, but either way, we should
have the best implementation for AtomString hashing in the Hasher class.
Added CharacterFallbackMapKeyHashTraits instead of using
SimpleClassHashTraits. Use the value U_SENTINEL for the UChar32 character,
which is the same as the -1 used before, but slightly clearer why it's OK.
(WebCore::Font::systemFallbackFontForCharacter const): Use HashMap::ensure
instead of HashMap::add to make the logic simpler.

  • platform/graphics/Font.h: Use bool instead of uint8_t as the base type

for the No/Yes enumeration IsForPlatformFont.

  • platform/graphics/FontCache.cpp: Removed unneeded "using namespace WTF",

which is not our best practice, especially given unified builds.
Changed FontPlatformDataCacheKey into a simple struct, removing all the
hash-related member functions. Also used struct-style naming for the
members without an "m_" prefix. Used the type FontFamilyName for the
family name, which means we will use FontCascadeDescription's system
for hashing and comparing family names for equality without having to
remember do to so explicitly. Changed FontPlatformDataCacheKeyHash to
use computeHash. The old version had unnecessarily complex logic to
handle Optional and was unnecessarily hashing hashes.
(WebCore::FontCache::cachedFontPlatformData): Renamed to remove "get"
from the function's name. Also use shorter argument and local variable
names that are single words, and updated since FontPlatformDataCacheKey
is now a struct without a constructor.
(WebCore::FontCache::fontForFamily): Use shorter names.
(WebCore::operator==): To compare two FontCascadeCacheKey objects,
use a simpler constructions, depending on the fact that Vector already
has an == operator and we are using FontFamilyName for the elements
of the vector, which has a correct == operator.
(WebCore::FontCascadeCacheKeyHash::hash): Use computeHash since
the FontFamilyName hashing is now correct, and we can rely on the
way Hasher knows how to iterate a collection.
(WebCore::FontCache::retrieveOrAddCachedFonts): Update since
FontCascadeCacheEntry is now a simple struct. Also use constexpr a bit.
(WebCore::FontCache::invalidate): Use copyToVectorOf<> to simplify the
code that calls fontCacheInvalidated on all the font selectors.

  • platform/graphics/FontCache.h: Use "using" instead of "typedef".

Remove FontDescriptionKey::computeHash.
(WebCore::add): An overload of add for Hasher to include a
FontDescriptionKey in a hash, which just lists all the data members.
The old version did a hash of hashes, but that's not needed any more.
Updated FontDescriptionKeyHash to use the Hasher version of ComputeHash.
Added FontFamilyName. Change FontCascadeCacheKey to use a vector of
FontFamilyName instead of AtomString. In FontCascadeCacheEntry, use
WTF_MAKE_STRUCT_FAST_ALLOCATED instead of WTF_MAKE_FAST_ALLOCATED
and also got rid of the unneeeded constructor.
(WebCore::FontCascadeCacheKeyHashTraits::constructDeletedValue):
Use the deleted value of FontDescriptionKey.
(WebCore::FontCascadeCacheKeyHashTraits::isDeletedValue): Ditto.
Renamed getCachedFontPlatformData to just cachedFontPlatformData.

  • platform/graphics/FontGenericFamilies.h: Use HashTraits instead of

WTF::GenericHashTraits.

  • platform/graphics/FontSelectionAlgorithm.h:

(WebCore::FontSelectionRange::uniqueValue const): Deleted.
(WebCore::add): Add both the minimum and maximum values to the hash
separately instead of combining them. For now, this makes the way
they are hashed a bit inefficient, but that can be re-tightened up by
improving the algorithm of Hasher if we like. Should be fine for our
needs either way.

  • platform/graphics/FontTaggedSettings.cpp:

(WebCore::FontFeatureSettings::hash const): Deleted.
(WebCore::FontVariationSettings::hash const): Deleted.

  • platform/graphics/FontTaggedSettings.h: Added overloads of the

add(Hasher&) function for std::array<char, 4> and FontTaggedSetting<T>.
Got rid of many uses of pass by reference instead of value for FontTag,
since it fits into a 32-bit register and bth more source code and less
efficient to pass by value.

  • platform/graphics/Gradient.cpp: Removed "using WTF::pairIntHash" since

that's now done in the WTF header.

  • platform/graphics/cg/GraphicsContextCG.cpp: Ditto. Also removed

"using WTF::GenericHashTraits", which was unhelpful. The GenericHashTraits
template is only really needed when specializing HashTraits, which
already has to be done within the WTF namespace. In all other cases, we
should just use HashTraits instead.

  • platform/graphics/cg/SubimageCacheWithTimer.h: Use HashTraits

instead of WTF::GenericHashTraits.

  • platform/graphics/cocoa/FontFamilySpecificationCoreText.cpp:

Move the data members to the top of the FontFamilySpecificationKey struct.
Removed unneeded computeHash function and WTF prefix from safeCFEqual.
(WebCore::FontFamilySpecificationKeyHash::hash): Call the Hasher version
of computeHash directly to hash the two items in this structure.

  • platform/graphics/cocoa/SystemFontDatabaseCoreText.h:

(WebCore::SystemFontDatabaseCoreText::CascadeListParameters::hash const):
Use computeHash instead of IntegerHasher. Also renamed the hash function
struct from CascadeListParameters::CascadeListParametersHash to
CascadeListParameters::Hash.

  • platform/graphics/mac/ComplexTextControllerCoreText.mm:

(WebCore::ComplexTextController::collectComplexTextRunsForCharacters):
Removed now-unneeded WTF prefixes from calls to safeCFEqual.

  • rendering/TextAutoSizing.h: Use HashTraits instead of WTF::GenericHashTraits.
  • rendering/style/RenderStyle.cpp:

(WebCore::computeFontHash): Use computeHash instead of IntegerHasher.
Still not great that we hash a hash here, but we can improve that later.

  • workers/service/ServiceWorkerClientIdentifier.h:

(WebCore::ServiceWorkerClientIdentifier::decode): Removed unneeded
WTFMove on ObjectIdentifier, which are just integers, so move vs. copy
is not an important distinction.
(WebCore::ServiceWorkerClientIdentifier::hash const): Use computeHash
instead of combining intHash with StringHasher::hashMemory. This fixes
two mistakes: one is that there is no need to hash a hash. The second is
that intHash takes a 32-bit integer as its parameter, so high bits
of object identifiers were discarded unnecessarily.

  • workers/service/ServiceWorkerContextData.h: Removed unneeded include.
  • workers/service/ServiceWorkerGlobalScope.h: Added now-needed include

of URLHash.h, since we removed it from a widely-included header.

  • workers/service/context/SWContextManager.h: Ditto.
  • workers/service/server/ServiceWorkerThreadProxy.h: Ditto.
  • workers/service/server/RegistrationStore.h: Ditto.
  • workers/service/server/SWServer.h: Ditto.
  • workers/service/server/SWServerToContextConnection.h: Ditto.
  • workers/service/server/SWServerWorker.h: Ditto.

Source/WebKit:

  • NetworkProcess/ServiceWorker/WebSWServerToContextConnection.h: Added now-needed include

of URLHash.h, since we removed it from a widely-included header.

  • NetworkProcess/cache/NetworkCache.h:

(WebKit::NetworkCache::GlobalFrameID::hash const): Use computeHash
instead of combining intHash with StringHasher::hashMemory. This fixes
two mistakes: one is that there is no need to hash a hash. The second is
that intHash takes a 32-bit integer as its parameter, so high bits
of object identifiers were discarded unnecessarily.

  • Scripts/webkit/messages.py: Added code so that if URL is in an argument, we include the

URLHash.h header. Would be better to just use URL.h and use URLHash.h only if it's a
HashMap<URL>, but currently the script does not distinguish those cases. This wasn't needed
before becuase a widely included header was always pulling in URLHash.h.

  • Shared/API/Cocoa/WKBrowsingContextHandle.mm:

(-[WKBrowsingContextHandle hash]): Use computeHash instead of pairIntHash.
This fixes a mistake: pairIntHash takes two 32-bit integers, so high bits
of object identifiers were discarded unnecessarily.

  • NetworkProcess/Storage/WebSWContextManagerConnection.h: Added now-needed include

of URLHash.h, since we removed it from a widely-included header.

Source/WebKitLegacy/mac:

  • History/BinaryPropertyList.cpp: Use HashTraits instead of WTF::GenericHashTraits.

Source/WTF:

  • wtf/HashFunctions.h: Export intHash and pairIntHash to the global namespace

so they can be called without an explicit WTF prefix. This follows the usual
WTF design pattern given that these functions are intended for use outside WTF.

  • wtf/Hasher.h: Deleted IntegerHasher.

(WTF::add): Added overloads for String, AtomString, and URL.

  • wtf/ObjectIdentifier.h:

(WTF::add): Added a Hasher overload for any ObjectIdentifier.

  • wtf/RetainPtr.h: Export safeCFEqual and safeCFHash to the global namespace

so they can be called without an explicit WTF prefix. This follows the usual
WTF design pattern given that these functions are intended for use outside WTF.

  • wtf/VectorHash.h: Removed the VectorHash template, instead just specializing

DefaultHash. Use computeHash to hash the contents of the vector instead of
hashing the hashes of the items in the vector. This is better in general and
better for the one case where we are currently using this, for a Vector<int>.
We want to hash all the integers rather than hashing hashes of all the integers.
In the future, this means the elements of the Vector need to be hashable using
the Hasher machinery. The old requirement was the the elements had a DefaultHash.

Location:
trunk/Source
Files:
53 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/JavaScriptCore/ChangeLog

    r275648 r275650  
     12021-04-02  Darin Adler  <darin@apple.com>
     2
     3        Use Hasher more, remove IntegerHasher, fix hashing-related mistakes
     4        https://bugs.webkit.org/show_bug.cgi?id=224138
     5
     6        Reviewed by Chris Dumez.
     7
     8        * bytecode/BytecodeIndex.h:
     9        (JSC::BytecodeIndex::hash const): Remove unneeded WTF prefix on call
     10        to intHash.
     11
     12        * ftl/FTLAbstractHeap.h: Use HashTraits instead of WTF::GenericHashTraits.
     13
     14        * ftl/FTLLowerDFGToB3.cpp:
     15        (JSC::FTL::DFG::LowerDFGToB3::validateAIState): Remove unneeded WTF
     16        prefix on call to intHash.
     17
     18        * wasm/WasmLLIntGenerator.cpp: Use HashTraits instead of WTF::GenericHashTraits.
     19
    1202021-04-07  Mark Lam  <mark.lam@apple.com>
    221
  • trunk/Source/JavaScriptCore/bytecode/BytecodeIndex.h

    r264488 r275650  
    6161    uint32_t asBits() const { return m_packedBits; }
    6262
    63     unsigned hash() const { return WTF::intHash(m_packedBits); }
     63    unsigned hash() const { return intHash(m_packedBits); }
    6464    static BytecodeIndex deletedValue() { return fromBits(invalidOffset - 1); }
    6565    bool isHashTableDeletedValue() const { return *this == deletedValue(); }
  • trunk/Source/JavaScriptCore/ftl/FTLAbstractHeap.h

    r262338 r275650  
    155155    std::array<AbstractHeap, 16> m_smallIndices;
    156156   
    157     struct WithoutZeroOrOneHashTraits : WTF::GenericHashTraits<ptrdiff_t> {
     157    struct WithoutZeroOrOneHashTraits : HashTraits<ptrdiff_t> {
    158158        static void constructDeletedValue(ptrdiff_t& slot) { slot = 1; }
    159159        static bool isDeletedValue(ptrdiff_t value) { return value == 1; }
  • trunk/Source/JavaScriptCore/ftl/FTLLowerDFGToB3.cpp

    r275626 r275650  
    592592        unsigned highParentIndex = node->index();
    593593        {
    594             uint64_t hash = WTF::intHash(highParentIndex);
    595             if (hash >= static_cast<uint64_t>((static_cast<double>(std::numeric_limits<unsigned>::max()) + 1) * Options::validateAbstractInterpreterStateProbability()))
     594            if (intHash(highParentIndex) >= (static_cast<double>(std::numeric_limits<unsigned>::max()) + 1) * Options::validateAbstractInterpreterStateProbability())
    596595                return;
    597596        }
  • trunk/Source/JavaScriptCore/wasm/WasmLLIntGenerator.cpp

    r273962 r275650  
    417417    };
    418418
    419     struct ConstantMapHashTraits : WTF::GenericHashTraits<EncodedJSValue> {
     419    struct ConstantMapHashTraits : HashTraits<EncodedJSValue> {
    420420        static constexpr bool emptyValueIsZero = true;
    421421        static void constructDeletedValue(EncodedJSValue& slot) { slot = JSValue::encode(jsNull()); }
  • trunk/Source/WTF/ChangeLog

    r275646 r275650  
     12021-04-02  Darin Adler  <darin@apple.com>
     2
     3        Use Hasher more, remove IntegerHasher, fix hashing-related mistakes
     4        https://bugs.webkit.org/show_bug.cgi?id=224138
     5
     6        Reviewed by Chris Dumez.
     7
     8        * wtf/HashFunctions.h: Export intHash and pairIntHash to the global namespace
     9        so they can be called without an explicit WTF prefix. This follows the usual
     10        WTF design pattern given that these functions are intended for use outside WTF.
     11
     12        * wtf/Hasher.h: Deleted IntegerHasher.
     13        (WTF::add): Added overloads for String, AtomString, and URL.
     14
     15        * wtf/ObjectIdentifier.h:
     16        (WTF::add): Added a Hasher overload for any ObjectIdentifier.
     17
     18        * wtf/RetainPtr.h: Export safeCFEqual and safeCFHash to the global namespace
     19        so they can be called without an explicit WTF prefix. This follows the usual
     20        WTF design pattern given that these functions are intended for use outside WTF.
     21
     22        * wtf/VectorHash.h: Removed the VectorHash template, instead just specializing
     23        DefaultHash. Use computeHash to hash the contents of the vector instead of
     24        hashing the hashes of the items in the vector. This is better in general and
     25        better for the one case where we are currently using this, for a Vector<int>.
     26        We want to hash all the integers rather than hashing hashes of all the integers.
     27        In the future, this means the elements of the Vector need to be hashable using
     28        the Hasher machinery. The old requirement was the the elements had a DefaultHash.
     29
    1302021-04-07  Michael Catanzaro  <mcatanzaro@gnome.org>
    231
  • trunk/Source/WTF/wtf/HashFunctions.h

    r264488 r275650  
    276276using WTF::IntHash;
    277277using WTF::PtrHash;
     278using WTF::intHash;
     279using WTF::pairIntHash;
  • trunk/Source/WTF/wtf/Hasher.h

    r267373 r275650  
    11/*
    2  * Copyright (C) 2016-2017 Apple Inc. All rights reserved.
     2 * Copyright (C) 2016-2021 Apple Inc. All rights reserved.
    33 *
    44 * This library is free software; you can redistribute it and/or
     
    2121#pragma once
    2222
    23 #include <wtf/Forward.h>
    2423#include <wtf/Optional.h>
    2524#include <wtf/StdLibExtras.h>
     25#include <wtf/URL.h>
     26#include <wtf/text/AtomString.h>
    2627#include <wtf/text/StringHasher.h>
    2728
    2829namespace WTF {
    29 
    30 // Deprecated. Use Hasher instead.
    31 class IntegerHasher {
    32     WTF_MAKE_FAST_ALLOCATED;
    33 public:
    34     void add(uint32_t integer)
    35     {
    36         m_underlyingHasher.addCharactersAssumingAligned(integer, integer >> 16);
    37     }
    38 
    39     unsigned hash() const
    40     {
    41         return m_underlyingHasher.hash();
    42     }
    43 
    44 private:
    45     StringHasher m_underlyingHasher;
    46 };
    4730
    4831template<typename... Types> uint32_t computeHash(const Types&...);
     
    11194{
    11295    add(hasher, bitwise_cast<uint32_t>(number));
     96}
     97
     98inline void add(Hasher& hasher, const String& string)
     99{
     100    // Chose to hash the characters here. Assuming this is better than hashing the possibly-already-computed hash of the characters.
     101    bool remainder = string.length() & 1;
     102    unsigned roundedLength = string.length() - remainder;
     103    for (unsigned i = 0; i < roundedLength; i += 2)
     104        add(hasher, (string[i] << 16) | string[i + 1]);
     105    if (remainder)
     106        add(hasher, string[roundedLength]);
     107}
     108
     109inline void add(Hasher& hasher, const AtomString& string)
     110{
     111    // Chose to hash the pointer here. Assuming this is better than hashing the characters or hashing the already-computed hash of the characters.
     112    add(hasher, bitwise_cast<uintptr_t>(string.impl()));
     113}
     114
     115inline void add(Hasher& hasher, const URL& url)
     116{
     117    add(hasher, url.string());
    113118}
    114119
     
    187192using WTF::computeHash;
    188193using WTF::Hasher;
    189 using WTF::IntegerHasher;
  • trunk/Source/WTF/wtf/ObjectIdentifier.h

    r264488 r275650  
    132132}
    133133
     134template<typename T> inline void add(Hasher& hasher, ObjectIdentifier<T> identifier)
     135{
     136    add(hasher, identifier.toUInt64());
     137}
     138
    134139template<typename T> struct ObjectIdentifierHash {
    135140    static unsigned hash(const ObjectIdentifier<T>& identifier) { return intHash(identifier.m_identifier); }
  • trunk/Source/WTF/wtf/RetainPtr.h

    r272985 r275650  
    403403using WTF::adoptCF;
    404404using WTF::retainPtr;
     405using WTF::safeCFEqual;
     406using WTF::safeCFHash;
    405407
    406408#ifdef __OBJC__
  • trunk/Source/WTF/wtf/VectorHash.h

    r264488 r275650  
    11/*
    2  * Copyright (C) 2019 Apple Inc. All Rights Reserved.
     2 * Copyright (C) 2019-2021 Apple Inc. All rights reserved.
    33 *
    44 * Redistribution and use in source and binary forms, with or without
     
    2727
    2828#include "HashFunctions.h"
    29 #include "HashTraits.h"
    3029#include "Hasher.h"
    3130
    3231namespace WTF {
    3332
    34 template<typename T, size_t inlineCapacity>
    35 struct VectorHash {
    36     static unsigned hash(const Vector<T, inlineCapacity>& vector)
    37     {
    38         IntegerHasher hasher;
    39         for (const auto& value : vector)
    40             hasher.add(DefaultHash<T>::hash(value));
    41         return hasher.hash();
    42     }
    43     static bool equal(const Vector<T, inlineCapacity>& a, const Vector<T, inlineCapacity>& b)
    44     {
    45         return a == b;
    46     }
     33template<typename T, size_t inlineCapacity> struct DefaultHash<Vector<T, inlineCapacity>> {
     34    static unsigned hash(const Vector<T, inlineCapacity>& vector) { return computeHash(vector); }
     35    static bool equal(const Vector<T, inlineCapacity>& a, const Vector<T, inlineCapacity>& b) { return a == b; }
    4736    static constexpr bool safeToCompareToEmptyOrDeleted = true;
    4837};
    4938
    50 template<typename T, size_t inlineCapacity>
    51 struct DefaultHash<Vector<T, inlineCapacity>> : VectorHash<T, inlineCapacity> { };
    52 
    5339}
  • trunk/Source/WebCore/ChangeLog

    r275648 r275650  
     12021-04-02  Darin Adler  <darin@apple.com>
     2
     3        Use Hasher more, remove IntegerHasher, fix hashing-related mistakes
     4        https://bugs.webkit.org/show_bug.cgi?id=224138
     5
     6        Reviewed by Chris Dumez.
     7
     8        * contentextensions/ContentExtensionRule.h:
     9        (WebCore::ContentExtensions::TriggerHash::hash): Use computeHash to
     10        hash all the fields instead of a custom-written algorithm. The custom
     11        algorithm had some magic numbers, repeatedly hashed hashes, and combined
     12        hashes using exclusive or. The new one is almost certainly better.
     13
     14        * contentextensions/Term.h:
     15        (WebCore::ContentExtensions::Term::CharacterSet::hash const):
     16        Use computeHash to hash the boolean and the characters rather than
     17        using intHash and pairIntHash.
     18
     19        * css/parser/CSSParserContext.cpp:
     20        (WebCore::add): Moved the hashing here from the header. Fixed the
     21        mistake where this was using & instead of | and so none of the booleans
     22        were having any effect on the hash value.
     23
     24        * css/parser/CSSParserContext.h: Use WTF_MAKE_STRUCT_FAST_ALLOCATED so
     25        we don't have to say public: explicitly. Also moved all the function
     26        members to the bottom of the struct. This is typically preferred style
     27        for structures as opposed to classes. Since the data members are the
     28        primary interface, they are first, and all function members are secondary
     29        and so they come after.
     30        (WebCore::CSSParserContextHash::hash): Use convertHash instead of
     31        a custom written hash function. The custom written function was combining
     32        hahes using exclusive or, not a best practice, and also had a mistake
     33        where it used & instead of | and so the "bits" local variable was always 0.
     34
     35        * html/FormController.cpp: Use HashTraits instead of WTF::GenericHashTraits.
     36
     37        * platform/encryptedmedia/CDMProxy.h: Removed unneedes includes.
     38
     39        * platform/graphics/Font.cpp: Changed CharacterFallbackMapKey into a
     40        simple struct with no additional function members or static data members.
     41        Changed CharacterFallbackMapKeyHash to use computeHash to calculate the
     42        hash, instead of IntegerHasher. Probably better to hash the pointer of
     43        the AtomString rather than hashing the hash, but either way, we should
     44        have the best implementation for AtomString hashing in the Hasher class.
     45        Added CharacterFallbackMapKeyHashTraits instead of using
     46        SimpleClassHashTraits. Use the value U_SENTINEL for the UChar32 character,
     47        which is the same as the -1 used before, but slightly clearer why it's OK.
     48        (WebCore::Font::systemFallbackFontForCharacter const): Use HashMap::ensure
     49        instead of HashMap::add to make the logic simpler.
     50
     51        * platform/graphics/Font.h: Use bool instead of uint8_t as the base type
     52        for the No/Yes enumeration IsForPlatformFont.
     53
     54        * platform/graphics/FontCache.cpp: Removed unneeded "using namespace WTF",
     55        which is not our best practice, especially given unified builds.
     56        Changed FontPlatformDataCacheKey into a simple struct, removing all the
     57        hash-related member functions. Also used struct-style naming for the
     58        members without an "m_" prefix. Used the type FontFamilyName for the
     59        family name, which means we will use FontCascadeDescription's system
     60        for hashing and comparing family names for equality without having to
     61        remember do to so explicitly. Changed FontPlatformDataCacheKeyHash to
     62        use computeHash. The old version had unnecessarily complex logic to
     63        handle Optional and was unnecessarily hashing hashes.
     64        (WebCore::FontCache::cachedFontPlatformData): Renamed to remove "get"
     65        from the function's name. Also use shorter argument and local variable
     66        names that are single words, and updated since FontPlatformDataCacheKey
     67        is now a struct without a constructor.
     68        (WebCore::FontCache::fontForFamily): Use shorter names.
     69        (WebCore::operator==): To compare two FontCascadeCacheKey objects,
     70        use a simpler constructions, depending on the fact that Vector already
     71        has an == operator and we are using FontFamilyName for the elements
     72        of the vector, which has a correct == operator.
     73        (WebCore::FontCascadeCacheKeyHash::hash): Use computeHash since
     74        the FontFamilyName hashing is now correct, and we can rely on the
     75        way Hasher knows how to iterate a collection.
     76        (WebCore::FontCache::retrieveOrAddCachedFonts): Update since
     77        FontCascadeCacheEntry is now a simple struct. Also use constexpr a bit.
     78        (WebCore::FontCache::invalidate): Use copyToVectorOf<> to simplify the
     79        code that calls fontCacheInvalidated on all the font selectors.
     80
     81        * platform/graphics/FontCache.h: Use "using" instead of "typedef".
     82        Remove FontDescriptionKey::computeHash.
     83        (WebCore::add): An overload of add for Hasher to include a
     84        FontDescriptionKey in a hash, which just lists all the data members.
     85        The old version did a hash of hashes, but that's not needed any more.
     86        Updated FontDescriptionKeyHash to use the Hasher version of ComputeHash.
     87        Added FontFamilyName. Change FontCascadeCacheKey to use a vector of
     88        FontFamilyName instead of AtomString. In FontCascadeCacheEntry, use
     89        WTF_MAKE_STRUCT_FAST_ALLOCATED instead of WTF_MAKE_FAST_ALLOCATED
     90        and also got rid of the unneeeded constructor.
     91        (WebCore::FontCascadeCacheKeyHashTraits::constructDeletedValue):
     92        Use the deleted value of FontDescriptionKey.
     93        (WebCore::FontCascadeCacheKeyHashTraits::isDeletedValue): Ditto.
     94        Renamed getCachedFontPlatformData to just cachedFontPlatformData.
     95
     96        * platform/graphics/FontGenericFamilies.h: Use HashTraits instead of
     97        WTF::GenericHashTraits.
     98
     99        * platform/graphics/FontSelectionAlgorithm.h:
     100        (WebCore::FontSelectionRange::uniqueValue const): Deleted.
     101        (WebCore::add): Add both the minimum and maximum values to the hash
     102        separately instead of combining them. For now, this makes the way
     103        they are hashed a bit inefficient, but that can be re-tightened up by
     104        improving the algorithm of Hasher if we like. Should be fine for our
     105        needs either way.
     106
     107        * platform/graphics/FontTaggedSettings.cpp:
     108        (WebCore::FontFeatureSettings::hash const): Deleted.
     109        (WebCore::FontVariationSettings::hash const): Deleted.
     110
     111        * platform/graphics/FontTaggedSettings.h: Added overloads of the
     112        add(Hasher&) function for std::array<char, 4> and FontTaggedSetting<T>.
     113        Got rid of many uses of pass by reference instead of value for FontTag,
     114        since it fits into a 32-bit register and bth more source code and less
     115        efficient to pass by value.
     116
     117        * platform/graphics/Gradient.cpp: Removed "using WTF::pairIntHash" since
     118        that's now done in the WTF header.
     119        * platform/graphics/cg/GraphicsContextCG.cpp: Ditto. Also removed
     120        "using WTF::GenericHashTraits", which was unhelpful. The GenericHashTraits
     121        template is only really needed when specializing HashTraits, which
     122        already has to be done within the WTF namespace. In all other cases, we
     123        should just use HashTraits instead.
     124
     125        * platform/graphics/cg/SubimageCacheWithTimer.h: Use HashTraits
     126        instead of WTF::GenericHashTraits.
     127
     128        * platform/graphics/cocoa/FontFamilySpecificationCoreText.cpp:
     129        Move the data members to the top of the FontFamilySpecificationKey struct.
     130        Removed unneeded computeHash function and WTF prefix from safeCFEqual.
     131        (WebCore::FontFamilySpecificationKeyHash::hash): Call the Hasher version
     132        of computeHash directly to hash the two items in this structure.
     133
     134        * platform/graphics/cocoa/SystemFontDatabaseCoreText.h:
     135        (WebCore::SystemFontDatabaseCoreText::CascadeListParameters::hash const):
     136        Use computeHash instead of IntegerHasher. Also renamed the hash function
     137        struct from CascadeListParameters::CascadeListParametersHash to
     138        CascadeListParameters::Hash.
     139
     140        * platform/graphics/mac/ComplexTextControllerCoreText.mm:
     141        (WebCore::ComplexTextController::collectComplexTextRunsForCharacters):
     142        Removed now-unneeded WTF prefixes from calls to safeCFEqual.
     143
     144        * rendering/TextAutoSizing.h: Use HashTraits instead of WTF::GenericHashTraits.
     145
     146        * rendering/style/RenderStyle.cpp:
     147        (WebCore::computeFontHash): Use computeHash instead of IntegerHasher.
     148        Still not great that we hash a hash here, but we can improve that later.
     149
     150        * workers/service/ServiceWorkerClientIdentifier.h:
     151        (WebCore::ServiceWorkerClientIdentifier::decode): Removed unneeded
     152        WTFMove on ObjectIdentifier, which are just integers, so move vs. copy
     153        is not an important distinction.
     154        (WebCore::ServiceWorkerClientIdentifier::hash const): Use computeHash
     155        instead of combining intHash with StringHasher::hashMemory. This fixes
     156        two mistakes: one is that there is no need to hash a hash. The second is
     157        that intHash takes a 32-bit integer as its parameter, so high bits
     158        of object identifiers were discarded unnecessarily.
     159
     160        * workers/service/ServiceWorkerContextData.h: Removed unneeded include.
     161
     162        * workers/service/ServiceWorkerGlobalScope.h: Added now-needed include
     163        of URLHash.h, since we removed it from a widely-included header.
     164        * workers/service/context/SWContextManager.h: Ditto.
     165        * workers/service/server/ServiceWorkerThreadProxy.h: Ditto.
     166        * workers/service/server/RegistrationStore.h: Ditto.
     167        * workers/service/server/SWServer.h: Ditto.
     168        * workers/service/server/SWServerToContextConnection.h: Ditto.
     169        * workers/service/server/SWServerWorker.h: Ditto.
     170
    11712021-04-07  Mark Lam  <mark.lam@apple.com>
    2172
  • trunk/Source/WebCore/contentextensions/ContentExtensionRule.h

    r264488 r275650  
    3030#include "ContentExtensionActions.h"
    3131#include "ResourceLoadInfo.h"
     32#include <wtf/Hasher.h>
    3233#include <wtf/text/WTFString.h>
    3334
     
    8990    static unsigned hash(const Trigger& trigger)
    9091    {
    91         unsigned hash = trigger.urlFilterIsCaseSensitive ? 10619863 : 40960001;
    92         if (!trigger.urlFilter.isNull())
    93             hash ^= StringHash::hash(trigger.urlFilter);
    94         hash = WTF::pairIntHash(hash, DefaultHash<ResourceFlags>::hash(trigger.flags));
    95 
    96         for (const String& condition : trigger.conditions)
    97             hash ^= StringHash::hash(condition);
    98 
    99         hash ^= 1 << static_cast<unsigned>(trigger.conditionType);
    100         return hash;
     92        return computeHash(trigger.urlFilterIsCaseSensitive, trigger.urlFilter, trigger.flags, trigger.conditions, trigger.conditionType);
    10193    }
    102 
    10394    static bool equal(const Trigger& a, const Trigger& b)
    10495    {
    10596        return a == b;
    10697    }
    107 
    10898    static const bool safeToCompareToEmptyOrDeleted = false;
    10999};
  • trunk/Source/WebCore/contentextensions/Term.h

    r208179 r275650  
    3333#include <wtf/ASCIICType.h>
    3434#include <wtf/HashMap.h>
     35#include <wtf/Hasher.h>
    3536#include <wtf/Vector.h>
    3637#include <wtf/text/StringBuilder.h>
     
    169170        unsigned hash() const
    170171        {
    171             return WTF::pairIntHash(WTF::pairIntHash(WTF::intHash(m_characters[0]), WTF::intHash(m_characters[1])), m_inverted);
    172         }
     172            return computeHash(m_inverted, m_characters);
     173        }
     174
    173175    private:
    174176        bool m_inverted { false };
    175         uint64_t m_characters[2] { 0, 0 };
     177        std::array<uint64_t, 2> m_characters { 0, 0 };
    176178    };
    177179
  • trunk/Source/WebCore/css/parser/CSSParserContext.cpp

    r274793 r275650  
    138138}
    139139
     140void add(Hasher& hasher, const CSSParserContext& context)
     141{
     142    unsigned bits = context.isHTMLDocument                  << 0
     143        | context.hasDocumentSecurityOrigin                 << 1
     144        | context.isContentOpaque                           << 2
     145        | context.useSystemAppearance                       << 3
     146        | context.aspectRatioEnabled                        << 4
     147        | context.colorContrastEnabled                      << 5
     148        | context.colorFilterEnabled                        << 6
     149        | context.colorMixEnabled                           << 7
     150        | context.constantPropertiesEnabled                 << 8
     151        | context.containmentEnabled                        << 9
     152        | context.cssColor4                                 << 10
     153        | context.deferredCSSParserEnabled                  << 11
     154        | context.individualTransformPropertiesEnabled      << 12
     155#if ENABLE(OVERFLOW_SCROLLING_TOUCH)
     156        | context.legacyOverflowScrollingTouchEnabled       << 13
     157#endif
     158        | context.overscrollBehaviorEnabled                 << 14
     159        | context.relativeColorSyntaxEnabled                << 15
     160        | context.scrollBehaviorEnabled                     << 16
     161        | context.springTimingFunctionEnabled               << 17
     162#if ENABLE(TEXT_AUTOSIZING)
     163        | context.textAutosizingEnabled                     << 18
     164#endif
     165#if ENABLE(CSS_TRANSFORM_STYLE_OPTIMIZED_3D)
     166        | context.transformStyleOptimized3DEnabled          << 19
     167#endif
     168        | context.useLegacyBackgroundSizeShorthandBehavior  << 20
     169        | context.focusVisibleEnabled                       << 21
     170#if ENABLE(ATTACHMENT_ELEMENT)
     171        | context.attachmentEnabled                         << 22
     172#endif
     173        | context.mode                                      << 23; // This is multiple bits, so keep it last.
     174    add(hasher, context.baseURL, context.charset, bits);
     175}
     176
    140177bool CSSParserContext::isPropertyRuntimeDisabled(CSSPropertyID property) const
    141178{
  • trunk/Source/WebCore/css/parser/CSSParserContext.h

    r274793 r275650  
    3131#include "TextEncoding.h"
    3232#include <wtf/HashFunctions.h>
     33#include <wtf/Hasher.h>
    3334#include <wtf/Optional.h>
    3435#include <wtf/URL.h>
    35 #include <wtf/URLHash.h>
    36 #include <wtf/text/StringHash.h>
    3736
    3837namespace WebCore {
     
    4140
    4241struct CSSParserContext {
    43     WTF_MAKE_FAST_ALLOCATED;
    44 public:
    45     CSSParserContext(CSSParserMode, const URL& baseURL = URL());
    46     WEBCORE_EXPORT CSSParserContext(const Document&, const URL& baseURL = URL(), const String& charset = emptyString());
     42    WTF_MAKE_STRUCT_FAST_ALLOCATED;
    4743
    4844    URL baseURL;
     
    5753    bool isContentOpaque { false };
    5854    bool useSystemAppearance { false };
    59 
    60     bool isPropertyRuntimeDisabled(CSSPropertyID) const;
    6155
    6256    // Settings.
     
    9185#endif
    9286
    93     URL completeURL(const String& url) const;
     87    CSSParserContext(CSSParserMode, const URL& baseURL = URL());
     88    WEBCORE_EXPORT CSSParserContext(const Document&, const URL& baseURL = URL(), const String& charset = emptyString());
     89    bool isPropertyRuntimeDisabled(CSSPropertyID) const;
     90    URL completeURL(const String& relativeURL) const;
    9491};
    9592
     
    9794inline bool operator!=(const CSSParserContext& a, const CSSParserContext& b) { return !(a == b); }
    9895
     96void add(Hasher&, const CSSParserContext&);
     97
    9998WEBCORE_EXPORT const CSSParserContext& strictCSSParserContext();
    10099
    101100struct CSSParserContextHash {
    102     static unsigned hash(const CSSParserContext& key)
    103     {
    104         // FIXME: Convert this to use WTF::Hasher.
    105 
    106         unsigned hash = 0;
    107         if (!key.baseURL.isNull())
    108             hash ^= WTF::URLHash::hash(key.baseURL);
    109         if (!key.charset.isEmpty())
    110             hash ^= StringHash::hash(key.charset);
    111        
    112         unsigned bits = key.isHTMLDocument                  << 0
    113             & key.hasDocumentSecurityOrigin                 << 1
    114             & key.isContentOpaque                           << 2
    115             & key.useSystemAppearance                       << 3
    116             & key.aspectRatioEnabled                        << 4
    117             & key.colorContrastEnabled                      << 5
    118             & key.colorFilterEnabled                        << 6
    119             & key.colorMixEnabled                           << 7
    120             & key.constantPropertiesEnabled                 << 8
    121             & key.containmentEnabled                        << 9
    122             & key.cssColor4                                 << 10
    123             & key.deferredCSSParserEnabled                  << 11
    124             & key.individualTransformPropertiesEnabled      << 12
    125 #if ENABLE(OVERFLOW_SCROLLING_TOUCH)
    126             & key.legacyOverflowScrollingTouchEnabled       << 13
    127 #endif
    128             & key.overscrollBehaviorEnabled                 << 14
    129             & key.relativeColorSyntaxEnabled                << 15
    130             & key.scrollBehaviorEnabled                     << 16
    131             & key.springTimingFunctionEnabled               << 17
    132 #if ENABLE(TEXT_AUTOSIZING)
    133             & key.textAutosizingEnabled                     << 18
    134 #endif
    135 #if ENABLE(CSS_TRANSFORM_STYLE_OPTIMIZED_3D)
    136             & key.transformStyleOptimized3DEnabled          << 19
    137 #endif
    138             & key.useLegacyBackgroundSizeShorthandBehavior  << 20
    139             & key.focusVisibleEnabled                       << 21
    140 #if ENABLE(ATTACHMENT_ELEMENT)
    141             & key.attachmentEnabled                         << 22
    142 #endif
    143             & key.mode                                      << 23; // Keep this last.
    144         hash ^= WTF::intHash(bits);
    145         return hash;
    146     }
    147     static bool equal(const CSSParserContext& a, const CSSParserContext& b)
    148     {
    149         return a == b;
    150     }
     101    static unsigned hash(const CSSParserContext& context) { return computeHash(context); }
     102    static bool equal(const CSSParserContext& a, const CSSParserContext& b) { return a == b; }
    151103    static const bool safeToCompareToEmptyOrDeleted = false;
    152104};
     
    155107
    156108namespace WTF {
     109
    157110template<> struct HashTraits<WebCore::CSSParserContext> : GenericHashTraits<WebCore::CSSParserContext> {
    158111    static void constructDeletedValue(WebCore::CSSParserContext& slot) { new (NotNull, &slot.baseURL) URL(WTF::HashTableDeletedValue); }
  • trunk/Source/WebCore/html/FormController.cpp

    r261013 r275650  
    162162}
    163163
    164 struct FormElementKeyHashTraits : WTF::GenericHashTraits<FormElementKey> {
     164struct FormElementKeyHashTraits : HashTraits<FormElementKey> {
    165165    static void constructDeletedValue(FormElementKey& slot) { new (NotNull, &slot) FormElementKey(WTF::HashTableDeletedValue); }
    166166    static bool isDeletedValue(const FormElementKey& value) { return value.isHashTableDeletedValue(); }
  • trunk/Source/WebCore/platform/encryptedmedia/CDMProxy.h

    r275599 r275650  
    3737#include <wtf/BoxPtr.h>
    3838#include <wtf/Condition.h>
    39 #include <wtf/VectorHash.h>
    40 #include <wtf/WeakHashSet.h>
    4139
    4240#if ENABLE(THUNDER)
     
    208206
    209207class CDMInstanceSessionProxy : public CDMInstanceSession, public CanMakeWeakPtr<CDMInstanceSessionProxy, WeakPtrFactoryInitialization::Eager> {
    210 public:
    211 
    212208protected:
    213209    CDMInstanceSessionProxy(CDMInstanceProxy&);
  • trunk/Source/WebCore/platform/graphics/Font.cpp

    r272783 r275650  
    536536#endif
    537537
    538 class CharacterFallbackMapKey {
    539 public:
    540     CharacterFallbackMapKey()
    541     {
    542     }
    543 
    544     CharacterFallbackMapKey(const AtomString& locale, UChar32 character, IsForPlatformFont isForPlatformFont)
    545         : locale(locale)
    546         , character(character)
    547         , isForPlatformFont(isForPlatformFont == IsForPlatformFont::Yes)
    548     {
    549     }
    550 
    551     CharacterFallbackMapKey(WTF::HashTableDeletedValueType)
    552         : character(-1)
    553     {
    554     }
    555 
    556     bool isHashTableDeletedValue() const { return character == -1; }
    557 
    558     bool operator==(const CharacterFallbackMapKey& other) const
    559     {
    560         return locale == other.locale && character == other.character && isForPlatformFont == other.isForPlatformFont;
    561     }
    562 
    563     static const bool emptyValueIsZero = true;
    564 
    565 private:
    566     friend struct CharacterFallbackMapKeyHash;
    567 
     538struct CharacterFallbackMapKey {
    568539    AtomString locale;
    569540    UChar32 character { 0 };
     
    571542};
    572543
     544inline bool operator==(const CharacterFallbackMapKey& a, const CharacterFallbackMapKey& b)
     545{
     546    return a.locale == b.locale && a.character == b.character && a.isForPlatformFont == b.isForPlatformFont;
     547}
     548
    573549struct CharacterFallbackMapKeyHash {
    574     static unsigned hash(const CharacterFallbackMapKey& key)
    575     {
    576         IntegerHasher hasher;
    577         hasher.add(key.character);
    578         hasher.add(key.isForPlatformFont);
    579         hasher.add(key.locale.existingHash());
    580         return hasher.hash();
    581     }
    582 
    583     static bool equal(const CharacterFallbackMapKey& a, const CharacterFallbackMapKey& b)
    584     {
    585         return a == b;
    586     }
    587 
     550    static unsigned hash(const CharacterFallbackMapKey& key) { return computeHash(key.locale, key.character, key.isForPlatformFont); }
     551    static bool equal(const CharacterFallbackMapKey& a, const CharacterFallbackMapKey& b) { return a == b; }
    588552    static const bool safeToCompareToEmptyOrDeleted = true;
    589553};
    590554
     555struct CharacterFallbackMapKeyHashTraits : SimpleClassHashTraits<CharacterFallbackMapKey> {
     556    static void constructDeletedValue(CharacterFallbackMapKey& slot) { new (NotNull, &slot) CharacterFallbackMapKey { { }, U_SENTINEL, { } }; }
     557    static bool isDeletedValue(const CharacterFallbackMapKey& key) { return key.character == U_SENTINEL; }
     558};
     559
    591560// Fonts are not ref'd to avoid cycles.
    592 // FIXME: Shouldn't these be WeakPtrs?
    593 typedef HashMap<CharacterFallbackMapKey, Font*, CharacterFallbackMapKeyHash, WTF::SimpleClassHashTraits<CharacterFallbackMapKey>> CharacterFallbackMap;
    594 typedef HashMap<const Font*, CharacterFallbackMap> SystemFallbackCache;
     561// FIXME: Consider changing these maps to use WeakPtr instead of raw pointers.
     562using CharacterFallbackMap = HashMap<CharacterFallbackMapKey, Font*, CharacterFallbackMapKeyHash, CharacterFallbackMapKeyHashTraits>;
     563using SystemFallbackCache = HashMap<const Font*, CharacterFallbackMap>;
    595564
    596565static SystemFallbackCache& systemFallbackCache()
     
    609578    }
    610579
    611     auto key = CharacterFallbackMapKey(description.computedLocale(), character, isForPlatformFont);
    612     auto characterAddResult = fontAddResult.iterator->value.add(WTFMove(key), nullptr);
    613 
    614     Font*& fallbackFont = characterAddResult.iterator->value;
    615 
    616     if (!fallbackFont) {
     580    auto key = CharacterFallbackMapKey { description.computedLocale(), character, isForPlatformFont != IsForPlatformFont::No };
     581    return fontAddResult.iterator->value.ensure(WTFMove(key), [&] {
    617582        UChar codeUnits[2];
    618583        unsigned codeUnitsLength;
     
    625590            codeUnitsLength = 2;
    626591        }
    627 
    628         fallbackFont = FontCache::singleton().systemFallbackForCharacters(description, this, isForPlatformFont, FontCache::PreferColoredFont::No, codeUnits, codeUnitsLength).get();
    629         if (fallbackFont)
    630             fallbackFont->m_isUsedInSystemFallbackCache = true;
    631     }
    632 
    633     return fallbackFont;
     592        auto font = FontCache::singleton().systemFallbackForCharacters(description, this, isForPlatformFont, FontCache::PreferColoredFont::No, codeUnits, codeUnitsLength).get();
     593        if (font)
     594            font->m_isUsedInSystemFallbackCache = true;
     595        return font;
     596    }).iterator->value;
    634597}
    635598
  • trunk/Source/WebCore/platform/graphics/Font.h

    r273121 r275650  
    6565enum FontVariant { AutoVariant, NormalVariant, SmallCapsVariant, EmphasisMarkVariant, BrokenIdeographVariant };
    6666enum Pitch { UnknownPitch, FixedPitch, VariablePitch };
    67 enum class IsForPlatformFont : uint8_t { No, Yes };
     67enum class IsForPlatformFont : bool { No, Yes };
    6868
    6969#if USE(CORE_TEXT)
  • trunk/Source/WebCore/platform/graphics/FontCache.cpp

    r275420 r275650  
    11/*
    2  * Copyright (C) 2006, 2008, 2013 Apple Inc. All rights reserved.
     2 * Copyright (C) 2006-2021 Apple Inc. All rights reserved.
    33 * Copyright (C) 2007 Nicholas Shanks <webkit@nickshanks.com>
    44 *
     
    4848
    4949namespace WebCore {
    50 using namespace WTF;
     50
     51FontFamilyName::FontFamilyName() = default;
     52
     53inline FontFamilyName::FontFamilyName(const AtomString& name)
     54    : m_name { name }
     55{
     56}
     57
     58inline const AtomString& FontFamilyName::string() const
     59{
     60    return m_name;
     61}
     62
     63inline void add(Hasher& hasher, const FontFamilyName& name)
     64{
     65    // FIXME: Would be better to hash the characters in the name instead of hashing a hash.
     66    if (!name.string().isNull())
     67        add(hasher, FontCascadeDescription::familyNameHash(name.string()));
     68}
     69
     70inline bool operator==(const FontFamilyName& a, const FontFamilyName& b)
     71{
     72    return (a.string().isNull() || b.string().isNull()) ? a.string() == b.string() : FontCascadeDescription::familyNamesAreEqual(a.string(), b.string());
     73}
     74
     75inline bool operator!=(const FontFamilyName& a, const FontFamilyName& b)
     76{
     77    return !(a == b);
     78}
    5179
    5280struct FontPlatformDataCacheKey {
    53     WTF_MAKE_FAST_ALLOCATED;
    54 public:
    55     FontPlatformDataCacheKey() { }
    56     FontPlatformDataCacheKey(const AtomString& family, const FontDescription& description, const FontFeatureSettings* fontFaceFeatures, FontSelectionSpecifiedCapabilities fontFaceCapabilities)
    57         : m_fontDescriptionKey(description)
    58         , m_family(family)
    59         , m_fontFaceFeatures(fontFaceFeatures ? *fontFaceFeatures : FontFeatureSettings())
    60         , m_fontFaceCapabilities(fontFaceCapabilities)
    61     { }
    62 
    63     explicit FontPlatformDataCacheKey(HashTableDeletedValueType t)
    64         : m_fontDescriptionKey(t)
    65     { }
    66 
    67     bool isHashTableDeletedValue() const { return m_fontDescriptionKey.isHashTableDeletedValue(); }
    68     bool operator==(const FontPlatformDataCacheKey& other) const
    69     {
    70         if (m_fontDescriptionKey != other.m_fontDescriptionKey
    71             || m_fontFaceFeatures != other.m_fontFaceFeatures
    72             || m_fontFaceCapabilities != other.m_fontFaceCapabilities)
    73             return false;
    74         if (m_family.impl() == other.m_family.impl())
    75             return true;
    76         if (m_family.isNull() || other.m_family.isNull())
    77             return false;
    78         return FontCascadeDescription::familyNamesAreEqual(m_family, other.m_family);
    79     }
    80 
    81     FontDescriptionKey m_fontDescriptionKey;
    82     AtomString m_family;
    83     FontFeatureSettings m_fontFaceFeatures;
    84     FontSelectionSpecifiedCapabilities m_fontFaceCapabilities;
     81    FontDescriptionKey descriptionKey;
     82    FontFamilyName family;
     83    FontFeatureSettings features;
     84    FontSelectionSpecifiedCapabilities capabilities;
    8585};
    8686
     87static bool operator==(const FontPlatformDataCacheKey& a, const FontPlatformDataCacheKey& b)
     88{
     89    return a.descriptionKey == b.descriptionKey && a.family == b.family && a.features == b.features && a.capabilities == b.capabilities;
     90}
     91
    8792struct FontPlatformDataCacheKeyHash {
    88     static unsigned hash(const FontPlatformDataCacheKey& fontKey)
    89     {
    90         IntegerHasher hasher;
    91         hasher.add(FontCascadeDescription::familyNameHash(fontKey.m_family));
    92         hasher.add(fontKey.m_fontDescriptionKey.computeHash());
    93         hasher.add(fontKey.m_fontFaceFeatures.hash());
    94         if (auto weight = fontKey.m_fontFaceCapabilities.weight)
    95             hasher.add(weight->uniqueValue());
    96         else
    97             hasher.add(std::numeric_limits<unsigned>::max());
    98         if (auto width = fontKey.m_fontFaceCapabilities.weight)
    99             hasher.add(width->uniqueValue());
    100         else
    101             hasher.add(std::numeric_limits<unsigned>::max());
    102         if (auto slope = fontKey.m_fontFaceCapabilities.weight)
    103             hasher.add(slope->uniqueValue());
    104         else
    105             hasher.add(std::numeric_limits<unsigned>::max());
    106         return hasher.hash();
    107     }
    108 
    109     static bool equal(const FontPlatformDataCacheKey& a, const FontPlatformDataCacheKey& b)
    110     {
    111         return a == b;
    112     }
    113 
     93    static unsigned hash(const FontPlatformDataCacheKey& key) { return computeHash(key.descriptionKey, key.family, key.features, key.capabilities.tied()); }
     94    static bool equal(const FontPlatformDataCacheKey& a, const FontPlatformDataCacheKey& b) { return a == b; }
    11495    static constexpr bool safeToCompareToEmptyOrDeleted = true;
    11596};
     
    11798struct FontPlatformDataCacheKeyHashTraits : public SimpleClassHashTraits<FontPlatformDataCacheKey> {
    11899    static constexpr bool emptyValueIsZero = false;
     100    static void constructDeletedValue(FontPlatformDataCacheKey& slot)
     101    {
     102        new (NotNull, &slot) FontPlatformDataCacheKey { FontDescriptionKey { WTF::HashTableDeletedValue }, { }, { }, { } };
     103    }
     104    static bool isDeletedValue(const FontPlatformDataCacheKey& key)
     105    {
     106        return key.descriptionKey.isHashTableDeletedValue();
     107    }
    119108};
    120109
    121110struct FontDataCacheKeyHash {
    122     static unsigned hash(const FontPlatformData& platformData)
    123     {
    124         return platformData.hash();
    125     }
    126 
    127     static bool equal(const FontPlatformData& a, const FontPlatformData& b)
    128     {
    129         return a == b;
    130     }
    131 
     111    static unsigned hash(const FontPlatformData& data) { return data.hash(); }
     112    static bool equal(const FontPlatformData& a, const FontPlatformData& b) { return a == b; }
    132113    static constexpr bool safeToCompareToEmptyOrDeleted = true;
    133114};
     
    142123    static void constructDeletedValue(FontPlatformData& slot)
    143124    {
    144         new (NotNull, &slot) FontPlatformData(HashTableDeletedValue);
     125        new (NotNull, &slot) FontPlatformData(WTF::HashTableDeletedValue);
    145126    }
    146127    static bool isDeletedValue(const FontPlatformData& value)
     
    178159}
    179160
    180 FontCache::~FontCache() = default;
    181 
    182161FontCache::FontCache()
    183162    : m_purgeTimer(*this, &FontCache::purgeInactiveFontDataIfNeeded)
     
    185164{
    186165}
     166
     167FontCache::~FontCache() = default;
    187168
    188169Optional<ASCIILiteral> FontCache::alternateFamilyName(const String& familyName)
     
    226207}
    227208
    228 FontPlatformData* FontCache::getCachedFontPlatformData(const FontDescription& fontDescription, const String& passedFamilyName,
    229     const FontFeatureSettings* fontFaceFeatures, FontSelectionSpecifiedCapabilities fontFaceCapabilities, bool checkingAlternateName)
     209FontPlatformData* FontCache::cachedFontPlatformData(const FontDescription& fontDescription, const String& passedFamilyName,
     210    const FontFeatureSettings* features, FontSelectionSpecifiedCapabilities capabilities, bool checkingAlternateName)
    230211{
    231212#if PLATFORM(IOS_FAMILY)
     
    247228    });
    248229
    249     FontPlatformDataCacheKey key(familyName, fontDescription, fontFaceFeatures, fontFaceCapabilities);
     230    FontPlatformDataCacheKey key { fontDescription, { familyName }, features ? *features : FontFeatureSettings { }, capabilities };
    250231
    251232    auto addResult = m_fontDataCaches->platformData.add(key, nullptr);
    252233    FontPlatformDataCache::iterator it = addResult.iterator;
    253234    if (addResult.isNewEntry) {
    254         it->value = createFontPlatformData(fontDescription, familyName, fontFaceFeatures, fontFaceCapabilities);
    255 
     235        it->value = createFontPlatformData(fontDescription, familyName, features, capabilities);
    256236        if (!it->value && !checkingAlternateName) {
    257             // We were unable to find a font.  We have a small set of fonts that we alias to other names,
    258             // e.g., Arial/Helvetica, Courier/Courier New, etc.  Try looking up the font under the aliased name.
     237            // We were unable to find a font. We have a small set of fonts that we alias to other names,
     238            // e.g., Arial/Helvetica, Courier/Courier New, etc. Try looking up the font under the aliased name.
    259239            if (auto alternateName = alternateFamilyName(familyName)) {
    260                 auto* fontPlatformDataForAlternateName = getCachedFontPlatformData(fontDescription, *alternateName, fontFaceFeatures, fontFaceCapabilities, true);
    261                 // Lookup the key in the hash table again as the previous iterator may have
    262                 // been invalidated by the recursive call to getCachedFontPlatformData().
     240                auto* alternateData = cachedFontPlatformData(fontDescription, *alternateName, features, capabilities, true);
     241                // Look up the key in the hash table again as the previous iterator may have
     242                // been invalidated by the recursive call to cachedFontPlatformData().
    263243                it = m_fontDataCaches->platformData.find(key);
    264244                ASSERT(it != m_fontDataCaches->platformData.end());
    265                 if (fontPlatformDataForAlternateName)
    266                     it->value = makeUnique<FontPlatformData>(*fontPlatformDataForAlternateName);
     245                if (alternateData)
     246                    it->value = makeUnique<FontPlatformData>(*alternateData);
    267247            }
    268248        }
     
    283263const unsigned cTargetUnderMemoryPressureInactiveFontData = 30;
    284264
    285 RefPtr<Font> FontCache::fontForFamily(const FontDescription& fontDescription, const String& family, const FontFeatureSettings* fontFaceFeatures, FontSelectionSpecifiedCapabilities fontFaceCapabilities, bool checkingAlternateName)
     265RefPtr<Font> FontCache::fontForFamily(const FontDescription& fontDescription, const String& family, const FontFeatureSettings* features, FontSelectionSpecifiedCapabilities capabilities, bool checkingAlternateName)
    286266{
    287267    if (!m_purgeTimer.isActive())
    288268        m_purgeTimer.startOneShot(0_s);
    289269
    290     if (auto* platformData = getCachedFontPlatformData(fontDescription, family, fontFaceFeatures, fontFaceCapabilities, checkingAlternateName))
     270    if (auto* platformData = cachedFontPlatformData(fontDescription, family, features, capabilities, checkingAlternateName))
    291271        return fontForPlatformData(*platformData);
    292272
     
    376356bool operator==(const FontCascadeCacheKey& a, const FontCascadeCacheKey& b)
    377357{
    378     if (a.fontDescriptionKey != b.fontDescriptionKey)
    379         return false;
    380     if (a.fontSelectorId != b.fontSelectorId || a.fontSelectorVersion != b.fontSelectorVersion)
    381         return false;
    382     unsigned size = a.families.size();
    383     if (size != b.families.size())
    384         return false;
    385     for (unsigned i = 0; i < size; ++i) {
    386         if (!FontCascadeDescription::familyNamesAreEqual(a.families[i], b.families[i]))
    387             return false;
    388     }
    389     return true;
     358    return a.fontDescriptionKey == b.fontDescriptionKey
     359        && a.fontSelectorId == b.fontSelectorId
     360        && a.fontSelectorVersion == b.fontSelectorVersion
     361        && a.families == b.families;
    390362}
    391363
    392364unsigned FontCascadeCacheKeyHash::hash(const FontCascadeCacheKey& key)
    393365{
    394     // FIXME: Should hash the key and the family name characters rather than making a hash out of other hashes.
    395     Hasher hasher;
    396     add(hasher, key.fontDescriptionKey.computeHash());
    397     add(hasher, key.fontSelectorId);
    398     add(hasher, key.fontSelectorVersion);
    399     for (auto& family : key.families)
    400         add(hasher, family.isNull() ? 0 : WebCore::FontCascadeDescription::familyNameHash(family));
    401     return hasher.hash();
     366    return computeHash(key.fontDescriptionKey, key.fontSelectorId, key.fontSelectorVersion, key.families);
    402367}
    403368
     
    457422
    458423    auto& newEntry = addResult.iterator->value;
    459     newEntry = makeUnique<FontCascadeCacheEntry>(WTFMove(key), FontCascadeFonts::create(WTFMove(fontSelector)));
     424    newEntry = makeUnique<FontCascadeCacheEntry>(FontCascadeCacheEntry { WTFMove(key), FontCascadeFonts::create(WTFMove(fontSelector)) });
    460425    Ref<FontCascadeFonts> glyphs = newEntry->fonts.get();
    461426
    462     static const unsigned unreferencedPruneInterval = 50;
    463     static const int maximumEntries = 400;
     427    static constexpr unsigned unreferencedPruneInterval = 50;
     428    static constexpr int maximumEntries = 400;
    464429    static unsigned pruneCounter;
    465430    // Referenced FontCascadeFonts would exist anyway so pruning them saves little memory.
     
    516481    invalidateFontCascadeCache();
    517482
    518     m_generation++;
    519 
    520     Vector<Ref<FontSelector>> clients;
    521     clients.reserveInitialCapacity(m_clients.size());
    522     for (auto it = m_clients.begin(), end = m_clients.end(); it != end; ++it)
    523         clients.uncheckedAppend(**it);
    524 
    525     for (unsigned i = 0; i < clients.size(); ++i)
    526         clients[i]->fontCacheInvalidated();
     483    ++m_generation;
     484
     485    for (auto& client : copyToVectorOf<RefPtr<FontSelector>>(m_clients))
     486        client->fontCacheInvalidated();
    527487
    528488    purgeInactiveFontData();
  • trunk/Source/WebCore/platform/graphics/FontCache.h

    r275420 r275650  
    11/*
    2  * Copyright (C) 2006, 2008 Apple Inc. All rights reserved.
     2 * Copyright (C) 2006-2021 Apple Inc. All rights reserved.
    33 * Copyright (C) 2007-2008 Torch Mobile, Inc.
    44 *
     
    88 *
    99 * 1.  Redistributions of source code must retain the above copyright
    10  *     notice, this list of conditions and the following disclaimer. 
     10 *     notice, this list of conditions and the following disclaimer.
    1111 * 2.  Redistributions in binary form must reproduce the above copyright
    1212 *     notice, this list of conditions and the following disclaimer in the
    13  *     documentation and/or other materials provided with the distribution. 
     13 *     documentation and/or other materials provided with the distribution.
    1414 * 3.  Neither the name of Apple Inc. ("Apple") nor the names of
    1515 *     its contributors may be used to endorse or promote products derived
    16  *     from this software without specific prior written permission. 
     16 *     from this software without specific prior written permission.
    1717 *
    1818 * THIS SOFTWARE IS PROVIDED BY APPLE AND ITS CONTRIBUTORS "AS IS" AND ANY
     
    6565namespace WebCore {
    6666
     67class Font;
    6768class FontCascade;
    6869class OpenTypeVerticalData;
    69 class Font;
    70 enum class IsForPlatformFont : uint8_t;
    71 
    72 #if PLATFORM(WIN)
    73 #if USE(IMLANG_FONT_LINK2)
    74 typedef IMLangFontLink2 IMLangFontLinkType;
    75 #else
    76 typedef IMLangFontLink IMLangFontLinkType;
    77 #endif
     70
     71enum class IsForPlatformFont : bool;
     72
     73#if PLATFORM(WIN) && USE(IMLANG_FONT_LINK2)
     74using IMLangFontLinkType = IMLangFontLink2;
     75#endif
     76
     77#if PLATFORM(WIN) && !USE(IMLANG_FONT_LINK2)
     78using IMLangFontLinkType = IMLangFontLink;
    7879#endif
    7980
     
    113114    bool isHashTableDeletedValue() const { return m_isDeletedValue; }
    114115
    115     inline unsigned computeHash() const
    116     {
    117         Hasher hasher;
    118         add(hasher, m_size);
    119         add(hasher, m_fontSelectionRequest.tied());
    120         add(hasher, m_locale.existingHash());
    121         add(hasher, m_flags);
    122         add(hasher, m_featureSettings.hash());
    123         add(hasher, m_variationSettings.hash());
    124         return hasher.hash();
    125     }
     116    friend void add(Hasher&, const FontDescriptionKey&);
    126117
    127118private:
     
    166157};
    167158
     159inline void add(Hasher& hasher, const FontDescriptionKey& key)
     160{
     161    add(hasher, key.m_size, key.m_fontSelectionRequest, key.m_flags, key.m_locale, key.m_featureSettings, key.m_variationSettings);
     162}
     163
    168164struct FontDescriptionKeyHash {
    169     static unsigned hash(const FontDescriptionKey& key)
    170     {
    171         return key.computeHash();
    172     }
    173 
    174     static bool equal(const FontDescriptionKey& a, const FontDescriptionKey& b)
    175     {
    176         return a == b;
    177     }
    178 
    179     static const bool safeToCompareToEmptyOrDeleted = true;
    180 };
     165    static unsigned hash(const FontDescriptionKey& key) { return computeHash(key); }
     166    static bool equal(const FontDescriptionKey& a, const FontDescriptionKey& b) { return a == b; }
     167    static constexpr bool safeToCompareToEmptyOrDeleted = true;
     168};
     169
     170// This class holds the name of a font family, and defines hashing and == of this name to
     171// use the rules for font family names instead of using straight string comparison.
     172class FontFamilyName {
     173public:
     174    FontFamilyName();
     175    FontFamilyName(const AtomString&);
     176    const AtomString& string() const;
     177    friend void add(Hasher&, const FontFamilyName&);
     178
     179private:
     180    AtomString m_name;
     181};
     182
     183bool operator==(const FontFamilyName&, const FontFamilyName&);
     184bool operator!=(const FontFamilyName&, const FontFamilyName&);
    181185
    182186struct FontCascadeCacheKey {
    183187    FontDescriptionKey fontDescriptionKey; // Shared with the lower level FontCache (caching Font objects)
    184     Vector<AtomString, 3> families;
     188    Vector<FontFamilyName, 3> families;
    185189    unsigned fontSelectorId;
    186190    unsigned fontSelectorVersion;
     
    190194
    191195struct FontCascadeCacheEntry {
    192     WTF_MAKE_FAST_ALLOCATED;
    193 public:
    194     FontCascadeCacheEntry(FontCascadeCacheKey&& key, Ref<FontCascadeFonts>&& fonts)
    195         : key(WTFMove(key))
    196         , fonts(WTFMove(fonts))
    197     { }
     196    WTF_MAKE_STRUCT_FAST_ALLOCATED;
     197
    198198    FontCascadeCacheKey key;
    199199    Ref<FontCascadeFonts> fonts;
     
    201201
    202202struct FontCascadeCacheKeyHash {
    203     static unsigned hash(const WebCore::FontCascadeCacheKey&);
    204     static bool equal(const WebCore::FontCascadeCacheKey& a, const WebCore::FontCascadeCacheKey& b) { return a == b; }
    205     static const bool safeToCompareToEmptyOrDeleted = false;
    206 };
    207 
    208 struct FontCascadeCacheKeyHashTraits : WTF::GenericHashTraits<WebCore::FontCascadeCacheKey> {
    209     static WebCore::FontCascadeCacheKey emptyValue() { return { }; }
    210     static void constructDeletedValue(WebCore::FontCascadeCacheKey& slot) { slot.fontSelectorId = std::numeric_limits<unsigned>::max(); }
    211     static bool isDeletedValue(const WebCore::FontCascadeCacheKey& slot) { return slot.fontSelectorId == std::numeric_limits<unsigned>::max(); }
     203    static unsigned hash(const FontCascadeCacheKey&);
     204    static bool equal(const FontCascadeCacheKey& a, const FontCascadeCacheKey& b) { return a == b; }
     205    static constexpr bool safeToCompareToEmptyOrDeleted = false;
     206};
     207
     208struct FontCascadeCacheKeyHashTraits : HashTraits<FontCascadeCacheKey> {
     209    static FontCascadeCacheKey emptyValue() { return { }; }
     210    static void constructDeletedValue(FontCascadeCacheKey& slot) { new (NotNull, &slot) FontCascadeCacheKey { FontDescriptionKey { WTF::HashTableDeletedValue }, { }, { }, { } }; }
     211    static bool isDeletedValue(const FontCascadeCacheKey& key) { return key.fontDescriptionKey.isHashTableDeletedValue(); }
    212212};
    213213
     
    226226
    227227    // These methods are implemented by the platform.
    228     enum class PreferColoredFont : uint8_t { No, Yes };
     228    enum class PreferColoredFont : bool { No, Yes };
    229229    RefPtr<Font> systemFallbackForCharacters(const FontDescription&, const Font* originalFontData, IsForPlatformFont, PreferColoredFont, const UChar* characters, unsigned length);
    230230    Vector<String> systemFontFamilies();
     
    236236    WEBCORE_EXPORT static void setFontAllowlist(const Vector<String>&);
    237237#endif
     238
    238239#if PLATFORM(WIN)
    239240    IMLangFontLinkType* getFontLinkInterface();
     
    302303    Ref<FontCascadeFonts> retrieveOrAddCachedFonts(const FontCascadeDescription&, RefPtr<FontSelector>&&);
    303304
    304     // FIXME: This method should eventually be removed.
    305     FontPlatformData* getCachedFontPlatformData(const FontDescription&, const String& family, const FontFeatureSettings* fontFaceFeatures = nullptr, FontSelectionSpecifiedCapabilities fontFaceCapabilities = { }, bool checkingAlternateName = false);
    306 
    307     // These methods are implemented by each platform.
    308     WEBCORE_EXPORT std::unique_ptr<FontPlatformData> createFontPlatformData(const FontDescription&, const AtomString& family, const FontFeatureSettings* fontFaceFeatures, FontSelectionSpecifiedCapabilities fontFaceCapabilities);
     305    FontPlatformData* cachedFontPlatformData(const FontDescription&, const String& family, const FontFeatureSettings* = nullptr, FontSelectionSpecifiedCapabilities = { }, bool checkingAlternateName = false);
     306
     307    // These functions are implemented by each platform (unclear which functions this comment applies to).
     308    WEBCORE_EXPORT std::unique_ptr<FontPlatformData> createFontPlatformData(const FontDescription&, const AtomString& family, const FontFeatureSettings*, FontSelectionSpecifiedCapabilities);
    309309   
    310310    static Optional<ASCIILiteral> alternateFamilyName(const String&);
     
    333333    friend class ComplexTextController;
    334334#endif
     335
    335336    friend class Font;
    336337};
     
    348349
    349350#endif
    350 
    351351
    352352inline bool FontCache::PrewarmInformation::isEmpty() const
  • trunk/Source/WebCore/platform/graphics/FontGenericFamilies.h

    r274143 r275650  
    3636// UScriptCode uses -1 and 0 for UScriptInvalidCode and UScriptCommon.
    3737// We need to use -2 and -3 for empty value and deleted value.
    38 struct UScriptCodeHashTraits : WTF::GenericHashTraits<int> {
     38struct UScriptCodeHashTraits : HashTraits<int> {
    3939    static const bool emptyValueIsZero = false;
    4040    static int emptyValue() { return -2; }
  • trunk/Source/WebCore/platform/graphics/FontSelectionAlgorithm.h

    r254295 r275650  
    292292}
    293293
     294inline void add(Hasher& hasher, const FontSelectionValue& value)
     295{
     296    add(hasher, value.rawValue());
     297}
     298
    294299// [Inclusive, Inclusive]
    295300struct FontSelectionRange {
     
    335340    }
    336341
    337     // FIXME: This name is not so great. Move this into the add function below
    338     // once we move FontPlatformDataCacheKeyHash from IntegerHasher to Hasher,
    339     // and then it doesn't need to have a name.
    340     constexpr uint32_t uniqueValue() const
    341     {
    342         return minimum.rawValue() << 16 | maximum.rawValue();
    343     }
    344 
    345342    template<class Encoder>
    346343    void encode(Encoder&) const;
     
    378375inline void add(Hasher& hasher, const FontSelectionRange& range)
    379376{
    380     add(hasher, range.uniqueValue());
     377    add(hasher, range.minimum, range.maximum);
    381378}
    382379
     
    386383    Value weight;
    387384    Value width;
     385
    388386    // FIXME: We are using an optional here to be able to distinguish between an explicit
    389387    // or implicit slope (for "italic" and "oblique") and the "normal" value which has no
  • trunk/Source/WebCore/platform/graphics/FontTaggedSettings.cpp

    r266686 r275650  
    2828#include "FontTaggedSettings.h"
    2929
    30 #include <wtf/Hasher.h>
    31 #include <wtf/text/AtomStringHash.h>
    3230#include <wtf/text/TextStream.h>
    3331
    3432namespace WebCore {
    3533
    36 template <>
    37 unsigned FontFeatureSettings::hash() const
    38 {
    39     IntegerHasher hasher;
    40     for (auto& feature : m_list) {
    41         hasher.add(FourCharacterTagHash::hash(feature.tag()));
    42         hasher.add(feature.value());
    43     }
    44     return hasher.hash();
    45 }
    46 
    47 template <>
    48 unsigned FontVariationSettings::hash() const
    49 {
    50     static_assert(sizeof(float) == sizeof(int), "IntegerHasher needs to accept floats too");
    51     union {
    52         float f;
    53         int i;
    54     } floatToInt;
    55 
    56     IntegerHasher hasher;
    57     for (auto& variation : m_list) {
    58         hasher.add(FourCharacterTagHash::hash(variation.tag()));
    59         floatToInt.f = variation.value();
    60         hasher.add(floatToInt.i);
    61     }
    62     return hasher.hash();
    63 }
    64 
    65 TextStream& operator<<(TextStream& ts, const FontVariationSettings& item)
     34TextStream& operator<<(TextStream& ts, const FontTaggedSettings<float>& item)
    6635{
    6736    for (unsigned i = 0; i < item.size(); ++i) {
  • trunk/Source/WebCore/platform/graphics/FontTaggedSettings.h

    r266686 r275650  
    3737namespace WebCore {
    3838
    39 typedef std::array<char, 4> FontTag;
    40 
    41 inline FontTag fontFeatureTag(const char arr[4]) { return {{ arr[0], arr[1], arr[2], arr[3] }}; }
     39using FontTag = std::array<char, 4>;
     40
     41inline FontTag fontFeatureTag(const char characters[4]) { return {{ characters[0], characters[1], characters[2], characters[3] }}; }
     42
     43inline void add(Hasher& hasher, std::array<char, 4> array)
     44{
     45    uint32_t integer = (static_cast<uint8_t>(array[0]) << 24) | (static_cast<uint8_t>(array[1]) << 16) | (static_cast<uint8_t>(array[2]) << 8) | static_cast<uint8_t>(array[3]);
     46    add(hasher, integer);
     47}
    4248
    4349struct FourCharacterTagHash {
    44     static unsigned hash(const FontTag& characters) { return (characters[0] << 24) | (characters[1] << 16) | (characters[2] << 8) | characters[3]; }
    45     static bool equal(const FontTag& a, const FontTag& b) { return a == b; }
     50    static unsigned hash(FontTag characters) { return computeHash(characters); }
     51    static bool equal(FontTag a, FontTag b) { return a == b; }
    4652    static const bool safeToCompareToEmptyOrDeleted = true;
    4753};
    4854
    49 struct FourCharacterTagHashTraits : WTF::GenericHashTraits<FontTag> {
     55struct FourCharacterTagHashTraits : HashTraits<FontTag> {
    5056    static const bool emptyValueIsZero = true;
    5157    static void constructDeletedValue(FontTag& slot) { new (NotNull, std::addressof(slot)) FontTag({{ ff, ff, ff, ff }}); }
    52     static bool isDeletedValue(const FontTag& value) { return value == FontTag({{ ff, ff, ff, ff }}); }
     58    static bool isDeletedValue(FontTag value) { return value == FontTag({{ ff, ff, ff, ff }}); }
    5359
    5460private:
     
    6066public:
    6167    FontTaggedSetting() = delete;
    62     FontTaggedSetting(const FontTag&, T value);
    63     FontTaggedSetting(FontTag&&, T value);
     68    FontTaggedSetting(FontTag, T value);
    6469
    6570    bool operator==(const FontTaggedSetting<T>& other) const;
     
    6772    bool operator<(const FontTaggedSetting<T>& other) const;
    6873
    69     const FontTag& tag() const { return m_tag; }
     74    FontTag tag() const { return m_tag; }
    7075    T value() const { return m_value; }
    7176    bool enabled() const { return value(); }
     
    8085
    8186template <typename T>
    82 FontTaggedSetting<T>::FontTaggedSetting(const FontTag& tag, T value)
     87FontTaggedSetting<T>::FontTaggedSetting(FontTag tag, T value)
    8388    : m_tag(tag)
    84     , m_value(value)
    85 {
    86 }
    87 
    88 template <typename T>
    89 FontTaggedSetting<T>::FontTaggedSetting(FontTag&& tag, T value)
    90     : m_tag(WTFMove(tag))
    9189    , m_value(value)
    9290{
     
    151149        static_cast<char>(*char3)
    152150    }}, *value);
     151}
     152
     153template<typename T> void add(Hasher& hasher, const FontTaggedSetting<T>& setting)
     154{
     155    add(hasher, setting.tag(), setting.value());
    153156}
    154157
     
    212215}
    213216
    214 typedef FontTaggedSetting<int> FontFeature;
    215 typedef FontTaggedSettings<int> FontFeatureSettings;
    216 
    217 template <> unsigned FontFeatureSettings::hash() const;
    218 
    219 typedef FontTaggedSettings<float> FontVariationSettings;
    220 WTF::TextStream& operator<<(WTF::TextStream&, const FontVariationSettings&);
    221 
    222 template <> unsigned FontVariationSettings::hash() const;
    223 
    224 }
     217using FontFeature = FontTaggedSetting<int>;
     218using FontFeatureSettings = FontTaggedSettings<int>;
     219using FontVariationSettings = FontTaggedSettings<float>;
     220
     221TextStream& operator<<(TextStream&, const FontTaggedSettings<float>&);
     222
     223}
  • trunk/Source/WebCore/platform/graphics/Gradient.cpp

    r271472 r275650  
    3232#include <wtf/HashFunctions.h>
    3333#include <wtf/Hasher.h>
    34 
    35 using WTF::pairIntHash;
    3634
    3735namespace WebCore {
  • trunk/Source/WebCore/platform/graphics/cg/GraphicsContextCG.cpp

    r274252 r275650  
    4848#include <wtf/URL.h>
    4949#include <wtf/text/TextStream.h>
    50 
    51 // FIXME: The following using declaration should be in <wtf/HashFunctions.h>.
    52 using WTF::pairIntHash;
    53 
    54 // FIXME: The following using declaration should be in <wtf/HashTraits.h>.
    55 using WTF::GenericHashTraits;
    5650
    5751namespace WebCore {
  • trunk/Source/WebCore/platform/graphics/cg/SubimageCacheWithTimer.h

    r271533 r275650  
    5454    };
    5555
    56     struct SubimageCacheEntryTraits : WTF::GenericHashTraits<SubimageCacheEntry> {
     56    struct SubimageCacheEntryTraits : HashTraits<SubimageCacheEntry> {
    5757        typedef HashTraits<RetainPtr<CGImageRef>> ImageTraits;
    5858
  • trunk/Source/WebCore/platform/graphics/cocoa/FontFamilySpecificationCoreText.cpp

    r272706 r275650  
    3838
    3939struct FontFamilySpecificationKey {
     40    RetainPtr<CTFontDescriptorRef> fontDescriptor;
     41    FontDescriptionKey fontDescriptionKey;
     42
    4043    FontFamilySpecificationKey() = default;
    4144
     
    5154    bool operator==(const FontFamilySpecificationKey& other) const
    5255    {
    53         return WTF::safeCFEqual(fontDescriptor.get(), other.fontDescriptor.get()) && fontDescriptionKey == other.fontDescriptionKey;
     56        return safeCFEqual(fontDescriptor.get(), other.fontDescriptor.get()) && fontDescriptionKey == other.fontDescriptionKey;
    5457    }
    5558
     
    6063
    6164    bool isHashTableDeletedValue() const { return fontDescriptionKey.isHashTableDeletedValue(); }
    62 
    63     unsigned computeHash() const
    64     {
    65         return WTF::pairIntHash(WTF::safeCFHash(fontDescriptor.get()), fontDescriptionKey.computeHash());
    66     }
    67 
    68     RetainPtr<CTFontDescriptorRef> fontDescriptor;
    69     FontDescriptionKey fontDescriptionKey;
    7065};
    7166
    7267struct FontFamilySpecificationKeyHash {
    73     static unsigned hash(const FontFamilySpecificationKey& key) { return key.computeHash(); }
     68    static unsigned hash(const FontFamilySpecificationKey& key) { return computeHash(safeCFHash(key.fontDescriptor.get()), key.fontDescriptionKey); }
    7469    static bool equal(const FontFamilySpecificationKey& a, const FontFamilySpecificationKey& b) { return a == b; }
    7570    static const bool safeToCompareToEmptyOrDeleted = true;
    7671};
    7772
    78 using FontMap = HashMap<FontFamilySpecificationKey, std::unique_ptr<FontPlatformData>, FontFamilySpecificationKeyHash, WTF::SimpleClassHashTraits<FontFamilySpecificationKey>>;
     73using FontMap = HashMap<FontFamilySpecificationKey, std::unique_ptr<FontPlatformData>, FontFamilySpecificationKeyHash, SimpleClassHashTraits<FontFamilySpecificationKey>>;
    7974
    8075static FontMap& fontMap()
  • trunk/Source/WebCore/platform/graphics/cocoa/SystemFontDatabaseCoreText.h

    r272706 r275650  
    7373        unsigned hash() const
    7474        {
    75             IntegerHasher hasher;
    76             ASSERT(!fontName.isNull());
    77             hasher.add(locale.existingHash());
    78             hasher.add(locale.isNull() ? 0 : locale.existingHash());
    79             hasher.add(weight);
    80             hasher.add(width);
    81             hasher.add(size);
    82             hasher.add(static_cast<unsigned>(allowUserInstalledFonts));
    83             hasher.add(italic);
    84             return hasher.hash();
     75            return computeHash(fontName, locale, weight, width, size, allowUserInstalledFonts, italic);
    8576        }
    8677
    87         struct CascadeListParametersHash : WTF::PairHash<AtomString, float> {
    88             static unsigned hash(const CascadeListParameters& parameters)
    89             {
    90                 return parameters.hash();
    91             }
    92             static bool equal(const CascadeListParameters& a, const CascadeListParameters& b)
    93             {
    94                 return a == b;
    95             }
     78        struct Hash {
     79            static unsigned hash(const CascadeListParameters& parameters) { return parameters.hash(); }
     80            static bool equal(const CascadeListParameters& a, const CascadeListParameters& b) { return a == b; }
    9681            static const bool safeToCompareToEmptyOrDeleted = true;
    9782        };
     
    132117    static CascadeListParameters systemFontParameters(const FontDescription&, const AtomString& familyName, SystemFontKind, AllowUserInstalledFonts);
    133118
    134     HashMap<CascadeListParameters, Vector<RetainPtr<CTFontDescriptorRef>>, CascadeListParameters::CascadeListParametersHash, SimpleClassHashTraits<CascadeListParameters>> m_systemFontCache;
     119    HashMap<CascadeListParameters, Vector<RetainPtr<CTFontDescriptorRef>>, CascadeListParameters::Hash, SimpleClassHashTraits<CascadeListParameters>> m_systemFontCache;
    135120
    136121    HashMap<String, String> m_serifFamilies;
  • trunk/Source/WebCore/platform/graphics/freetype/FontCacheFreeType.cpp

    r275420 r275650  
    196196
    197197struct FallbackFontDescriptionKey {
     198    FontDescriptionKey descriptionKey;
     199    bool coloredFont { false };
     200
    198201    FallbackFontDescriptionKey() = default;
    199202
     
    221224    bool isHashTableDeletedValue() const { return descriptionKey.isHashTableDeletedValue(); }
    222225
    223     unsigned computeHash() const
    224     {
    225         return WTF::pairIntHash(descriptionKey.computeHash(), WTF::DefaultHash<bool>::hash(coloredFont));
    226     }
    227 
    228     FontDescriptionKey descriptionKey;
    229     bool coloredFont { false };
    230226};
    231227
    232228struct FallbackFontDescriptionKeyHash {
    233     static unsigned hash(const FallbackFontDescriptionKey& key) { return key.computeHash(); }
     229    static unsigned hash(const FallbackFontDescriptionKey& key) { return computeHash(key.descriptionKey, key.coloredFont); }
    234230    static bool equal(const FallbackFontDescriptionKey& a, const FallbackFontDescriptionKey& b) { return a == b; }
    235231    static const bool safeToCompareToEmptyOrDeleted = true;
  • trunk/Source/WebCore/platform/graphics/mac/ComplexTextControllerCoreText.mm

    r274252 r275650  
    186186            ASSERT(runCTFont && CFGetTypeID(runCTFont) == CTFontGetTypeID());
    187187            RetainPtr<CFTypeRef> runFontEqualityObject = FontPlatformData::objectForEqualityCheck(runCTFont);
    188             if (!WTF::safeCFEqual(runFontEqualityObject.get(), font->platformData().objectForEqualityCheck().get())) {
     188            if (!safeCFEqual(runFontEqualityObject.get(), font->platformData().objectForEqualityCheck().get())) {
    189189                // Begin trying to see if runFont matches any of the fonts in the fallback list.
    190190                for (unsigned i = 0; !m_font.fallbackRangesAt(i).isNull(); ++i) {
     
    192192                    if (!runFont)
    193193                        continue;
    194                     if (WTF::safeCFEqual(runFont->platformData().objectForEqualityCheck().get(), runFontEqualityObject.get()))
     194                    if (safeCFEqual(runFont->platformData().objectForEqualityCheck().get(), runFontEqualityObject.get()))
    195195                        break;
    196196                    runFont = nullptr;
  • trunk/Source/WebCore/platform/graphics/win/FontCacheWin.cpp

    r275364 r275650  
    339339    if (hfont) {
    340340        if (!familyName.isEmpty()) {
    341             FontPlatformData* result = getCachedFontPlatformData(description, familyName);
    342             if (result)
     341            if (auto result = cachedFontPlatformData(description, familyName))
    343342                fontData = fontForPlatformData(*result);
    344343        }
  • trunk/Source/WebCore/rendering/TextAutoSizing.h

    r220685 r275650  
    109109};
    110110
    111 struct TextAutoSizingTraits : WTF::GenericHashTraits<TextAutoSizingKey> {
     111struct TextAutoSizingTraits : HashTraits<TextAutoSizingKey> {
    112112    static const bool emptyValueIsZero = true;
    113113    static void constructDeletedValue(TextAutoSizingKey& slot) { new (NotNull, &slot) TextAutoSizingKey(TextAutoSizingKey::Deleted); }
  • trunk/Source/WebCore/rendering/style/RenderStyle.cpp

    r275607 r275650  
    450450static inline unsigned computeFontHash(const FontCascade& font)
    451451{
    452     IntegerHasher hasher;
    453     hasher.add(ASCIICaseInsensitiveHash::hash(font.fontDescription().firstFamily()));
    454     hasher.add(font.fontDescription().specifiedSize());
    455     return hasher.hash();
     452    // FIXME: Would be better to hash the family name rather than hashing a hash of the family name. Also, should this use FontCascadeDescription::familyNameHash?
     453    return computeHash(ASCIICaseInsensitiveHash::hash(font.fontDescription().firstFamily()), font.fontDescription().specifiedSize());
    456454}
    457455
  • trunk/Source/WebCore/workers/service/ServiceWorkerClientIdentifier.h

    r264488 r275650  
    11/*
    2  * Copyright (C) 2017 Apple Inc. All rights reserved.
     2 * Copyright (C) 2017-2021 Apple Inc. All rights reserved.
    33 *
    44 * Redistribution and use in source and binary forms, with or without
     
    3030#include "DocumentIdentifier.h"
    3131#include "ServiceWorkerTypes.h"
     32#include <wtf/Hasher.h>
    3233#include <wtf/text/StringConcatenateNumbers.h>
    3334
     
    8889        return WTF::nullopt;
    8990
    90     return { { WTFMove(*serverConnectionIdentifier), WTFMove(*contextIdentifier) } };
     91    return { { *serverConnectionIdentifier, *contextIdentifier } };
    9192}
    9293
    9394inline unsigned ServiceWorkerClientIdentifier::hash() const
    9495{
    95     unsigned hashes[2];
    96     hashes[0] = WTF::intHash(serverConnectionIdentifier.toUInt64());
    97     hashes[1] = WTF::intHash(contextIdentifier.toUInt64());
    98 
    99     return StringHasher::hashMemory(hashes, sizeof(hashes));
     96    return computeHash(serverConnectionIdentifier, contextIdentifier);
    10097}
    10198
  • trunk/Source/WebCore/workers/service/ServiceWorkerContextData.h

    r275443 r275650  
    3434#include "WorkerType.h"
    3535#include <wtf/HashMap.h>
    36 #include <wtf/URL.h>
    3736#include <wtf/URLHash.h>
    3837
  • trunk/Source/WebCore/workers/service/ServiceWorkerGlobalScope.h

    r275443 r275650  
    3232#include "ServiceWorkerRegistration.h"
    3333#include "WorkerGlobalScope.h"
     34#include <wtf/URLHash.h>
    3435
    3536namespace WebCore {
  • trunk/Source/WebCore/workers/service/context/SWContextManager.h

    r275443 r275650  
    3535#include <wtf/CompletionHandler.h>
    3636#include <wtf/HashMap.h>
     37#include <wtf/URLHash.h>
    3738
    3839namespace WebCore {
  • trunk/Source/WebCore/workers/service/context/ServiceWorkerThreadProxy.h

    r275443 r275650  
    4040#include "WorkerLoaderProxy.h"
    4141#include <wtf/HashMap.h>
     42#include <wtf/URLHash.h>
    4243
    4344namespace WebCore {
  • trunk/Source/WebCore/workers/service/server/RegistrationStore.h

    r275443 r275650  
    3535#include <wtf/CompletionHandler.h>
    3636#include <wtf/HashMap.h>
     37#include <wtf/URLHash.h>
    3738#include <wtf/WeakPtr.h>
    3839#include <wtf/text/WTFString.h>
  • trunk/Source/WebCore/workers/service/server/SWServer.h

    r275465 r275650  
    4646#include <wtf/ThreadSafeRefCounted.h>
    4747#include <wtf/Threading.h>
     48#include <wtf/URLHash.h>
    4849#include <wtf/UniqueRef.h>
    4950#include <wtf/WeakPtr.h>
  • trunk/Source/WebCore/workers/service/server/SWServerToContextConnection.h

    r275443 r275650  
    3434#include "ServiceWorkerIdentifier.h"
    3535#include "ServiceWorkerTypes.h"
     36#include <wtf/URLHash.h>
    3637
    3738namespace WebCore {
  • trunk/Source/WebCore/workers/service/server/SWServerWorker.h

    r275443 r275650  
    4040#include <wtf/CompletionHandler.h>
    4141#include <wtf/RefCounted.h>
     42#include <wtf/URLHash.h>
    4243#include <wtf/WeakPtr.h>
    4344
  • trunk/Source/WebKit/ChangeLog

    r275645 r275650  
     12021-04-02  Darin Adler  <darin@apple.com>
     2
     3        Use Hasher more, remove IntegerHasher, fix hashing-related mistakes
     4        https://bugs.webkit.org/show_bug.cgi?id=224138
     5
     6        Reviewed by Chris Dumez.
     7
     8        * NetworkProcess/ServiceWorker/WebSWServerToContextConnection.h: Added now-needed include
     9        of URLHash.h, since we removed it from a widely-included header.
     10
     11        * NetworkProcess/cache/NetworkCache.h:
     12        (WebKit::NetworkCache::GlobalFrameID::hash const): Use computeHash
     13        instead of combining intHash with StringHasher::hashMemory. This fixes
     14        two mistakes: one is that there is no need to hash a hash. The second is
     15        that intHash takes a 32-bit integer as its parameter, so high bits
     16        of object identifiers were discarded unnecessarily.
     17
     18        * Scripts/webkit/messages.py: Added code so that if URL is in an argument, we include the
     19        URLHash.h header. Would be better to just use URL.h and use URLHash.h only if it's a
     20        HashMap<URL>, but currently the script does not distinguish those cases. This wasn't needed
     21        before becuase a widely included header was always pulling in URLHash.h.
     22
     23        * Shared/API/Cocoa/WKBrowsingContextHandle.mm:
     24        (-[WKBrowsingContextHandle hash]): Use computeHash instead of pairIntHash.
     25        This fixes a mistake: pairIntHash takes two 32-bit integers, so high bits
     26        of object identifiers were discarded unnecessarily.
     27
     28        * NetworkProcess/Storage/WebSWContextManagerConnection.h: Added now-needed include
     29        of URLHash.h, since we removed it from a widely-included header.
     30
    1312021-04-07  Jer Noble  <jer.noble@apple.com>
    232
  • trunk/Source/WebKit/NetworkProcess/ServiceWorker/WebSWServerToContextConnection.h

    r275443 r275650  
    3333#include "WebPageProxyIdentifier.h"
    3434#include <WebCore/SWServerToContextConnection.h>
     35#include <wtf/URLHash.h>
    3536#include <wtf/WeakPtr.h>
    3637
  • trunk/Source/WebKit/NetworkProcess/cache/NetworkCache.h

    r264488 r275650  
    6060inline unsigned GlobalFrameID::hash() const
    6161{
    62     unsigned hashes[2];
    63     hashes[0] = WTF::intHash(webPageID.toUInt64());
    64     hashes[1] = WTF::intHash(frameID.toUInt64());
    65 
    66     return StringHasher::hashMemory(hashes, sizeof(hashes));
     62    return computeHash(webPageID, frameID);
    6763}
    6864
     
    7470}
    7571
    76 };
    77 } // namespace NetworkCache
     72}
     73}
    7874
    7975namespace WTF {
  • trunk/Source/WebKit/Scripts/webkit/messages.py

    r275103 r275650  
    670670        'MonotonicTime': ['<wtf/MonotonicTime.h>'],
    671671        'Seconds': ['<wtf/Seconds.h>'],
     672        'URL': ['<wtf/URLHash.h>'],
    672673        'WallTime': ['<wtf/WallTime.h>'],
    673674        'String': ['<wtf/text/WTFString.h>'],
  • trunk/Source/WebKit/Shared/API/Cocoa/WKBrowsingContextHandle.mm

    r273471 r275650  
    5656- (NSUInteger)hash
    5757{
    58     return WTF::pairIntHash(_pageProxyID.toUInt64(), _webPageID.toUInt64());
     58    return computeHash(_pageProxyID, _webPageID);
    5959}
    6060
  • trunk/Source/WebKit/WebProcess/Storage/WebSWContextManagerConnection.h

    r275443 r275650  
    3838#include <WebCore/ServiceWorkerClientData.h>
    3939#include <WebCore/ServiceWorkerTypes.h>
     40#include <wtf/URLHash.h>
    4041
    4142namespace IPC {
  • trunk/Source/WebKitLegacy/mac/ChangeLog

    r275327 r275650  
     12021-04-02  Darin Adler  <darin@apple.com>
     2
     3        Use Hasher more, remove IntegerHasher, fix hashing-related mistakes
     4        https://bugs.webkit.org/show_bug.cgi?id=224138
     5
     6        Reviewed by Chris Dumez.
     7
     8        * History/BinaryPropertyList.cpp: Use HashTraits instead of WTF::GenericHashTraits.
     9
    1102021-03-31  Chris Dumez  <cdumez@apple.com>
    211
  • trunk/Source/WebKitLegacy/mac/History/BinaryPropertyList.cpp

    r235886 r275650  
    7676}
    7777
    78 struct IntegerArrayHashTraits : WTF::GenericHashTraits<IntegerArray> {
     78struct IntegerArrayHashTraits : HashTraits<IntegerArray> {
    7979    static void constructDeletedValue(IntegerArray& slot) { slot.markDeleted(); }
    8080    static bool isDeletedValue(const IntegerArray& array) { return array.isDeletedValue(); }
Note: See TracChangeset for help on using the changeset viewer.