From 67753c43824b81b747d00806e10fe7e8cad89f33 Mon Sep 17 00:00:00 2001 From: Simon Giesecke Date: Tue, 23 Mar 2021 10:36:32 +0000 Subject: [PATCH] Bug 708901 - Migrate to nsTHashSet in toolkit/components/telemetry/core. r=chutten Depends on D106950 Differential Revision: https://phabricator.services.mozilla.com/D107686 --- .../components/telemetry/core/Telemetry.cpp | 3 +-- .../telemetry/core/TelemetryCommon.h | 4 ++- .../telemetry/core/TelemetryEvent.cpp | 26 +++++++++---------- .../telemetry/core/TelemetryHistogram.cpp | 2 +- .../telemetry/core/TelemetryScalar.cpp | 4 +-- 5 files changed, 20 insertions(+), 19 deletions(-) diff --git a/toolkit/components/telemetry/core/Telemetry.cpp b/toolkit/components/telemetry/core/Telemetry.cpp index fbeebb009ef6..abf018e59de2 100644 --- a/toolkit/components/telemetry/core/Telemetry.cpp +++ b/toolkit/components/telemetry/core/Telemetry.cpp @@ -1731,8 +1731,7 @@ TelemetryImpl::GetAllStores(JSContext* aCx, JS::MutableHandleValue aResult) { return NS_ERROR_FAILURE; } - for (auto iter = stores.Iter(); !iter.Done(); iter.Next()) { - auto& value = iter.Get()->GetKey(); + for (const auto& value : stores) { JS::RootedValue store(aCx); store.setString(ToJSString(aCx, value)); diff --git a/toolkit/components/telemetry/core/TelemetryCommon.h b/toolkit/components/telemetry/core/TelemetryCommon.h index 5af8f7f0cd93..fd126e72fd51 100644 --- a/toolkit/components/telemetry/core/TelemetryCommon.h +++ b/toolkit/components/telemetry/core/TelemetryCommon.h @@ -9,7 +9,9 @@ #include "jsapi.h" #include "mozilla/TypedEnumBits.h" #include "mozilla/TelemetryProcessEnums.h" +#include "nsHashtablesFwd.h" #include "nsIScriptError.h" +#include "nsTHashSet.h" #include "nsTHashtable.h" #include "nsHashKeys.h" #include "nsXULAppAPI.h" @@ -18,7 +20,7 @@ namespace mozilla { namespace Telemetry { namespace Common { -typedef nsTHashtable StringHashSet; +typedef nsTHashSet StringHashSet; enum class RecordedProcessType : uint16_t { Main = (1 << GeckoProcessType_Default), // Also known as "parent process" diff --git a/toolkit/components/telemetry/core/TelemetryEvent.cpp b/toolkit/components/telemetry/core/TelemetryEvent.cpp index 3ca3c445ddf5..040262cf5d86 100644 --- a/toolkit/components/telemetry/core/TelemetryEvent.cpp +++ b/toolkit/components/telemetry/core/TelemetryEvent.cpp @@ -288,10 +288,10 @@ bool gCanRecordExtended; nsClassHashtable gEventNameIDMap(kEventCount); // The CategoryName set. -nsTHashtable gCategoryNames; +nsTHashSet gCategoryNames; // This tracks the IDs of the categories for which recording is enabled. -nsTHashtable gEnabledCategories; +nsTHashSet gEnabledCategories; // The main event storage. Events are inserted here, keyed by process id and // in recording order. @@ -386,21 +386,21 @@ EventKey* GetEventKey(const StaticMutexAutoLock& lock, static bool CheckExtraKeysValid(const EventKey& eventKey, const ExtraArray& extra) { - nsTHashtable validExtraKeys; + nsTHashSet validExtraKeys; if (!eventKey.dynamic) { const CommonEventInfo& common = gEventInfo[eventKey.id].common_info; for (uint32_t i = 0; i < common.extra_count; ++i) { - validExtraKeys.PutEntry(common.extra_key(i)); + validExtraKeys.Insert(common.extra_key(i)); } } else if (gDynamicEventInfo) { const DynamicEventInfo& info = (*gDynamicEventInfo)[eventKey.id]; for (uint32_t i = 0, len = info.extra_keys.Length(); i < len; ++i) { - validExtraKeys.PutEntry(info.extra_keys[i]); + validExtraKeys.Insert(info.extra_keys[i]); } } for (uint32_t i = 0; i < extra.Length(); ++i) { - if (!validExtraKeys.GetEntry(extra[i].key)) { + if (!validExtraKeys.Contains(extra[i].key)) { return false; } } @@ -459,7 +459,7 @@ RecordEventResult RecordEvent(const StaticMutexAutoLock& lock, processType, dynamicNonBuiltin); // Check whether this event's category has recording enabled - if (!gEnabledCategories.GetEntry(GetCategory(lock, *eventKey))) { + if (!gEnabledCategories.Contains(GetCategory(lock, *eventKey))) { return RecordEventResult::Ok; } @@ -537,13 +537,13 @@ void RegisterEvents(const StaticMutexAutoLock& lock, const nsACString& category, // If it is a builtin, add the category name in order to enable it later. if (aBuiltin) { - gCategoryNames.PutEntry(category); + gCategoryNames.Insert(category); } if (!aBuiltin) { // Now after successful registration enable recording for this category // (if not a dynamic builtin). - gEnabledCategories.PutEntry(category); + gEnabledCategories.Insert(category); } } @@ -704,11 +704,11 @@ void TelemetryEvent::InitializeGlobalState(bool aCanRecordBase, gEventNameIDMap.InsertOrUpdate( UniqueEventName(info), UniquePtr{new EventKey{eventId, false}}); - gCategoryNames.PutEntry(info.common_info.category()); + gCategoryNames.Insert(info.common_info.category()); } // A hack until bug 1691156 is fixed - gEnabledCategories.PutEntry("avif"_ns); + gEnabledCategories.Insert("avif"_ns); gInitDone = true; } @@ -1341,9 +1341,9 @@ void TelemetryEvent::SetEventRecordingEnabled(const nsACString& category, } if (enabled) { - gEnabledCategories.PutEntry(category); + gEnabledCategories.Insert(category); } else { - gEnabledCategories.RemoveEntry(category); + gEnabledCategories.Remove(category); } } diff --git a/toolkit/components/telemetry/core/TelemetryHistogram.cpp b/toolkit/components/telemetry/core/TelemetryHistogram.cpp index e9df49adff37..be0527a1e933 100644 --- a/toolkit/components/telemetry/core/TelemetryHistogram.cpp +++ b/toolkit/components/telemetry/core/TelemetryHistogram.cpp @@ -2763,7 +2763,7 @@ nsresult TelemetryHistogram::GetAllStores(StringHashSet& set) { const char* name = &gHistogramStringTable[storeIdx]; nsAutoCString store; store.AssignASCII(name); - if (!set.PutEntry(store)) { + if (!set.Insert(store, mozilla::fallible)) { return NS_ERROR_FAILURE; } } diff --git a/toolkit/components/telemetry/core/TelemetryScalar.cpp b/toolkit/components/telemetry/core/TelemetryScalar.cpp index 9385bf8e7c12..85375422ce3d 100644 --- a/toolkit/components/telemetry/core/TelemetryScalar.cpp +++ b/toolkit/components/telemetry/core/TelemetryScalar.cpp @@ -3744,7 +3744,7 @@ nsresult TelemetryScalar::GetAllStores(StringHashSet& set) { const char* name = &gScalarsStringTable[storeIdx]; nsAutoCString store; store.AssignASCII(name); - if (!set.PutEntry(store)) { + if (!set.Insert(store, mozilla::fallible)) { return NS_ERROR_FAILURE; } } @@ -3753,7 +3753,7 @@ nsresult TelemetryScalar::GetAllStores(StringHashSet& set) { for (auto& ptr : *gDynamicStoreNames) { nsAutoCString store; ptr->ToUTF8String(store); - if (!set.PutEntry(store)) { + if (!set.Insert(store, mozilla::fallible)) { return NS_ERROR_FAILURE; } }