Branch: refs/heads/main
Home: https://github.com/WebKit/WebKit
Commit: f7a9d16e1531496bbe9d20952252b0d28aa56061
https://github.com/WebKit/WebKit/commit/f7a9d16e1531496bbe9d20952252b0d28aa56061
Author: David Kilzer <[email protected]>
Date: 2026-07-31 (Fri, 31 Jul 2026)
Changed paths:
M Source/WTF/wtf/WeakHashSet.h
M Source/WTF/wtf/WeakListHashSet.h
M Source/WebCore/Modules/gamepad/GamepadManager.cpp
M Source/WebCore/Modules/indexeddb/IDBObjectStore.cpp
M Source/WebCore/Modules/indexeddb/IDBTransaction.cpp
M Source/WebCore/Modules/indexeddb/server/IndexValueStore.cpp
M Source/WebCore/animation/StyleOriginatedTimelinesController.cpp
M Source/WebCore/loader/cache/CachedResourceLoader.cpp
M Source/WebCore/platform/graphics/cg/CGSubimageCacheWithTimer.cpp
M Source/WebCore/rendering/RenderView.cpp
M Source/WebKit/NetworkProcess/NetworkBroadcastChannelRegistry.cpp
M Source/WebKit/NetworkProcess/storage/CacheStorageManager.cpp
M Source/WebKit/UIProcess/WebBackForwardCache.cpp
M Source/WebKit/UIProcess/WebProcessCache.cpp
M Source/WebKit/WebProcess/WebPage/WebFoundTextRangeController.cpp
M Tools/TestWebKitAPI/Tests/WTF/WeakPtr.cpp
Log Message:
-----------
Add removeIf() to WeakHashSet and WeakListHashSet and adopt it to simplify
more remove-matching-entries loops
<https://bugs.webkit.org/show_bug.cgi?id=320324>
<rdar://183264359>
Reviewed by Darin Adler, Abrar Rahman Protyasha, and Zak Ridouh.
Follow-up to 317934@main, which implemented the same optimization
at sites whose predicate was a pure function of the element. The
sites converted here additionally perform a per-element side effect (a
release log, a secondary-container update, or `std::exchange`
bookkeeping). Because `removeIf()` visits each live entry exactly once,
the side effect moves into the lambda unchanged, eliminating the
temporary storage and the second traversal.
One candidate, `WebBackForwardCache::removeEntriesMatching()`, is
intentionally left as a two-pass loop: its side effect can destroy a
`SuspendedPageProxy` whose teardown re-enters the cache and mutates the
container, which a single-pass `removeIf()` would do mid-iteration.
Add `removeIf()` to `WeakHashSet` and `WeakListHashSet` so that call
sites backed by those weak containers can use the same single-pass
algorithm. `HashMap`, `HashSet`, `ListHashSet`, and `WeakHashMap`
already provide it; the two additions delegate to the underlying
container's `removeIf()`, drop dead (null) weak references without
invoking the predicate, and then run the amortized cleanup, matching
`WeakHashMap::removeIf()`.
Where the predicate reads a member guarded by a lock, the lambda calls
`assertIsHeld()` because the Clang thread-safety analyzer does not carry
the caller's lock state into a lambda body.
Tests: WTF_WeakPtr.WeakHashSetRemoveIf
WTF_WeakPtr.WeakListHashSetRemoveIf
* Source/WTF/wtf/WeakHashSet.h:
(WTF::WeakHashSet::removeIf): Add.
* Source/WTF/wtf/WeakListHashSet.h:
(WTF::WeakListHashSet::removeIf): Add.
* Source/WebCore/Modules/gamepad/GamepadManager.cpp:
(WebCore::GamepadManager::updateQuarantineStatus):
* Source/WebCore/Modules/indexeddb/IDBObjectStore.cpp:
(WebCore::IDBObjectStore::rollbackForVersionChangeAbort):
* Source/WebCore/Modules/indexeddb/IDBTransaction.cpp:
(WebCore::IDBTransaction::abortInternal):
* Source/WebCore/Modules/indexeddb/server/IndexValueStore.cpp:
(WebCore::IDBServer::IndexValueStore::removeEntriesWithValueKey):
* Source/WebCore/animation/StyleOriginatedTimelinesController.cpp:
(WebCore::StyleOriginatedTimelinesController::unregisterNamedTimelinesAssociatedWithElement):
* Source/WebCore/loader/cache/CachedResourceLoader.cpp:
(WebCore::CachedResourceLoader::garbageCollectDocumentResources):
* Source/WebCore/platform/graphics/cg/CGSubimageCacheWithTimer.cpp:
(WebCore::CGSubimageCacheWithTimer::prune):
* Source/WebCore/rendering/RenderView.cpp:
(WebCore::RenderView::resumePausedImageAnimationsIfNeeded):
* Source/WebKit/NetworkProcess/NetworkBroadcastChannelRegistry.cpp:
(WebKit::NetworkBroadcastChannelRegistry::removeConnection):
* Source/WebKit/NetworkProcess/storage/CacheStorageManager.cpp:
(WebKit::CacheStorageManager::connectionClosed):
* Source/WebKit/UIProcess/WebBackForwardCache.cpp:
(WebKit::WebBackForwardCache::removeEntriesMatching):
- Document why removeIf() can't be used.
* Source/WebKit/UIProcess/WebProcessCache.cpp:
(WebKit::WebProcessCache::clearAllProcessesForSession):
* Source/WebKit/WebProcess/WebPage/WebFoundTextRangeController.cpp:
(WebKit::WebFoundTextRangeController::decorateTextRangeWithStyle):
* Tools/TestWebKitAPI/Tests/WTF/WeakPtr.cpp:
(TestWebKitAPI::TEST(WTF_WeakPtr, WeakHashSetRemoveIf)): Add.
(TestWebKitAPI::TEST(WTF_WeakPtr, WeakListHashSetRemoveIf)): Add.
Canonical link: https://commits.webkit.org/318341@main
To unsubscribe from these emails, change your notification settings at
https://github.com/WebKit/WebKit/settings/notifications