Skip to content

HashTable doesn't need ShouldValidateKey as template parameter for the whole class#45555

Merged
webkit-commit-queue merged 1 commit into
WebKit:mainfrom
cdumez:293190_HashTable_ShouldValidateKey
May 18, 2025
Merged

HashTable doesn't need ShouldValidateKey as template parameter for the whole class#45555
webkit-commit-queue merged 1 commit into
WebKit:mainfrom
cdumez:293190_HashTable_ShouldValidateKey

Conversation

@cdumez
Copy link
Copy Markdown
Contributor

@cdumez cdumez commented May 17, 2025

a8416d2

HashTable doesn't need `ShouldValidateKey` as template parameter for the whole class
https://bugs.webkit.org/show_bug.cgi?id=293190

Reviewed by Geoffrey Garen and Darin Adler.

HashTable doesn't need `ShouldValidateKey` as template parameter for the whole
class. Instead, only add this template parameter for HashTable functions that
actually need it. This reduces unnecessary code duplication, reduces binary
size in WebCore by 1MB and avoids redundant key validations since we can now
be more fine-grained.

Also extract `checkKey` out of HashTable to reduce template-related duplication.
This reduces the binary size for WebKit by 1MB.

* Source/WTF/wtf/Forward.h:
* Source/WTF/wtf/HashMap.h:
(WTF::M>::find):
(WTF::M>::find const):
(WTF::M>::contains const):
(WTF::M>::get const):
(WTF::M>::inlineGet const):
(WTF::M>::inlineAdd):
(WTF::M>::inlineEnsure):
(WTF::M>::ensure):
(WTF::M>::add):
(WTF::M>::getOptional const):
* Source/WTF/wtf/HashSet.h:
(WTF::shouldValidateKey>::find const):
(WTF::shouldValidateKey>::contains const):
(WTF::shouldValidateKey>::ensure):
(WTF::shouldValidateKey>::add):
(WTF::shouldValidateKey>::addVoid):
* Source/WTF/wtf/HashTable.h:
(WTF::HashTable::add):
(WTF::HashTable::find):
(WTF::HashTable::find const):
(WTF::HashTable::contains const):
(WTF::HashTable::lookup):
(WTF::Malloc>::HashTable):
(WTF::Malloc>::checkKey):
(WTF::Malloc>::lookup):
(WTF::Malloc>::inlineLookup):
(WTF::Malloc>::lookupForReinsert):
(WTF::Malloc>::fullLookupForWriting):
(WTF::Malloc>::addUniqueForInitialization):
(WTF::Malloc>::initializeBucket):
(WTF::Malloc>::add):
(WTF::Malloc>::addPassingHashCode):
(WTF::Malloc>::reinsert):
(WTF::Malloc>::find):
(WTF::Malloc>::find const):
(WTF::Malloc>::contains const):
(WTF::Malloc>::removeAndInvalidateWithoutEntryConsistencyCheck):
(WTF::Malloc>::removeAndInvalidate):
(WTF::Malloc>::remove):
(WTF::Malloc>::removeWithoutEntryConsistencyCheck):
(WTF::Malloc>::removeIf):
(WTF::Malloc>::takeIf):
(WTF::Malloc>::allocateTable):
(WTF::Malloc>::deallocateTable):
(WTF::Malloc>::expand):
(WTF::Malloc>::computeBestTableSize):
(WTF::Malloc>::shrinkToBestSize):
(WTF::Malloc>::deleteReleasedWeakBuckets):
(WTF::Malloc>::rehash):
(WTF::Malloc>::clear):
(WTF::Malloc>::swap):
(WTF::=):
(WTF::Malloc>::checkTableConsistency const):
(WTF::Malloc>::checkTableConsistencyExceptSize const):
* Source/WTF/wtf/ListHashSet.h:
(WTF::U>::takeFirst):
(WTF::U>::takeLast):
(WTF::U>::find):
(WTF::U>::find const):
(WTF::U>::contains const):
(WTF::U>::add):
(WTF::U>::appendOrMoveToLast):
(WTF::U>::moveToLastIfPresent):
(WTF::U>::prependOrMoveToFirst):
(WTF::U>::insertBefore):
(WTF::U>::remove):
* Source/WTF/wtf/RobinHoodHashTable.h:
(WTF::RobinHoodHashTable::add):
(WTF::RobinHoodHashTable::find):
(WTF::RobinHoodHashTable::find const):
(WTF::RobinHoodHashTable::contains const):
(WTF::RobinHoodHashTable::lookup):
(WTF::Malloc>::checkKey):
(WTF::Malloc>::lookup):
(WTF::Malloc>::inlineLookup):
(WTF::Malloc>::initializeBucket):
(WTF::Malloc>::add):
(WTF::Malloc>::maintainProbeDistanceForAdd):
(WTF::Malloc>::addPassingHashCode):
(WTF::Malloc>::reinsert):
(WTF::Malloc>::find):
(WTF::Malloc>::find const):
(WTF::Malloc>::contains const):
(WTF::Malloc>::removeAndInvalidateWithoutEntryConsistencyCheck):
(WTF::Malloc>::removeAndInvalidate):
(WTF::Malloc>::remove):
(WTF::Malloc>::removeWithoutEntryConsistencyCheck):
(WTF::Malloc>::allocateTable):
(WTF::Malloc>::deallocateTable):
(WTF::Malloc>::expand):
(WTF::Malloc>::computeBestTableSize):
(WTF::Malloc>::shrinkToBestSize):
(WTF::Malloc>::rehash):
(WTF::Malloc>::clear):
(WTF::Malloc>::RobinHoodHashTable):
(WTF::Malloc>::swap):
(WTF::=):
(WTF::Malloc>::checkTableConsistency const):
(WTF::Malloc>::checkTableConsistencyExceptSize const):

Canonical link: https://commits.webkit.org/295078@main

21c5fce

Misc iOS, visionOS, tvOS & watchOS macOS Linux Windows
❌ 🧪 style ✅ 🛠 ios ✅ 🛠 mac ✅ 🛠 wpe ✅ 🛠 win
✅ 🛠 ios-sim ✅ 🛠 mac-AS-debug ✅ 🧪 wpe-wk2 ⏳ 🧪 win-tests
✅ 🧪 webkitperl ✅ 🧪 ios-wk2 ✅ 🧪 api-mac ✅ 🧪 api-wpe
❌ 🧪 ios-wk2-wpt ✅ 🧪 mac-wk1 ✅ 🛠 wpe-cairo
✅ 🛠 🧪 jsc ❌ 🧪 api-ios ✅ 🧪 mac-wk2 ✅ 🛠 gtk
✅ 🛠 🧪 jsc-arm64 ✅ 🛠 vision ✅ 🧪 mac-AS-debug-wk2 ✅ 🧪 gtk-wk2
✅ 🛠 vision-sim ✅ 🧪 mac-wk2-stress ✅ 🧪 api-gtk
✅ 🛠 🧪 merge ✅ 🧪 vision-wk2 ✅ 🧪 mac-intel-wk2 ✅ 🛠 playstation
✅ 🛠 tv ✅ 🛠 mac-safer-cpp ✅ 🛠 jsc-armv7
✅ 🛠 tv-sim ✅ 🧪 jsc-armv7-tests
✅ 🛠 watch
✅ 🛠 watch-sim

@cdumez cdumez self-assigned this May 17, 2025
@cdumez cdumez force-pushed the 293190_HashTable_ShouldValidateKey branch from 91e9207 to 21c5fce Compare May 18, 2025 04:28
@cdumez cdumez marked this pull request as ready for review May 18, 2025 05:31
@webkit-ews-buildbot webkit-ews-buildbot added the merging-blocked Applied to prevent a change from being merged label May 18, 2025
@cdumez cdumez added merge-queue Applied to send a pull request to merge-queue and removed merging-blocked Applied to prevent a change from being merged labels May 18, 2025
…the whole class

https://bugs.webkit.org/show_bug.cgi?id=293190

Reviewed by Geoffrey Garen and Darin Adler.

HashTable doesn't need `ShouldValidateKey` as template parameter for the whole
class. Instead, only add this template parameter for HashTable functions that
actually need it. This reduces unnecessary code duplication, reduces binary
size in WebCore by 1MB and avoids redundant key validations since we can now
be more fine-grained.

Also extract `checkKey` out of HashTable to reduce template-related duplication.
This reduces the binary size for WebKit by 1MB.

* Source/WTF/wtf/Forward.h:
* Source/WTF/wtf/HashMap.h:
(WTF::M>::find):
(WTF::M>::find const):
(WTF::M>::contains const):
(WTF::M>::get const):
(WTF::M>::inlineGet const):
(WTF::M>::inlineAdd):
(WTF::M>::inlineEnsure):
(WTF::M>::ensure):
(WTF::M>::add):
(WTF::M>::getOptional const):
* Source/WTF/wtf/HashSet.h:
(WTF::shouldValidateKey>::find const):
(WTF::shouldValidateKey>::contains const):
(WTF::shouldValidateKey>::ensure):
(WTF::shouldValidateKey>::add):
(WTF::shouldValidateKey>::addVoid):
* Source/WTF/wtf/HashTable.h:
(WTF::HashTable::add):
(WTF::HashTable::find):
(WTF::HashTable::find const):
(WTF::HashTable::contains const):
(WTF::HashTable::lookup):
(WTF::Malloc>::HashTable):
(WTF::Malloc>::checkKey):
(WTF::Malloc>::lookup):
(WTF::Malloc>::inlineLookup):
(WTF::Malloc>::lookupForReinsert):
(WTF::Malloc>::fullLookupForWriting):
(WTF::Malloc>::addUniqueForInitialization):
(WTF::Malloc>::initializeBucket):
(WTF::Malloc>::add):
(WTF::Malloc>::addPassingHashCode):
(WTF::Malloc>::reinsert):
(WTF::Malloc>::find):
(WTF::Malloc>::find const):
(WTF::Malloc>::contains const):
(WTF::Malloc>::removeAndInvalidateWithoutEntryConsistencyCheck):
(WTF::Malloc>::removeAndInvalidate):
(WTF::Malloc>::remove):
(WTF::Malloc>::removeWithoutEntryConsistencyCheck):
(WTF::Malloc>::removeIf):
(WTF::Malloc>::takeIf):
(WTF::Malloc>::allocateTable):
(WTF::Malloc>::deallocateTable):
(WTF::Malloc>::expand):
(WTF::Malloc>::computeBestTableSize):
(WTF::Malloc>::shrinkToBestSize):
(WTF::Malloc>::deleteReleasedWeakBuckets):
(WTF::Malloc>::rehash):
(WTF::Malloc>::clear):
(WTF::Malloc>::swap):
(WTF::=):
(WTF::Malloc>::checkTableConsistency const):
(WTF::Malloc>::checkTableConsistencyExceptSize const):
* Source/WTF/wtf/ListHashSet.h:
(WTF::U>::takeFirst):
(WTF::U>::takeLast):
(WTF::U>::find):
(WTF::U>::find const):
(WTF::U>::contains const):
(WTF::U>::add):
(WTF::U>::appendOrMoveToLast):
(WTF::U>::moveToLastIfPresent):
(WTF::U>::prependOrMoveToFirst):
(WTF::U>::insertBefore):
(WTF::U>::remove):
* Source/WTF/wtf/RobinHoodHashTable.h:
(WTF::RobinHoodHashTable::add):
(WTF::RobinHoodHashTable::find):
(WTF::RobinHoodHashTable::find const):
(WTF::RobinHoodHashTable::contains const):
(WTF::RobinHoodHashTable::lookup):
(WTF::Malloc>::checkKey):
(WTF::Malloc>::lookup):
(WTF::Malloc>::inlineLookup):
(WTF::Malloc>::initializeBucket):
(WTF::Malloc>::add):
(WTF::Malloc>::maintainProbeDistanceForAdd):
(WTF::Malloc>::addPassingHashCode):
(WTF::Malloc>::reinsert):
(WTF::Malloc>::find):
(WTF::Malloc>::find const):
(WTF::Malloc>::contains const):
(WTF::Malloc>::removeAndInvalidateWithoutEntryConsistencyCheck):
(WTF::Malloc>::removeAndInvalidate):
(WTF::Malloc>::remove):
(WTF::Malloc>::removeWithoutEntryConsistencyCheck):
(WTF::Malloc>::allocateTable):
(WTF::Malloc>::deallocateTable):
(WTF::Malloc>::expand):
(WTF::Malloc>::computeBestTableSize):
(WTF::Malloc>::shrinkToBestSize):
(WTF::Malloc>::rehash):
(WTF::Malloc>::clear):
(WTF::Malloc>::RobinHoodHashTable):
(WTF::Malloc>::swap):
(WTF::=):
(WTF::Malloc>::checkTableConsistency const):
(WTF::Malloc>::checkTableConsistencyExceptSize const):

Canonical link: https://commits.webkit.org/295078@main
@webkit-commit-queue webkit-commit-queue force-pushed the 293190_HashTable_ShouldValidateKey branch from 21c5fce to a8416d2 Compare May 18, 2025 18:06
@webkit-commit-queue
Copy link
Copy Markdown
Collaborator

Committed 295078@main (a8416d2): https://commits.webkit.org/295078@main

Reviewed commits have been landed. Closing PR #45555 and removing active labels.

@webkit-commit-queue webkit-commit-queue merged commit a8416d2 into WebKit:main May 18, 2025
@webkit-commit-queue webkit-commit-queue removed the merge-queue Applied to send a pull request to merge-queue label May 18, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants