From 548aa9022ee79a95a07b99a88df28cee6cb0e16d Mon Sep 17 00:00:00 2001 From: Vitaly Buka Date: Thu, 30 Sep 2021 19:10:20 -0700 Subject: [PATCH] [NFC][sanitizer] Lazy init in StackDepotReverseMap --- compiler-rt/lib/sanitizer_common/sanitizer_stackdepot.cpp | 5 ++++- compiler-rt/lib/sanitizer_common/sanitizer_stackdepot.h | 6 ++++-- 2 files changed, 8 insertions(+), 3 deletions(-) diff --git a/compiler-rt/lib/sanitizer_common/sanitizer_stackdepot.cpp b/compiler-rt/lib/sanitizer_common/sanitizer_stackdepot.cpp index 9215867..c71b0a1 100644 --- a/compiler-rt/lib/sanitizer_common/sanitizer_stackdepot.cpp +++ b/compiler-rt/lib/sanitizer_common/sanitizer_stackdepot.cpp @@ -125,7 +125,9 @@ bool StackDepotReverseMap::IdDescPair::IdComparator( return a.id < b.id; } -StackDepotReverseMap::StackDepotReverseMap() { +void StackDepotReverseMap::Init() const { + if (LIKELY(map_.capacity())) + return; map_.reserve(StackDepotGetStats().n_uniq_ids + 100); for (int idx = 0; idx < StackDepot::kTabSize; idx++) { atomic_uintptr_t *p = &theDepot.tab[idx]; @@ -140,6 +142,7 @@ StackDepotReverseMap::StackDepotReverseMap() { } StackTrace StackDepotReverseMap::Get(u32 id) const { + Init(); if (!map_.size()) return StackTrace(); IdDescPair pair = {id, nullptr}; diff --git a/compiler-rt/lib/sanitizer_common/sanitizer_stackdepot.h b/compiler-rt/lib/sanitizer_common/sanitizer_stackdepot.h index d4c2ee3..6f79fff 100644 --- a/compiler-rt/lib/sanitizer_common/sanitizer_stackdepot.h +++ b/compiler-rt/lib/sanitizer_common/sanitizer_stackdepot.h @@ -49,7 +49,7 @@ void StackDepotPrintAll(); // which were stored before it was instantiated. class StackDepotReverseMap { public: - StackDepotReverseMap(); + StackDepotReverseMap() = default; StackTrace Get(u32 id) const; private: @@ -60,7 +60,9 @@ class StackDepotReverseMap { static bool IdComparator(const IdDescPair &a, const IdDescPair &b); }; - InternalMmapVector map_; + void Init() const; + + mutable InternalMmapVector map_; // Disallow evil constructors. StackDepotReverseMap(const StackDepotReverseMap&); -- 2.7.4