Branch: refs/heads/main
  Home:   https://github.com/WebKit/WebKit
  Commit: 9b4ffe1f77999658bdda22d8b76dee99fa6e5c7c
      
https://github.com/WebKit/WebKit/commit/9b4ffe1f77999658bdda22d8b76dee99fa6e5c7c
  Author: Justin Michaud <[email protected]>
  Date:   2026-06-30 (Tue, 30 Jun 2026)

  Changed paths:
    M Source/WTF/wtf/TinyLRUCache.h
    M Tools/TestWebKitAPI/CMakeLists.txt
    A Tools/TestWebKitAPI/Tests/WTF/TinyLRUCache.cpp

  Log Message:
  -----------
  Add findIfCached / insert to TinyLRUCache
https://bugs.webkit.org/show_bug.cgi?id=314417

Reviewed by Keith Miller.

This is useful for cases when you need to cache something that can't
created statically.

We also add a generated test to gently exercise this new code.

We also add a new safe iterator mechanism to ensure that this new API
can't be used unsafely.

* Source/WTF/wtf/TinyLRUCache.h:
(WTF::TinyLRUCache::~TinyLRUCache):
(WTF::TinyLRUCache::TinyLRUCache):
(WTF::TinyLRUCache::operator=):
(WTF::TinyLRUCache::FindResult::~FindResult):
(WTF::TinyLRUCache::FindResult::operator bool const):
(WTF::TinyLRUCache::FindResult::operator* const):
(WTF::TinyLRUCache::FindResult::operator-> const):
(WTF::TinyLRUCache::FindResult::FindResult):
(WTF::TinyLRUCache::FindResult::assertValid const):
(WTF::TinyLRUCache::get):
(WTF::TinyLRUCache::findIfCached):
(WTF::TinyLRUCache::insert):
(WTF::TinyLRUCache::clear):
(WTF::TinyLRUCache::size const):
(WTF::TinyLRUCache::trackFindResult):
(WTF::TinyLRUCache::invalidateIterators):
(WTF::TinyLRUCache::findInternal):
(WTF::TinyLRUCache::insertInternal):
* Tools/TestWebKitAPI/CMakeLists.txt:
* Tools/TestWebKitAPI/Tests/WTF/TinyLRUCache.cpp: Added.
(TestWebKitAPI::CountingPolicy::createValueForKey):
(TestWebKitAPI::TEST(WTF_TinyLRUCache, GetCachesOnHit)):
(TestWebKitAPI::TEST(WTF_TinyLRUCache, GetEvictsLRU)):
(TestWebKitAPI::NullKeyPolicy::isKeyNull):
(TestWebKitAPI::NullKeyPolicy::createValueForNullKey):
(TestWebKitAPI::NullKeyPolicy::createValueForKey):
(TestWebKitAPI::TEST(WTF_TinyLRUCache, 
GetWithNullKeyReturnsNullValueAndDoesNotStore)):
(TestWebKitAPI::TEST(WTF_TinyLRUCache, FindIfCachedReturnsNullOnMiss)):
(TestWebKitAPI::TEST(WTF_TinyLRUCache, FindIfCachedHitsAfterInsert)):
(TestWebKitAPI::TEST(WTF_TinyLRUCache, InsertEvictsLRU)):
(TestWebKitAPI::TEST(WTF_TinyLRUCache, FindIfCachedPromotesToMRU)):
(TestWebKitAPI::TEST(WTF_TinyLRUCache, ClearReleasesEntriesAndResetsSize)):
(TestWebKitAPI::TrackedRefCounted::create):
(TestWebKitAPI::TrackedRefCounted::value const):
(TestWebKitAPI::TrackedRefCounted::~TrackedRefCounted):
(TestWebKitAPI::TrackedRefCounted::TrackedRefCounted):
(TestWebKitAPI::TEST(WTF_TinyLRUCache, ClearReleasesRefsImmediately)):
(TestWebKitAPI::TEST(WTF_TinyLRUCache, EvictionViaInsertReleasesRef)):
(TestWebKitAPI::TEST(WTF_TinyLRUCache, FindIfCachedDoesNotConsumeEntry)):
(TestWebKitAPI::TEST(WTF_TinyLRUCache, FindIfCachedAfterClearMisses)):
(TestWebKitAPI::TEST(WTF_TinyLRUCache, FindOrComputeWorkflow)):
(TestWebKitAPI::TEST(WTF_TinyLRUCache, FindResultSafeAfterCacheDestroyed)):
(TestWebKitAPI::TEST(WTF_TinyLRUCache, InsertInvalidatesFindResult)):
(TestWebKitAPI::TEST(WTF_TinyLRUCache, ClearInvalidatesFindResult)):
(TestWebKitAPI::TEST(WTF_TinyLRUCache, 
SubsequentFindInvalidatesPriorFindResult)):
(TestWebKitAPI::TEST(WTF_TinyLRUCacheDeathTest, UseAfterInsertDeathTest)):
(TestWebKitAPI::TEST(WTF_TinyLRUCacheDeathTest, UseAfterClearDeathTest)):
(TestWebKitAPI::TEST(WTF_TinyLRUCacheDeathTest, 
UseAfterSubsequentFindDeathTest)):

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



To unsubscribe from these emails, change your notification settings at 
https://github.com/WebKit/WebKit/settings/notifications

Reply via email to