[NFC][sanitizer] Lazy init in StackDepotReverseMap

This commit is contained in:
Vitaly Buka 2021-09-30 19:10:20 -07:00
parent fcdefc8575
commit 548aa9022e
2 changed files with 8 additions and 3 deletions

View File

@ -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};

View File

@ -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<IdDescPair> map_;
void Init() const;
mutable InternalMmapVector<IdDescPair> map_;
// Disallow evil constructors.
StackDepotReverseMap(const StackDepotReverseMap&);