From 490ee515a66b15dfcaa096c6f42ae5d97fa907ca Mon Sep 17 00:00:00 2001 From: Vaibhav Gogte CA Date: Wed, 23 Sep 2026 15:16:00 -0700 Subject: [PATCH] Shrink sizes of per-size-class misses and overall cache misses from std::atomic down to std::atomic. Since differences are computed with unsigned arithmetic wrapping and returned as size_t or handled correctly in comparisons, wrap around behaviors evaluate correctly and perfectly safe. PiperOrigin-RevId: 987036273 --- tcmalloc/cpu_cache.h | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/tcmalloc/cpu_cache.h b/tcmalloc/cpu_cache.h index 1a34c2dc5..de1ee04d7 100644 --- a/tcmalloc/cpu_cache.h +++ b/tcmalloc/cpu_cache.h @@ -528,10 +528,10 @@ class CpuCache { using Freelist = subtle::percpu::TcmallocSlab; struct PerClassMissCounts { - std::atomic + std::atomic misses[static_cast(PerClassMissType::kNumTypes)]; - std::atomic& operator[](PerClassMissType type) { + std::atomic& operator[](PerClassMissType type) { return misses[static_cast(type)]; } }; @@ -588,9 +588,9 @@ class CpuCache { // Helper type so we don't need to sprinkle `static_cast`s everywhere. struct MissCounts { - std::atomic misses[static_cast(MissCount::kNumCounts)]; + std::atomic misses[static_cast(MissCount::kNumCounts)]; - std::atomic& operator[](MissCount miss_count) { + std::atomic& operator[](MissCount miss_count) { return misses[static_cast(miss_count)]; } };