Changeset 275650 in webkit
- Timestamp:
- Apr 7, 2021 7:19:20 PM (3 years ago)
- Location:
- trunk/Source
- Files:
-
- 53 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/Source/JavaScriptCore/ChangeLog
r275648 r275650 1 2021-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 1 20 2021-04-07 Mark Lam <mark.lam@apple.com> 2 21 -
trunk/Source/JavaScriptCore/bytecode/BytecodeIndex.h
r264488 r275650 61 61 uint32_t asBits() const { return m_packedBits; } 62 62 63 unsigned hash() const { return WTF::intHash(m_packedBits); }63 unsigned hash() const { return intHash(m_packedBits); } 64 64 static BytecodeIndex deletedValue() { return fromBits(invalidOffset - 1); } 65 65 bool isHashTableDeletedValue() const { return *this == deletedValue(); } -
trunk/Source/JavaScriptCore/ftl/FTLAbstractHeap.h
r262338 r275650 155 155 std::array<AbstractHeap, 16> m_smallIndices; 156 156 157 struct WithoutZeroOrOneHashTraits : WTF::GenericHashTraits<ptrdiff_t> {157 struct WithoutZeroOrOneHashTraits : HashTraits<ptrdiff_t> { 158 158 static void constructDeletedValue(ptrdiff_t& slot) { slot = 1; } 159 159 static bool isDeletedValue(ptrdiff_t value) { return value == 1; } -
trunk/Source/JavaScriptCore/ftl/FTLLowerDFGToB3.cpp
r275626 r275650 592 592 unsigned highParentIndex = node->index(); 593 593 { 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()) 596 595 return; 597 596 } -
trunk/Source/JavaScriptCore/wasm/WasmLLIntGenerator.cpp
r273962 r275650 417 417 }; 418 418 419 struct ConstantMapHashTraits : WTF::GenericHashTraits<EncodedJSValue> {419 struct ConstantMapHashTraits : HashTraits<EncodedJSValue> { 420 420 static constexpr bool emptyValueIsZero = true; 421 421 static void constructDeletedValue(EncodedJSValue& slot) { slot = JSValue::encode(jsNull()); } -
trunk/Source/WTF/ChangeLog
r275646 r275650 1 2021-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 1 30 2021-04-07 Michael Catanzaro <mcatanzaro@gnome.org> 2 31 -
trunk/Source/WTF/wtf/HashFunctions.h
r264488 r275650 276 276 using WTF::IntHash; 277 277 using WTF::PtrHash; 278 using WTF::intHash; 279 using WTF::pairIntHash; -
trunk/Source/WTF/wtf/Hasher.h
r267373 r275650 1 1 /* 2 * Copyright (C) 2016-20 17Apple Inc. All rights reserved.2 * Copyright (C) 2016-2021 Apple Inc. All rights reserved. 3 3 * 4 4 * This library is free software; you can redistribute it and/or … … 21 21 #pragma once 22 22 23 #include <wtf/Forward.h>24 23 #include <wtf/Optional.h> 25 24 #include <wtf/StdLibExtras.h> 25 #include <wtf/URL.h> 26 #include <wtf/text/AtomString.h> 26 27 #include <wtf/text/StringHasher.h> 27 28 28 29 namespace 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() const40 {41 return m_underlyingHasher.hash();42 }43 44 private:45 StringHasher m_underlyingHasher;46 };47 30 48 31 template<typename... Types> uint32_t computeHash(const Types&...); … … 111 94 { 112 95 add(hasher, bitwise_cast<uint32_t>(number)); 96 } 97 98 inline 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 109 inline 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 115 inline void add(Hasher& hasher, const URL& url) 116 { 117 add(hasher, url.string()); 113 118 } 114 119 … … 187 192 using WTF::computeHash; 188 193 using WTF::Hasher; 189 using WTF::IntegerHasher; -
trunk/Source/WTF/wtf/ObjectIdentifier.h
r264488 r275650 132 132 } 133 133 134 template<typename T> inline void add(Hasher& hasher, ObjectIdentifier<T> identifier) 135 { 136 add(hasher, identifier.toUInt64()); 137 } 138 134 139 template<typename T> struct ObjectIdentifierHash { 135 140 static unsigned hash(const ObjectIdentifier<T>& identifier) { return intHash(identifier.m_identifier); } -
trunk/Source/WTF/wtf/RetainPtr.h
r272985 r275650 403 403 using WTF::adoptCF; 404 404 using WTF::retainPtr; 405 using WTF::safeCFEqual; 406 using WTF::safeCFHash; 405 407 406 408 #ifdef __OBJC__ -
trunk/Source/WTF/wtf/VectorHash.h
r264488 r275650 1 1 /* 2 * Copyright (C) 2019 Apple Inc. All Rights Reserved.2 * Copyright (C) 2019-2021 Apple Inc. All rights reserved. 3 3 * 4 4 * Redistribution and use in source and binary forms, with or without … … 27 27 28 28 #include "HashFunctions.h" 29 #include "HashTraits.h"30 29 #include "Hasher.h" 31 30 32 31 namespace WTF { 33 32 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 } 33 template<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; } 47 36 static constexpr bool safeToCompareToEmptyOrDeleted = true; 48 37 }; 49 38 50 template<typename T, size_t inlineCapacity>51 struct DefaultHash<Vector<T, inlineCapacity>> : VectorHash<T, inlineCapacity> { };52 53 39 } -
trunk/Source/WebCore/ChangeLog
r275648 r275650 1 2021-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 1 171 2021-04-07 Mark Lam <mark.lam@apple.com> 2 172 -
trunk/Source/WebCore/contentextensions/ContentExtensionRule.h
r264488 r275650 30 30 #include "ContentExtensionActions.h" 31 31 #include "ResourceLoadInfo.h" 32 #include <wtf/Hasher.h> 32 33 #include <wtf/text/WTFString.h> 33 34 … … 89 90 static unsigned hash(const Trigger& trigger) 90 91 { 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); 101 93 } 102 103 94 static bool equal(const Trigger& a, const Trigger& b) 104 95 { 105 96 return a == b; 106 97 } 107 108 98 static const bool safeToCompareToEmptyOrDeleted = false; 109 99 }; -
trunk/Source/WebCore/contentextensions/Term.h
r208179 r275650 33 33 #include <wtf/ASCIICType.h> 34 34 #include <wtf/HashMap.h> 35 #include <wtf/Hasher.h> 35 36 #include <wtf/Vector.h> 36 37 #include <wtf/text/StringBuilder.h> … … 169 170 unsigned hash() const 170 171 { 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 173 175 private: 174 176 bool m_inverted { false }; 175 uint64_t m_characters[2]{ 0, 0 };177 std::array<uint64_t, 2> m_characters { 0, 0 }; 176 178 }; 177 179 -
trunk/Source/WebCore/css/parser/CSSParserContext.cpp
r274793 r275650 138 138 } 139 139 140 void 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 140 177 bool CSSParserContext::isPropertyRuntimeDisabled(CSSPropertyID property) const 141 178 { -
trunk/Source/WebCore/css/parser/CSSParserContext.h
r274793 r275650 31 31 #include "TextEncoding.h" 32 32 #include <wtf/HashFunctions.h> 33 #include <wtf/Hasher.h> 33 34 #include <wtf/Optional.h> 34 35 #include <wtf/URL.h> 35 #include <wtf/URLHash.h>36 #include <wtf/text/StringHash.h>37 36 38 37 namespace WebCore { … … 41 40 42 41 struct 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; 47 43 48 44 URL baseURL; … … 57 53 bool isContentOpaque { false }; 58 54 bool useSystemAppearance { false }; 59 60 bool isPropertyRuntimeDisabled(CSSPropertyID) const;61 55 62 56 // Settings. … … 91 85 #endif 92 86 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; 94 91 }; 95 92 … … 97 94 inline bool operator!=(const CSSParserContext& a, const CSSParserContext& b) { return !(a == b); } 98 95 96 void add(Hasher&, const CSSParserContext&); 97 99 98 WEBCORE_EXPORT const CSSParserContext& strictCSSParserContext(); 100 99 101 100 struct 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; } 151 103 static const bool safeToCompareToEmptyOrDeleted = false; 152 104 }; … … 155 107 156 108 namespace WTF { 109 157 110 template<> struct HashTraits<WebCore::CSSParserContext> : GenericHashTraits<WebCore::CSSParserContext> { 158 111 static void constructDeletedValue(WebCore::CSSParserContext& slot) { new (NotNull, &slot.baseURL) URL(WTF::HashTableDeletedValue); } -
trunk/Source/WebCore/html/FormController.cpp
r261013 r275650 162 162 } 163 163 164 struct FormElementKeyHashTraits : WTF::GenericHashTraits<FormElementKey> {164 struct FormElementKeyHashTraits : HashTraits<FormElementKey> { 165 165 static void constructDeletedValue(FormElementKey& slot) { new (NotNull, &slot) FormElementKey(WTF::HashTableDeletedValue); } 166 166 static bool isDeletedValue(const FormElementKey& value) { return value.isHashTableDeletedValue(); } -
trunk/Source/WebCore/platform/encryptedmedia/CDMProxy.h
r275599 r275650 37 37 #include <wtf/BoxPtr.h> 38 38 #include <wtf/Condition.h> 39 #include <wtf/VectorHash.h>40 #include <wtf/WeakHashSet.h>41 39 42 40 #if ENABLE(THUNDER) … … 208 206 209 207 class CDMInstanceSessionProxy : public CDMInstanceSession, public CanMakeWeakPtr<CDMInstanceSessionProxy, WeakPtrFactoryInitialization::Eager> { 210 public:211 212 208 protected: 213 209 CDMInstanceSessionProxy(CDMInstanceProxy&); -
trunk/Source/WebCore/platform/graphics/Font.cpp
r272783 r275650 536 536 #endif 537 537 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 538 struct CharacterFallbackMapKey { 568 539 AtomString locale; 569 540 UChar32 character { 0 }; … … 571 542 }; 572 543 544 inline 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 573 549 struct 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; } 588 552 static const bool safeToCompareToEmptyOrDeleted = true; 589 553 }; 590 554 555 struct 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 591 560 // 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. 562 using CharacterFallbackMap = HashMap<CharacterFallbackMapKey, Font*, CharacterFallbackMapKeyHash, CharacterFallbackMapKeyHashTraits>; 563 using SystemFallbackCache = HashMap<const Font*, CharacterFallbackMap>; 595 564 596 565 static SystemFallbackCache& systemFallbackCache() … … 609 578 } 610 579 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), [&] { 617 582 UChar codeUnits[2]; 618 583 unsigned codeUnitsLength; … … 625 590 codeUnitsLength = 2; 626 591 } 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; 634 597 } 635 598 -
trunk/Source/WebCore/platform/graphics/Font.h
r273121 r275650 65 65 enum FontVariant { AutoVariant, NormalVariant, SmallCapsVariant, EmphasisMarkVariant, BrokenIdeographVariant }; 66 66 enum Pitch { UnknownPitch, FixedPitch, VariablePitch }; 67 enum class IsForPlatformFont : uint8_t{ No, Yes };67 enum class IsForPlatformFont : bool { No, Yes }; 68 68 69 69 #if USE(CORE_TEXT) -
trunk/Source/WebCore/platform/graphics/FontCache.cpp
r275420 r275650 1 1 /* 2 * Copyright (C) 2006 , 2008, 2013Apple Inc. All rights reserved.2 * Copyright (C) 2006-2021 Apple Inc. All rights reserved. 3 3 * Copyright (C) 2007 Nicholas Shanks <webkit@nickshanks.com> 4 4 * … … 48 48 49 49 namespace WebCore { 50 using namespace WTF; 50 51 FontFamilyName::FontFamilyName() = default; 52 53 inline FontFamilyName::FontFamilyName(const AtomString& name) 54 : m_name { name } 55 { 56 } 57 58 inline const AtomString& FontFamilyName::string() const 59 { 60 return m_name; 61 } 62 63 inline 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 70 inline 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 75 inline bool operator!=(const FontFamilyName& a, const FontFamilyName& b) 76 { 77 return !(a == b); 78 } 51 79 52 80 struct 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; 85 85 }; 86 86 87 static 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 87 92 struct 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; } 114 95 static constexpr bool safeToCompareToEmptyOrDeleted = true; 115 96 }; … … 117 98 struct FontPlatformDataCacheKeyHashTraits : public SimpleClassHashTraits<FontPlatformDataCacheKey> { 118 99 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 } 119 108 }; 120 109 121 110 struct 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; } 132 113 static constexpr bool safeToCompareToEmptyOrDeleted = true; 133 114 }; … … 142 123 static void constructDeletedValue(FontPlatformData& slot) 143 124 { 144 new (NotNull, &slot) FontPlatformData( HashTableDeletedValue);125 new (NotNull, &slot) FontPlatformData(WTF::HashTableDeletedValue); 145 126 } 146 127 static bool isDeletedValue(const FontPlatformData& value) … … 178 159 } 179 160 180 FontCache::~FontCache() = default;181 182 161 FontCache::FontCache() 183 162 : m_purgeTimer(*this, &FontCache::purgeInactiveFontDataIfNeeded) … … 185 164 { 186 165 } 166 167 FontCache::~FontCache() = default; 187 168 188 169 Optional<ASCIILiteral> FontCache::alternateFamilyName(const String& familyName) … … 226 207 } 227 208 228 FontPlatformData* FontCache:: getCachedFontPlatformData(const FontDescription& fontDescription, const String& passedFamilyName,229 const FontFeatureSettings* f ontFaceFeatures, FontSelectionSpecifiedCapabilities fontFaceCapabilities, bool checkingAlternateName)209 FontPlatformData* FontCache::cachedFontPlatformData(const FontDescription& fontDescription, const String& passedFamilyName, 210 const FontFeatureSettings* features, FontSelectionSpecifiedCapabilities capabilities, bool checkingAlternateName) 230 211 { 231 212 #if PLATFORM(IOS_FAMILY) … … 247 228 }); 248 229 249 FontPlatformDataCacheKey key (familyName, fontDescription, fontFaceFeatures, fontFaceCapabilities);230 FontPlatformDataCacheKey key { fontDescription, { familyName }, features ? *features : FontFeatureSettings { }, capabilities }; 250 231 251 232 auto addResult = m_fontDataCaches->platformData.add(key, nullptr); 252 233 FontPlatformDataCache::iterator it = addResult.iterator; 253 234 if (addResult.isNewEntry) { 254 it->value = createFontPlatformData(fontDescription, familyName, fontFaceFeatures, fontFaceCapabilities); 255 235 it->value = createFontPlatformData(fontDescription, familyName, features, capabilities); 256 236 if (!it->value && !checkingAlternateName) { 257 // We were unable to find a font. 258 // e.g., Arial/Helvetica, Courier/Courier New, etc. 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. 259 239 if (auto alternateName = alternateFamilyName(familyName)) { 260 auto* fontPlatformDataForAlternateName = getCachedFontPlatformData(fontDescription, *alternateName, fontFaceFeatures, fontFaceCapabilities, true);261 // Look up the key in the hash table again as the previous iterator may have262 // 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(). 263 243 it = m_fontDataCaches->platformData.find(key); 264 244 ASSERT(it != m_fontDataCaches->platformData.end()); 265 if ( fontPlatformDataForAlternateName)266 it->value = makeUnique<FontPlatformData>(* fontPlatformDataForAlternateName);245 if (alternateData) 246 it->value = makeUnique<FontPlatformData>(*alternateData); 267 247 } 268 248 } … … 283 263 const unsigned cTargetUnderMemoryPressureInactiveFontData = 30; 284 264 285 RefPtr<Font> FontCache::fontForFamily(const FontDescription& fontDescription, const String& family, const FontFeatureSettings* f ontFaceFeatures, FontSelectionSpecifiedCapabilities fontFaceCapabilities, bool checkingAlternateName)265 RefPtr<Font> FontCache::fontForFamily(const FontDescription& fontDescription, const String& family, const FontFeatureSettings* features, FontSelectionSpecifiedCapabilities capabilities, bool checkingAlternateName) 286 266 { 287 267 if (!m_purgeTimer.isActive()) 288 268 m_purgeTimer.startOneShot(0_s); 289 269 290 if (auto* platformData = getCachedFontPlatformData(fontDescription, family, fontFaceFeatures, fontFaceCapabilities, checkingAlternateName))270 if (auto* platformData = cachedFontPlatformData(fontDescription, family, features, capabilities, checkingAlternateName)) 291 271 return fontForPlatformData(*platformData); 292 272 … … 376 356 bool operator==(const FontCascadeCacheKey& a, const FontCascadeCacheKey& b) 377 357 { 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; 390 362 } 391 363 392 364 unsigned FontCascadeCacheKeyHash::hash(const FontCascadeCacheKey& key) 393 365 { 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); 402 367 } 403 368 … … 457 422 458 423 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)) }); 460 425 Ref<FontCascadeFonts> glyphs = newEntry->fonts.get(); 461 426 462 static const unsigned unreferencedPruneInterval = 50;463 static const int maximumEntries = 400;427 static constexpr unsigned unreferencedPruneInterval = 50; 428 static constexpr int maximumEntries = 400; 464 429 static unsigned pruneCounter; 465 430 // Referenced FontCascadeFonts would exist anyway so pruning them saves little memory. … … 516 481 invalidateFontCascadeCache(); 517 482 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(); 527 487 528 488 purgeInactiveFontData(); -
trunk/Source/WebCore/platform/graphics/FontCache.h
r275420 r275650 1 1 /* 2 * Copyright (C) 2006 , 2008 Apple Inc.All rights reserved.2 * Copyright (C) 2006-2021 Apple Inc. All rights reserved. 3 3 * Copyright (C) 2007-2008 Torch Mobile, Inc. 4 4 * … … 8 8 * 9 9 * 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. 11 11 * 2. Redistributions in binary form must reproduce the above copyright 12 12 * 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. 14 14 * 3. Neither the name of Apple Inc. ("Apple") nor the names of 15 15 * 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. 17 17 * 18 18 * THIS SOFTWARE IS PROVIDED BY APPLE AND ITS CONTRIBUTORS "AS IS" AND ANY … … 65 65 namespace WebCore { 66 66 67 class Font; 67 68 class FontCascade; 68 69 class 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 71 enum class IsForPlatformFont : bool; 72 73 #if PLATFORM(WIN) && USE(IMLANG_FONT_LINK2) 74 using IMLangFontLinkType = IMLangFontLink2; 75 #endif 76 77 #if PLATFORM(WIN) && !USE(IMLANG_FONT_LINK2) 78 using IMLangFontLinkType = IMLangFontLink; 78 79 #endif 79 80 … … 113 114 bool isHashTableDeletedValue() const { return m_isDeletedValue; } 114 115 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&); 126 117 127 118 private: … … 166 157 }; 167 158 159 inline 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 168 164 struct 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. 172 class FontFamilyName { 173 public: 174 FontFamilyName(); 175 FontFamilyName(const AtomString&); 176 const AtomString& string() const; 177 friend void add(Hasher&, const FontFamilyName&); 178 179 private: 180 AtomString m_name; 181 }; 182 183 bool operator==(const FontFamilyName&, const FontFamilyName&); 184 bool operator!=(const FontFamilyName&, const FontFamilyName&); 181 185 182 186 struct FontCascadeCacheKey { 183 187 FontDescriptionKey fontDescriptionKey; // Shared with the lower level FontCache (caching Font objects) 184 Vector< AtomString, 3> families;188 Vector<FontFamilyName, 3> families; 185 189 unsigned fontSelectorId; 186 190 unsigned fontSelectorVersion; … … 190 194 191 195 struct 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 198 198 FontCascadeCacheKey key; 199 199 Ref<FontCascadeFonts> fonts; … … 201 201 202 202 struct 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 208 struct 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(); } 212 212 }; 213 213 … … 226 226 227 227 // These methods are implemented by the platform. 228 enum class PreferColoredFont : uint8_t{ No, Yes };228 enum class PreferColoredFont : bool { No, Yes }; 229 229 RefPtr<Font> systemFallbackForCharacters(const FontDescription&, const Font* originalFontData, IsForPlatformFont, PreferColoredFont, const UChar* characters, unsigned length); 230 230 Vector<String> systemFontFamilies(); … … 236 236 WEBCORE_EXPORT static void setFontAllowlist(const Vector<String>&); 237 237 #endif 238 238 239 #if PLATFORM(WIN) 239 240 IMLangFontLinkType* getFontLinkInterface(); … … 302 303 Ref<FontCascadeFonts> retrieveOrAddCachedFonts(const FontCascadeDescription&, RefPtr<FontSelector>&&); 303 304 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); 309 309 310 310 static Optional<ASCIILiteral> alternateFamilyName(const String&); … … 333 333 friend class ComplexTextController; 334 334 #endif 335 335 336 friend class Font; 336 337 }; … … 348 349 349 350 #endif 350 351 351 352 352 inline bool FontCache::PrewarmInformation::isEmpty() const -
trunk/Source/WebCore/platform/graphics/FontGenericFamilies.h
r274143 r275650 36 36 // UScriptCode uses -1 and 0 for UScriptInvalidCode and UScriptCommon. 37 37 // We need to use -2 and -3 for empty value and deleted value. 38 struct UScriptCodeHashTraits : WTF::GenericHashTraits<int> {38 struct UScriptCodeHashTraits : HashTraits<int> { 39 39 static const bool emptyValueIsZero = false; 40 40 static int emptyValue() { return -2; } -
trunk/Source/WebCore/platform/graphics/FontSelectionAlgorithm.h
r254295 r275650 292 292 } 293 293 294 inline void add(Hasher& hasher, const FontSelectionValue& value) 295 { 296 add(hasher, value.rawValue()); 297 } 298 294 299 // [Inclusive, Inclusive] 295 300 struct FontSelectionRange { … … 335 340 } 336 341 337 // FIXME: This name is not so great. Move this into the add function below338 // once we move FontPlatformDataCacheKeyHash from IntegerHasher to Hasher,339 // and then it doesn't need to have a name.340 constexpr uint32_t uniqueValue() const341 {342 return minimum.rawValue() << 16 | maximum.rawValue();343 }344 345 342 template<class Encoder> 346 343 void encode(Encoder&) const; … … 378 375 inline void add(Hasher& hasher, const FontSelectionRange& range) 379 376 { 380 add(hasher, range. uniqueValue());377 add(hasher, range.minimum, range.maximum); 381 378 } 382 379 … … 386 383 Value weight; 387 384 Value width; 385 388 386 // FIXME: We are using an optional here to be able to distinguish between an explicit 389 387 // or implicit slope (for "italic" and "oblique") and the "normal" value which has no -
trunk/Source/WebCore/platform/graphics/FontTaggedSettings.cpp
r266686 r275650 28 28 #include "FontTaggedSettings.h" 29 29 30 #include <wtf/Hasher.h>31 #include <wtf/text/AtomStringHash.h>32 30 #include <wtf/text/TextStream.h> 33 31 34 32 namespace WebCore { 35 33 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) 34 TextStream& operator<<(TextStream& ts, const FontTaggedSettings<float>& item) 66 35 { 67 36 for (unsigned i = 0; i < item.size(); ++i) { -
trunk/Source/WebCore/platform/graphics/FontTaggedSettings.h
r266686 r275650 37 37 namespace WebCore { 38 38 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] }}; } 39 using FontTag = std::array<char, 4>; 40 41 inline FontTag fontFeatureTag(const char characters[4]) { return {{ characters[0], characters[1], characters[2], characters[3] }}; } 42 43 inline 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 } 42 48 43 49 struct 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; } 46 52 static const bool safeToCompareToEmptyOrDeleted = true; 47 53 }; 48 54 49 struct FourCharacterTagHashTraits : WTF::GenericHashTraits<FontTag> {55 struct FourCharacterTagHashTraits : HashTraits<FontTag> { 50 56 static const bool emptyValueIsZero = true; 51 57 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 }}); } 53 59 54 60 private: … … 60 66 public: 61 67 FontTaggedSetting() = delete; 62 FontTaggedSetting(const FontTag&, T value); 63 FontTaggedSetting(FontTag&&, T value); 68 FontTaggedSetting(FontTag, T value); 64 69 65 70 bool operator==(const FontTaggedSetting<T>& other) const; … … 67 72 bool operator<(const FontTaggedSetting<T>& other) const; 68 73 69 const FontTag&tag() const { return m_tag; }74 FontTag tag() const { return m_tag; } 70 75 T value() const { return m_value; } 71 76 bool enabled() const { return value(); } … … 80 85 81 86 template <typename T> 82 FontTaggedSetting<T>::FontTaggedSetting( const FontTag&tag, T value)87 FontTaggedSetting<T>::FontTaggedSetting(FontTag tag, T value) 83 88 : 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))91 89 , m_value(value) 92 90 { … … 151 149 static_cast<char>(*char3) 152 150 }}, *value); 151 } 152 153 template<typename T> void add(Hasher& hasher, const FontTaggedSetting<T>& setting) 154 { 155 add(hasher, setting.tag(), setting.value()); 153 156 } 154 157 … … 212 215 } 213 216 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 } 217 using FontFeature = FontTaggedSetting<int>; 218 using FontFeatureSettings = FontTaggedSettings<int>; 219 using FontVariationSettings = FontTaggedSettings<float>; 220 221 TextStream& operator<<(TextStream&, const FontTaggedSettings<float>&); 222 223 } -
trunk/Source/WebCore/platform/graphics/Gradient.cpp
r271472 r275650 32 32 #include <wtf/HashFunctions.h> 33 33 #include <wtf/Hasher.h> 34 35 using WTF::pairIntHash;36 34 37 35 namespace WebCore { -
trunk/Source/WebCore/platform/graphics/cg/GraphicsContextCG.cpp
r274252 r275650 48 48 #include <wtf/URL.h> 49 49 #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;56 50 57 51 namespace WebCore { -
trunk/Source/WebCore/platform/graphics/cg/SubimageCacheWithTimer.h
r271533 r275650 54 54 }; 55 55 56 struct SubimageCacheEntryTraits : WTF::GenericHashTraits<SubimageCacheEntry> {56 struct SubimageCacheEntryTraits : HashTraits<SubimageCacheEntry> { 57 57 typedef HashTraits<RetainPtr<CGImageRef>> ImageTraits; 58 58 -
trunk/Source/WebCore/platform/graphics/cocoa/FontFamilySpecificationCoreText.cpp
r272706 r275650 38 38 39 39 struct FontFamilySpecificationKey { 40 RetainPtr<CTFontDescriptorRef> fontDescriptor; 41 FontDescriptionKey fontDescriptionKey; 42 40 43 FontFamilySpecificationKey() = default; 41 44 … … 51 54 bool operator==(const FontFamilySpecificationKey& other) const 52 55 { 53 return WTF::safeCFEqual(fontDescriptor.get(), other.fontDescriptor.get()) && fontDescriptionKey == other.fontDescriptionKey;56 return safeCFEqual(fontDescriptor.get(), other.fontDescriptor.get()) && fontDescriptionKey == other.fontDescriptionKey; 54 57 } 55 58 … … 60 63 61 64 bool isHashTableDeletedValue() const { return fontDescriptionKey.isHashTableDeletedValue(); } 62 63 unsigned computeHash() const64 {65 return WTF::pairIntHash(WTF::safeCFHash(fontDescriptor.get()), fontDescriptionKey.computeHash());66 }67 68 RetainPtr<CTFontDescriptorRef> fontDescriptor;69 FontDescriptionKey fontDescriptionKey;70 65 }; 71 66 72 67 struct 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); } 74 69 static bool equal(const FontFamilySpecificationKey& a, const FontFamilySpecificationKey& b) { return a == b; } 75 70 static const bool safeToCompareToEmptyOrDeleted = true; 76 71 }; 77 72 78 using FontMap = HashMap<FontFamilySpecificationKey, std::unique_ptr<FontPlatformData>, FontFamilySpecificationKeyHash, WTF::SimpleClassHashTraits<FontFamilySpecificationKey>>;73 using FontMap = HashMap<FontFamilySpecificationKey, std::unique_ptr<FontPlatformData>, FontFamilySpecificationKeyHash, SimpleClassHashTraits<FontFamilySpecificationKey>>; 79 74 80 75 static FontMap& fontMap() -
trunk/Source/WebCore/platform/graphics/cocoa/SystemFontDatabaseCoreText.h
r272706 r275650 73 73 unsigned hash() const 74 74 { 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); 85 76 } 86 77 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; } 96 81 static const bool safeToCompareToEmptyOrDeleted = true; 97 82 }; … … 132 117 static CascadeListParameters systemFontParameters(const FontDescription&, const AtomString& familyName, SystemFontKind, AllowUserInstalledFonts); 133 118 134 HashMap<CascadeListParameters, Vector<RetainPtr<CTFontDescriptorRef>>, CascadeListParameters:: CascadeListParametersHash, SimpleClassHashTraits<CascadeListParameters>> m_systemFontCache;119 HashMap<CascadeListParameters, Vector<RetainPtr<CTFontDescriptorRef>>, CascadeListParameters::Hash, SimpleClassHashTraits<CascadeListParameters>> m_systemFontCache; 135 120 136 121 HashMap<String, String> m_serifFamilies; -
trunk/Source/WebCore/platform/graphics/freetype/FontCacheFreeType.cpp
r275420 r275650 196 196 197 197 struct FallbackFontDescriptionKey { 198 FontDescriptionKey descriptionKey; 199 bool coloredFont { false }; 200 198 201 FallbackFontDescriptionKey() = default; 199 202 … … 221 224 bool isHashTableDeletedValue() const { return descriptionKey.isHashTableDeletedValue(); } 222 225 223 unsigned computeHash() const224 {225 return WTF::pairIntHash(descriptionKey.computeHash(), WTF::DefaultHash<bool>::hash(coloredFont));226 }227 228 FontDescriptionKey descriptionKey;229 bool coloredFont { false };230 226 }; 231 227 232 228 struct FallbackFontDescriptionKeyHash { 233 static unsigned hash(const FallbackFontDescriptionKey& key) { return key.computeHash(); }229 static unsigned hash(const FallbackFontDescriptionKey& key) { return computeHash(key.descriptionKey, key.coloredFont); } 234 230 static bool equal(const FallbackFontDescriptionKey& a, const FallbackFontDescriptionKey& b) { return a == b; } 235 231 static const bool safeToCompareToEmptyOrDeleted = true; -
trunk/Source/WebCore/platform/graphics/mac/ComplexTextControllerCoreText.mm
r274252 r275650 186 186 ASSERT(runCTFont && CFGetTypeID(runCTFont) == CTFontGetTypeID()); 187 187 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())) { 189 189 // Begin trying to see if runFont matches any of the fonts in the fallback list. 190 190 for (unsigned i = 0; !m_font.fallbackRangesAt(i).isNull(); ++i) { … … 192 192 if (!runFont) 193 193 continue; 194 if ( WTF::safeCFEqual(runFont->platformData().objectForEqualityCheck().get(), runFontEqualityObject.get()))194 if (safeCFEqual(runFont->platformData().objectForEqualityCheck().get(), runFontEqualityObject.get())) 195 195 break; 196 196 runFont = nullptr; -
trunk/Source/WebCore/platform/graphics/win/FontCacheWin.cpp
r275364 r275650 339 339 if (hfont) { 340 340 if (!familyName.isEmpty()) { 341 FontPlatformData* result = getCachedFontPlatformData(description, familyName); 342 if (result) 341 if (auto result = cachedFontPlatformData(description, familyName)) 343 342 fontData = fontForPlatformData(*result); 344 343 } -
trunk/Source/WebCore/rendering/TextAutoSizing.h
r220685 r275650 109 109 }; 110 110 111 struct TextAutoSizingTraits : WTF::GenericHashTraits<TextAutoSizingKey> {111 struct TextAutoSizingTraits : HashTraits<TextAutoSizingKey> { 112 112 static const bool emptyValueIsZero = true; 113 113 static void constructDeletedValue(TextAutoSizingKey& slot) { new (NotNull, &slot) TextAutoSizingKey(TextAutoSizingKey::Deleted); } -
trunk/Source/WebCore/rendering/style/RenderStyle.cpp
r275607 r275650 450 450 static inline unsigned computeFontHash(const FontCascade& font) 451 451 { 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()); 456 454 } 457 455 -
trunk/Source/WebCore/workers/service/ServiceWorkerClientIdentifier.h
r264488 r275650 1 1 /* 2 * Copyright (C) 2017 Apple Inc. All rights reserved.2 * Copyright (C) 2017-2021 Apple Inc. All rights reserved. 3 3 * 4 4 * Redistribution and use in source and binary forms, with or without … … 30 30 #include "DocumentIdentifier.h" 31 31 #include "ServiceWorkerTypes.h" 32 #include <wtf/Hasher.h> 32 33 #include <wtf/text/StringConcatenateNumbers.h> 33 34 … … 88 89 return WTF::nullopt; 89 90 90 return { { WTFMove(*serverConnectionIdentifier), WTFMove(*contextIdentifier)} };91 return { { *serverConnectionIdentifier, *contextIdentifier } }; 91 92 } 92 93 93 94 inline unsigned ServiceWorkerClientIdentifier::hash() const 94 95 { 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); 100 97 } 101 98 -
trunk/Source/WebCore/workers/service/ServiceWorkerContextData.h
r275443 r275650 34 34 #include "WorkerType.h" 35 35 #include <wtf/HashMap.h> 36 #include <wtf/URL.h>37 36 #include <wtf/URLHash.h> 38 37 -
trunk/Source/WebCore/workers/service/ServiceWorkerGlobalScope.h
r275443 r275650 32 32 #include "ServiceWorkerRegistration.h" 33 33 #include "WorkerGlobalScope.h" 34 #include <wtf/URLHash.h> 34 35 35 36 namespace WebCore { -
trunk/Source/WebCore/workers/service/context/SWContextManager.h
r275443 r275650 35 35 #include <wtf/CompletionHandler.h> 36 36 #include <wtf/HashMap.h> 37 #include <wtf/URLHash.h> 37 38 38 39 namespace WebCore { -
trunk/Source/WebCore/workers/service/context/ServiceWorkerThreadProxy.h
r275443 r275650 40 40 #include "WorkerLoaderProxy.h" 41 41 #include <wtf/HashMap.h> 42 #include <wtf/URLHash.h> 42 43 43 44 namespace WebCore { -
trunk/Source/WebCore/workers/service/server/RegistrationStore.h
r275443 r275650 35 35 #include <wtf/CompletionHandler.h> 36 36 #include <wtf/HashMap.h> 37 #include <wtf/URLHash.h> 37 38 #include <wtf/WeakPtr.h> 38 39 #include <wtf/text/WTFString.h> -
trunk/Source/WebCore/workers/service/server/SWServer.h
r275465 r275650 46 46 #include <wtf/ThreadSafeRefCounted.h> 47 47 #include <wtf/Threading.h> 48 #include <wtf/URLHash.h> 48 49 #include <wtf/UniqueRef.h> 49 50 #include <wtf/WeakPtr.h> -
trunk/Source/WebCore/workers/service/server/SWServerToContextConnection.h
r275443 r275650 34 34 #include "ServiceWorkerIdentifier.h" 35 35 #include "ServiceWorkerTypes.h" 36 #include <wtf/URLHash.h> 36 37 37 38 namespace WebCore { -
trunk/Source/WebCore/workers/service/server/SWServerWorker.h
r275443 r275650 40 40 #include <wtf/CompletionHandler.h> 41 41 #include <wtf/RefCounted.h> 42 #include <wtf/URLHash.h> 42 43 #include <wtf/WeakPtr.h> 43 44 -
trunk/Source/WebKit/ChangeLog
r275645 r275650 1 2021-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 1 31 2021-04-07 Jer Noble <jer.noble@apple.com> 2 32 -
trunk/Source/WebKit/NetworkProcess/ServiceWorker/WebSWServerToContextConnection.h
r275443 r275650 33 33 #include "WebPageProxyIdentifier.h" 34 34 #include <WebCore/SWServerToContextConnection.h> 35 #include <wtf/URLHash.h> 35 36 #include <wtf/WeakPtr.h> 36 37 -
trunk/Source/WebKit/NetworkProcess/cache/NetworkCache.h
r264488 r275650 60 60 inline unsigned GlobalFrameID::hash() const 61 61 { 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); 67 63 } 68 64 … … 74 70 } 75 71 76 } ;77 } // namespace NetworkCache72 } 73 } 78 74 79 75 namespace WTF { -
trunk/Source/WebKit/Scripts/webkit/messages.py
r275103 r275650 670 670 'MonotonicTime': ['<wtf/MonotonicTime.h>'], 671 671 'Seconds': ['<wtf/Seconds.h>'], 672 'URL': ['<wtf/URLHash.h>'], 672 673 'WallTime': ['<wtf/WallTime.h>'], 673 674 'String': ['<wtf/text/WTFString.h>'], -
trunk/Source/WebKit/Shared/API/Cocoa/WKBrowsingContextHandle.mm
r273471 r275650 56 56 - (NSUInteger)hash 57 57 { 58 return WTF::pairIntHash(_pageProxyID.toUInt64(), _webPageID.toUInt64());58 return computeHash(_pageProxyID, _webPageID); 59 59 } 60 60 -
trunk/Source/WebKit/WebProcess/Storage/WebSWContextManagerConnection.h
r275443 r275650 38 38 #include <WebCore/ServiceWorkerClientData.h> 39 39 #include <WebCore/ServiceWorkerTypes.h> 40 #include <wtf/URLHash.h> 40 41 41 42 namespace IPC { -
trunk/Source/WebKitLegacy/mac/ChangeLog
r275327 r275650 1 2021-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 1 10 2021-03-31 Chris Dumez <cdumez@apple.com> 2 11 -
trunk/Source/WebKitLegacy/mac/History/BinaryPropertyList.cpp
r235886 r275650 76 76 } 77 77 78 struct IntegerArrayHashTraits : WTF::GenericHashTraits<IntegerArray> {78 struct IntegerArrayHashTraits : HashTraits<IntegerArray> { 79 79 static void constructDeletedValue(IntegerArray& slot) { slot.markDeleted(); } 80 80 static bool isDeletedValue(const IntegerArray& array) { return array.isDeletedValue(); }
Note: See TracChangeset
for help on using the changeset viewer.