From 479c566771d6464785f205a368701c689e094fe5 Mon Sep 17 00:00:00 2001 From: Siying Dong Date: Fri, 5 Apr 2019 16:05:10 -0700 Subject: [PATCH] Add final annotations to some cache functions (#5156) Summary: cache functions heavily use virtual functions. Add some "final" annotations to give compilers more information to optimize. The compiler doesn't seem to take advantage of it though. But it doesn't hurt. Pull Request resolved: https://github.com/facebook/rocksdb/pull/5156 Differential Revision: D14814837 Pulled By: siying fbshipit-source-id: 4423f58eafc93f7dd3c5f04b02b5c993dba2ea94 --- cache/clock_cache.cc | 4 ++-- cache/lru_cache.h | 8 ++++++-- 2 files changed, 8 insertions(+), 4 deletions(-) diff --git a/cache/clock_cache.cc b/cache/clock_cache.cc index 3fa4c3659..89173834e 100644 --- a/cache/clock_cache.cc +++ b/cache/clock_cache.cc @@ -234,7 +234,7 @@ struct CleanupContext { }; // A cache shard which maintains its own CLOCK cache. -class ClockCacheShard : public CacheShard { +class ClockCacheShard final : public CacheShard { public: // Hash map type. typedef tbb::concurrent_hash_map HashTable; @@ -672,7 +672,7 @@ void ClockCacheShard::EraseUnRefEntries() { Cleanup(context); } -class ClockCache : public ShardedCache { +class ClockCache final : public ShardedCache { public: ClockCache(size_t capacity, int num_shard_bits, bool strict_capacity_limit) : ShardedCache(capacity, num_shard_bits, strict_capacity_limit) { diff --git a/cache/lru_cache.h b/cache/lru_cache.h index 665a97a5c..0d9a31748 100644 --- a/cache/lru_cache.h +++ b/cache/lru_cache.h @@ -165,7 +165,7 @@ class LRUHandleTable { }; // A single shard of sharded cache. -class ALIGN_AS(CACHE_LINE_SIZE) LRUCacheShard : public CacheShard { +class ALIGN_AS(CACHE_LINE_SIZE) LRUCacheShard final : public CacheShard { public: LRUCacheShard(size_t capacity, bool strict_capacity_limit, double high_pri_pool_ratio, bool use_adaptive_mutex); @@ -284,7 +284,11 @@ class ALIGN_AS(CACHE_LINE_SIZE) LRUCacheShard : public CacheShard { mutable port::Mutex mutex_; }; -class LRUCache : public ShardedCache { +class LRUCache +#ifdef NDEBUG + final +#endif + : public ShardedCache { public: LRUCache(size_t capacity, int num_shard_bits, bool strict_capacity_limit, double high_pri_pool_ratio,