Skip to content

Commit dda41fa

Browse files
committed
Bug 1575479 - Encapsulate mBaseHashtableET::mData. r=froydnj
Differential Revision: https://phabricator.services.mozilla.com/D45004 --HG-- extra : moz-landing-system : lando
1 parent 28fa1df commit dda41fa

File tree

10 files changed

+48
-39
lines changed

10 files changed

+48
-39
lines changed

toolkit/components/telemetry/core/Telemetry.cpp

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -561,13 +561,13 @@ bool TelemetryImpl::ReflectSQL(const SlowSQLEntryType* entry, const Stat* stat,
561561

562562
bool TelemetryImpl::ReflectMainThreadSQL(SlowSQLEntryType* entry, JSContext* cx,
563563
JS::Handle<JSObject*> obj) {
564-
return ReflectSQL(entry, &entry->mData.mainThread, cx, obj);
564+
return ReflectSQL(entry, &entry->GetModifiableData()->mainThread, cx, obj);
565565
}
566566

567567
bool TelemetryImpl::ReflectOtherThreadsSQL(SlowSQLEntryType* entry,
568568
JSContext* cx,
569569
JS::Handle<JSObject*> obj) {
570-
return ReflectSQL(entry, &entry->mData.otherThreads, cx, obj);
570+
return ReflectSQL(entry, &entry->GetModifiableData()->otherThreads, cx, obj);
571571
}
572572

573573
bool TelemetryImpl::AddSQLInfo(JSContext* cx, JS::Handle<JSObject*> rootObj,
@@ -1262,18 +1262,18 @@ void TelemetryImpl::StoreSlowSQL(const nsACString& sql, uint32_t delay,
12621262
if (!entry) {
12631263
entry = slowSQLMap->PutEntry(sql);
12641264
if (MOZ_UNLIKELY(!entry)) return;
1265-
entry->mData.mainThread.hitCount = 0;
1266-
entry->mData.mainThread.totalTime = 0;
1267-
entry->mData.otherThreads.hitCount = 0;
1268-
entry->mData.otherThreads.totalTime = 0;
1265+
entry->GetModifiableData()->mainThread.hitCount = 0;
1266+
entry->GetModifiableData()->mainThread.totalTime = 0;
1267+
entry->GetModifiableData()->otherThreads.hitCount = 0;
1268+
entry->GetModifiableData()->otherThreads.totalTime = 0;
12691269
}
12701270

12711271
if (NS_IsMainThread()) {
1272-
entry->mData.mainThread.hitCount++;
1273-
entry->mData.mainThread.totalTime += delay;
1272+
entry->GetModifiableData()->mainThread.hitCount++;
1273+
entry->GetModifiableData()->mainThread.totalTime += delay;
12741274
} else {
1275-
entry->mData.otherThreads.hitCount++;
1276-
entry->mData.otherThreads.totalTime += delay;
1275+
entry->GetModifiableData()->otherThreads.hitCount++;
1276+
entry->GetModifiableData()->otherThreads.totalTime += delay;
12771277
}
12781278
}
12791279

toolkit/components/telemetry/core/TelemetryScalar.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1409,7 +1409,7 @@ nsresult internal_GetEnumByScalarName(const StaticMutexAutoLock& lock,
14091409
if (!entry) {
14101410
return NS_ERROR_INVALID_ARG;
14111411
}
1412-
*aId = entry->mData;
1412+
*aId = entry->GetData();
14131413
return NS_OK;
14141414
}
14151415

@@ -1921,7 +1921,7 @@ void internal_RegisterScalars(const StaticMutexAutoLock& lock,
19211921
// Change the scalar to expired if needed.
19221922
if (scalarInfo.mDynamicExpiration && !scalarInfo.builtin) {
19231923
DynamicScalarInfo& scalarData =
1924-
(*gDynamicScalarInfo)[existingKey->mData.id];
1924+
(*gDynamicScalarInfo)[existingKey->GetData().id];
19251925
scalarData.mDynamicExpiration = true;
19261926
}
19271927
continue;
@@ -1930,7 +1930,7 @@ void internal_RegisterScalars(const StaticMutexAutoLock& lock,
19301930
gDynamicScalarInfo->AppendElement(scalarInfo);
19311931
uint32_t scalarId = gDynamicScalarInfo->Length() - 1;
19321932
CharPtrEntryType* entry = gScalarNameIDMap.PutEntry(scalarInfo.name());
1933-
entry->mData = ScalarKey{scalarId, true};
1933+
entry->SetData(ScalarKey{scalarId, true});
19341934
}
19351935
}
19361936

@@ -2415,7 +2415,7 @@ void TelemetryScalar::InitializeGlobalState(bool aCanRecordBase,
24152415
static_cast<uint32_t>(mozilla::Telemetry::ScalarID::ScalarCount);
24162416
for (uint32_t i = 0; i < scalarCount; i++) {
24172417
CharPtrEntryType* entry = gScalarNameIDMap.PutEntry(gScalars[i].name());
2418-
entry->mData = ScalarKey{i, false};
2418+
entry->SetData(ScalarKey{i, false});
24192419
}
24202420

24212421
// To summarize dynamic events we need a dynamic scalar.

toolkit/components/telemetry/other/TelemetryIOInterposeObserver.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ void TelemetryIOInterposeObserver::Observe(Observation& aOb) {
7575
// Create a new entry or retrieve the existing one
7676
FileIOEntryType* entry = mFileStats.PutEntry(processedName);
7777
if (entry) {
78-
FileStats& stats = entry->mData.mStats[mCurStage];
78+
FileStats& stats = entry->GetModifiableData()->mStats[mCurStage];
7979
// Update the statistics
8080
stats.totalTime += (double)aOb.Duration().ToMilliseconds();
8181
switch (aOb.ObservedOperation()) {
@@ -105,7 +105,7 @@ bool TelemetryIOInterposeObserver::ReflectFileStats(FileIOEntryType* entry,
105105
JS::Handle<JSObject*> obj) {
106106
JS::AutoValueArray<NUM_STAGES> stages(cx);
107107

108-
FileStatsByStage& statsByStage = entry->mData;
108+
FileStatsByStage& statsByStage = *entry->GetModifiableData();
109109
for (int s = STAGE_STARTUP; s < NUM_STAGES; ++s) {
110110
FileStats& fileStats = statsByStage.mStats[s];
111111

toolkit/components/telemetry/other/WebrtcTelemetry.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,9 @@ void WebrtcTelemetry::RecordIceCandidateMask(const uint32_t iceCandidateBitmask,
2020
}
2121

2222
if (success) {
23-
entry->mData.webrtc.successCount++;
23+
entry->GetModifiableData()->webrtc.successCount++;
2424
} else {
25-
entry->mData.webrtc.failureCount++;
25+
entry->GetModifiableData()->webrtc.failureCount++;
2626
}
2727
}
2828

@@ -55,7 +55,7 @@ bool ReflectIceEntry(const WebrtcTelemetry::WebrtcIceCandidateType* entry,
5555

5656
bool ReflectIceWebrtc(WebrtcTelemetry::WebrtcIceCandidateType* entry,
5757
JSContext* cx, JS::Handle<JSObject*> obj) {
58-
return ReflectIceEntry(entry, &entry->mData.webrtc, cx, obj);
58+
return ReflectIceEntry(entry, &entry->GetData().webrtc, cx, obj);
5959
}
6060

6161
bool WebrtcTelemetry::AddIceInfo(JSContext* cx, JS::Handle<JSObject*> iceObj) {

xpcom/ds/nsBaseHashtable.h

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,10 +23,19 @@ class nsBaseHashtable; // forward declaration
2323
template <class KeyClass, class DataType>
2424
class nsBaseHashtableET : public KeyClass {
2525
public:
26+
const DataType& GetData() const { return mData; }
27+
DataType* GetModifiableData() { return &mData; }
28+
template <typename U>
29+
void SetData(U&& aData) {
30+
mData = std::forward<U>(aData);
31+
}
32+
33+
private:
2634
DataType mData;
2735
friend class nsTHashtable<nsBaseHashtableET<KeyClass, DataType>>;
36+
template <typename KeyClassX, typename DataTypeX, typename UserDataTypeX>
37+
friend class nsBaseHashtable;
2838

29-
private:
3039
typedef typename KeyClass::KeyType KeyType;
3140
typedef typename KeyClass::KeyTypePointer KeyTypePointer;
3241

xpcom/ds/nsClassHashtable.h

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -80,9 +80,9 @@ T* nsClassHashtable<KeyClass, T>::LookupOrAdd(KeyType aKey,
8080
auto count = this->Count();
8181
typename base_type::EntryType* ent = this->PutEntry(aKey);
8282
if (count != this->Count()) {
83-
ent->mData = new T(std::forward<Args>(aConstructionArgs)...);
83+
ent->SetData(nsAutoPtr<T>(new T(std::forward<Args>(aConstructionArgs)...)));
8484
}
85-
return ent->mData;
85+
return ent->GetData();
8686
}
8787

8888
template <class KeyClass, class T>
@@ -91,7 +91,7 @@ bool nsClassHashtable<KeyClass, T>::Get(KeyType aKey, T** aRetVal) const {
9191

9292
if (ent) {
9393
if (aRetVal) {
94-
*aRetVal = ent->mData;
94+
*aRetVal = ent->GetData();
9595
}
9696

9797
return true;
@@ -111,7 +111,7 @@ T* nsClassHashtable<KeyClass, T>::Get(KeyType aKey) const {
111111
return nullptr;
112112
}
113113

114-
return ent->mData;
114+
return ent->GetData();
115115
}
116116

117117
#endif // nsClassHashtable_h__

xpcom/ds/nsDataHashtable.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ class nsDataHashtable : public nsBaseHashtable<KeyClass, DataType, DataType> {
4040
*/
4141
DataType* GetValue(KeyType aKey) {
4242
if (EntryType* ent = this->GetEntry(aKey)) {
43-
return &ent->mData;
43+
return ent->GetModifiableData();
4444
}
4545
return nullptr;
4646
}
@@ -56,7 +56,7 @@ class nsDataHashtable : public nsBaseHashtable<KeyClass, DataType, DataType> {
5656
mozilla::Maybe<DataType> GetAndRemove(KeyType aKey) {
5757
mozilla::Maybe<DataType> value;
5858
if (EntryType* ent = this->GetEntry(aKey)) {
59-
value.emplace(std::move(ent->mData));
59+
value.emplace(std::move(*ent->GetModifiableData()));
6060
this->RemoveEntry(ent);
6161
}
6262
return value;

xpcom/ds/nsInterfaceHashtable.h

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,7 @@ bool nsInterfaceHashtable<KeyClass, Interface>::Get(
104104

105105
if (ent) {
106106
if (aInterface) {
107-
*aInterface = ent->mData;
107+
*aInterface = ent->GetData();
108108

109109
NS_IF_ADDREF(*aInterface);
110110
}
@@ -129,7 +129,7 @@ already_AddRefed<Interface> nsInterfaceHashtable<KeyClass, Interface>::Get(
129129
return nullptr;
130130
}
131131

132-
nsCOMPtr<Interface> copy = ent->mData;
132+
nsCOMPtr<Interface> copy = ent->GetData();
133133
return copy.forget();
134134
}
135135

@@ -143,7 +143,7 @@ Interface* nsInterfaceHashtable<KeyClass, Interface>::GetWeak(
143143
*aFound = true;
144144
}
145145

146-
return ent->mData;
146+
return ent->GetData();
147147
}
148148

149149
// Key does not exist, return nullptr and set aFound to false
@@ -162,7 +162,7 @@ bool nsInterfaceHashtable<KeyClass, Interface>::Put(
162162
return false;
163163
}
164164

165-
ent->mData = aValue;
165+
ent->SetData(std::move(aValue));
166166
return true;
167167
}
168168

@@ -173,7 +173,7 @@ bool nsInterfaceHashtable<KeyClass, Interface>::Remove(KeyType aKey,
173173

174174
if (ent) {
175175
if (aData) {
176-
ent->mData.forget(aData);
176+
ent->GetModifiableData()->forget(aData);
177177
}
178178
this->RemoveEntry(ent);
179179
return true;

xpcom/ds/nsRefPtrHashtable.h

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,7 @@ bool nsRefPtrHashtable<KeyClass, PtrType>::Get(KeyType aKey,
9696

9797
if (ent) {
9898
if (aRefPtr) {
99-
*aRefPtr = ent->mData;
99+
*aRefPtr = ent->GetData();
100100

101101
NS_IF_ADDREF(*aRefPtr);
102102
}
@@ -121,7 +121,7 @@ already_AddRefed<PtrType> nsRefPtrHashtable<KeyClass, PtrType>::Get(
121121
return nullptr;
122122
}
123123

124-
RefPtr<PtrType> copy = ent->mData;
124+
RefPtr<PtrType> copy = ent->GetData();
125125
return copy.forget();
126126
}
127127

@@ -135,7 +135,7 @@ PtrType* nsRefPtrHashtable<KeyClass, PtrType>::GetWeak(KeyType aKey,
135135
*aFound = true;
136136
}
137137

138-
return ent->mData;
138+
return ent->GetData();
139139
}
140140

141141
// Key does not exist, return nullptr and set aFound to false
@@ -164,7 +164,7 @@ bool nsRefPtrHashtable<KeyClass, PtrType>::Put(KeyType aKey,
164164
return false;
165165
}
166166

167-
ent->mData = aData;
167+
ent->SetData(aData);
168168

169169
return true;
170170
}
@@ -176,7 +176,7 @@ bool nsRefPtrHashtable<KeyClass, PtrType>::Remove(KeyType aKey,
176176

177177
if (ent) {
178178
if (aRefPtr) {
179-
ent->mData.forget(aRefPtr);
179+
ent->GetModifiableData()->forget(aRefPtr);
180180
}
181181
this->RemoveEntry(ent);
182182
return true;

xpcom/threads/nsEnvironment.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -144,9 +144,9 @@ nsEnvironment::Set(const nsAString& aName, const nsAString& aValue) {
144144
}
145145

146146
PR_SetEnv(newData.get());
147-
if (entry->mData) {
148-
free(entry->mData);
147+
if (entry->GetData()) {
148+
free(entry->GetData());
149149
}
150-
entry->mData = newData.release();
150+
entry->SetData(newData.release());
151151
return NS_OK;
152152
}

0 commit comments

Comments
 (0)