diff --git a/gfx/thebes/gfxFT2Fonts.h b/gfx/thebes/gfxFT2Fonts.h index 0b4df43c4031..7313d509a12a 100644 --- a/gfx/thebes/gfxFT2Fonts.h +++ b/gfx/thebes/gfxFT2Fonts.h @@ -51,12 +51,12 @@ class gfxFT2Font : public gfxFT2FontBase { if (!entry) return nullptr; - if (entry->mData.glyphIndex == 0xffffffffU) { + if (entry->GetData().glyphIndex == 0xffffffffU) { // this is a new entry, fill it - FillGlyphDataForChar(aFace, ch, &entry->mData); + FillGlyphDataForChar(aFace, ch, entry->GetModifiableData()); } - return &entry->mData; + return &entry->GetData(); } bool ShapeText(DrawTarget* aDrawTarget, const char16_t* aText, diff --git a/toolkit/components/telemetry/core/Telemetry.cpp b/toolkit/components/telemetry/core/Telemetry.cpp index 0599e46d2165..c3fbfab18851 100644 --- a/toolkit/components/telemetry/core/Telemetry.cpp +++ b/toolkit/components/telemetry/core/Telemetry.cpp @@ -561,13 +561,13 @@ bool TelemetryImpl::ReflectSQL(const SlowSQLEntryType* entry, const Stat* stat, bool TelemetryImpl::ReflectMainThreadSQL(SlowSQLEntryType* entry, JSContext* cx, JS::Handle obj) { - return ReflectSQL(entry, &entry->mData.mainThread, cx, obj); + return ReflectSQL(entry, &entry->GetModifiableData()->mainThread, cx, obj); } bool TelemetryImpl::ReflectOtherThreadsSQL(SlowSQLEntryType* entry, JSContext* cx, JS::Handle obj) { - return ReflectSQL(entry, &entry->mData.otherThreads, cx, obj); + return ReflectSQL(entry, &entry->GetModifiableData()->otherThreads, cx, obj); } bool TelemetryImpl::AddSQLInfo(JSContext* cx, JS::Handle rootObj, @@ -1262,18 +1262,18 @@ void TelemetryImpl::StoreSlowSQL(const nsACString& sql, uint32_t delay, if (!entry) { entry = slowSQLMap->PutEntry(sql); if (MOZ_UNLIKELY(!entry)) return; - entry->mData.mainThread.hitCount = 0; - entry->mData.mainThread.totalTime = 0; - entry->mData.otherThreads.hitCount = 0; - entry->mData.otherThreads.totalTime = 0; + entry->GetModifiableData()->mainThread.hitCount = 0; + entry->GetModifiableData()->mainThread.totalTime = 0; + entry->GetModifiableData()->otherThreads.hitCount = 0; + entry->GetModifiableData()->otherThreads.totalTime = 0; } if (NS_IsMainThread()) { - entry->mData.mainThread.hitCount++; - entry->mData.mainThread.totalTime += delay; + entry->GetModifiableData()->mainThread.hitCount++; + entry->GetModifiableData()->mainThread.totalTime += delay; } else { - entry->mData.otherThreads.hitCount++; - entry->mData.otherThreads.totalTime += delay; + entry->GetModifiableData()->otherThreads.hitCount++; + entry->GetModifiableData()->otherThreads.totalTime += delay; } } diff --git a/toolkit/components/telemetry/core/TelemetryScalar.cpp b/toolkit/components/telemetry/core/TelemetryScalar.cpp index 195c09ac0429..827ca03a3d60 100644 --- a/toolkit/components/telemetry/core/TelemetryScalar.cpp +++ b/toolkit/components/telemetry/core/TelemetryScalar.cpp @@ -1409,7 +1409,7 @@ nsresult internal_GetEnumByScalarName(const StaticMutexAutoLock& lock, if (!entry) { return NS_ERROR_INVALID_ARG; } - *aId = entry->mData; + *aId = entry->GetData(); return NS_OK; } @@ -1921,7 +1921,7 @@ void internal_RegisterScalars(const StaticMutexAutoLock& lock, // Change the scalar to expired if needed. if (scalarInfo.mDynamicExpiration && !scalarInfo.builtin) { DynamicScalarInfo& scalarData = - (*gDynamicScalarInfo)[existingKey->mData.id]; + (*gDynamicScalarInfo)[existingKey->GetData().id]; scalarData.mDynamicExpiration = true; } continue; @@ -1930,7 +1930,7 @@ void internal_RegisterScalars(const StaticMutexAutoLock& lock, gDynamicScalarInfo->AppendElement(scalarInfo); uint32_t scalarId = gDynamicScalarInfo->Length() - 1; CharPtrEntryType* entry = gScalarNameIDMap.PutEntry(scalarInfo.name()); - entry->mData = ScalarKey{scalarId, true}; + entry->SetData(ScalarKey{scalarId, true}); } } @@ -2415,7 +2415,7 @@ void TelemetryScalar::InitializeGlobalState(bool aCanRecordBase, static_cast(mozilla::Telemetry::ScalarID::ScalarCount); for (uint32_t i = 0; i < scalarCount; i++) { CharPtrEntryType* entry = gScalarNameIDMap.PutEntry(gScalars[i].name()); - entry->mData = ScalarKey{i, false}; + entry->SetData(ScalarKey{i, false}); } // To summarize dynamic events we need a dynamic scalar. diff --git a/toolkit/components/telemetry/other/TelemetryIOInterposeObserver.cpp b/toolkit/components/telemetry/other/TelemetryIOInterposeObserver.cpp index 4b3f2afcafcd..d41fd253d8f9 100644 --- a/toolkit/components/telemetry/other/TelemetryIOInterposeObserver.cpp +++ b/toolkit/components/telemetry/other/TelemetryIOInterposeObserver.cpp @@ -75,7 +75,7 @@ void TelemetryIOInterposeObserver::Observe(Observation& aOb) { // Create a new entry or retrieve the existing one FileIOEntryType* entry = mFileStats.PutEntry(processedName); if (entry) { - FileStats& stats = entry->mData.mStats[mCurStage]; + FileStats& stats = entry->GetModifiableData()->mStats[mCurStage]; // Update the statistics stats.totalTime += (double)aOb.Duration().ToMilliseconds(); switch (aOb.ObservedOperation()) { @@ -105,7 +105,7 @@ bool TelemetryIOInterposeObserver::ReflectFileStats(FileIOEntryType* entry, JS::Handle obj) { JS::AutoValueArray stages(cx); - FileStatsByStage& statsByStage = entry->mData; + FileStatsByStage& statsByStage = *entry->GetModifiableData(); for (int s = STAGE_STARTUP; s < NUM_STAGES; ++s) { FileStats& fileStats = statsByStage.mStats[s]; diff --git a/toolkit/components/telemetry/other/WebrtcTelemetry.cpp b/toolkit/components/telemetry/other/WebrtcTelemetry.cpp index a9fff1f3be10..651fc4a1f4a2 100644 --- a/toolkit/components/telemetry/other/WebrtcTelemetry.cpp +++ b/toolkit/components/telemetry/other/WebrtcTelemetry.cpp @@ -20,9 +20,9 @@ void WebrtcTelemetry::RecordIceCandidateMask(const uint32_t iceCandidateBitmask, } if (success) { - entry->mData.webrtc.successCount++; + entry->GetModifiableData()->webrtc.successCount++; } else { - entry->mData.webrtc.failureCount++; + entry->GetModifiableData()->webrtc.failureCount++; } } @@ -55,7 +55,7 @@ bool ReflectIceEntry(const WebrtcTelemetry::WebrtcIceCandidateType* entry, bool ReflectIceWebrtc(WebrtcTelemetry::WebrtcIceCandidateType* entry, JSContext* cx, JS::Handle obj) { - return ReflectIceEntry(entry, &entry->mData.webrtc, cx, obj); + return ReflectIceEntry(entry, &entry->GetData().webrtc, cx, obj); } bool WebrtcTelemetry::AddIceInfo(JSContext* cx, JS::Handle iceObj) { diff --git a/xpcom/ds/nsBaseHashtable.h b/xpcom/ds/nsBaseHashtable.h index 166c0d3f3222..fe935bf2dd5a 100644 --- a/xpcom/ds/nsBaseHashtable.h +++ b/xpcom/ds/nsBaseHashtable.h @@ -23,10 +23,19 @@ class nsBaseHashtable; // forward declaration template class nsBaseHashtableET : public KeyClass { public: - DataType mData; - friend class nsTHashtable>; + const DataType& GetData() const { return mData; } + DataType* GetModifiableData() { return &mData; } + template + void SetData(U&& aData) { + mData = std::forward(aData); + } private: + DataType mData; + friend class nsTHashtable>; + template + friend class nsBaseHashtable; + typedef typename KeyClass::KeyType KeyType; typedef typename KeyClass::KeyTypePointer KeyTypePointer; diff --git a/xpcom/ds/nsClassHashtable.h b/xpcom/ds/nsClassHashtable.h index 2a98f3a79874..4ea28144b27e 100644 --- a/xpcom/ds/nsClassHashtable.h +++ b/xpcom/ds/nsClassHashtable.h @@ -80,9 +80,9 @@ T* nsClassHashtable::LookupOrAdd(KeyType aKey, auto count = this->Count(); typename base_type::EntryType* ent = this->PutEntry(aKey); if (count != this->Count()) { - ent->mData = new T(std::forward(aConstructionArgs)...); + ent->SetData(nsAutoPtr(new T(std::forward(aConstructionArgs)...))); } - return ent->mData; + return ent->GetData(); } template @@ -91,7 +91,7 @@ bool nsClassHashtable::Get(KeyType aKey, T** aRetVal) const { if (ent) { if (aRetVal) { - *aRetVal = ent->mData; + *aRetVal = ent->GetData(); } return true; @@ -111,7 +111,7 @@ T* nsClassHashtable::Get(KeyType aKey) const { return nullptr; } - return ent->mData; + return ent->GetData(); } #endif // nsClassHashtable_h__ diff --git a/xpcom/ds/nsDataHashtable.h b/xpcom/ds/nsDataHashtable.h index 033b4d1d61d3..0dbe7a076fa5 100644 --- a/xpcom/ds/nsDataHashtable.h +++ b/xpcom/ds/nsDataHashtable.h @@ -40,7 +40,7 @@ class nsDataHashtable : public nsBaseHashtable { */ DataType* GetValue(KeyType aKey) { if (EntryType* ent = this->GetEntry(aKey)) { - return &ent->mData; + return ent->GetModifiableData(); } return nullptr; } @@ -56,7 +56,7 @@ class nsDataHashtable : public nsBaseHashtable { mozilla::Maybe GetAndRemove(KeyType aKey) { mozilla::Maybe value; if (EntryType* ent = this->GetEntry(aKey)) { - value.emplace(std::move(ent->mData)); + value.emplace(std::move(*ent->GetModifiableData())); this->RemoveEntry(ent); } return value; diff --git a/xpcom/ds/nsInterfaceHashtable.h b/xpcom/ds/nsInterfaceHashtable.h index 9135a4cf4c3e..ad3adc1ee164 100644 --- a/xpcom/ds/nsInterfaceHashtable.h +++ b/xpcom/ds/nsInterfaceHashtable.h @@ -104,7 +104,7 @@ bool nsInterfaceHashtable::Get( if (ent) { if (aInterface) { - *aInterface = ent->mData; + *aInterface = ent->GetData(); NS_IF_ADDREF(*aInterface); } @@ -129,7 +129,7 @@ already_AddRefed nsInterfaceHashtable::Get( return nullptr; } - nsCOMPtr copy = ent->mData; + nsCOMPtr copy = ent->GetData(); return copy.forget(); } @@ -143,7 +143,7 @@ Interface* nsInterfaceHashtable::GetWeak( *aFound = true; } - return ent->mData; + return ent->GetData(); } // Key does not exist, return nullptr and set aFound to false @@ -162,7 +162,7 @@ bool nsInterfaceHashtable::Put( return false; } - ent->mData = aValue; + ent->SetData(std::move(aValue)); return true; } @@ -173,7 +173,7 @@ bool nsInterfaceHashtable::Remove(KeyType aKey, if (ent) { if (aData) { - ent->mData.forget(aData); + ent->GetModifiableData()->forget(aData); } this->RemoveEntry(ent); return true; diff --git a/xpcom/ds/nsRefPtrHashtable.h b/xpcom/ds/nsRefPtrHashtable.h index f3e5980ac7ad..fd3e86defea7 100644 --- a/xpcom/ds/nsRefPtrHashtable.h +++ b/xpcom/ds/nsRefPtrHashtable.h @@ -96,7 +96,7 @@ bool nsRefPtrHashtable::Get(KeyType aKey, if (ent) { if (aRefPtr) { - *aRefPtr = ent->mData; + *aRefPtr = ent->GetData(); NS_IF_ADDREF(*aRefPtr); } @@ -121,7 +121,7 @@ already_AddRefed nsRefPtrHashtable::Get( return nullptr; } - RefPtr copy = ent->mData; + RefPtr copy = ent->GetData(); return copy.forget(); } @@ -135,7 +135,7 @@ PtrType* nsRefPtrHashtable::GetWeak(KeyType aKey, *aFound = true; } - return ent->mData; + return ent->GetData(); } // Key does not exist, return nullptr and set aFound to false @@ -164,7 +164,7 @@ bool nsRefPtrHashtable::Put(KeyType aKey, return false; } - ent->mData = aData; + ent->SetData(aData); return true; } @@ -176,7 +176,7 @@ bool nsRefPtrHashtable::Remove(KeyType aKey, if (ent) { if (aRefPtr) { - ent->mData.forget(aRefPtr); + ent->GetModifiableData()->forget(aRefPtr); } this->RemoveEntry(ent); return true; diff --git a/xpcom/threads/nsEnvironment.cpp b/xpcom/threads/nsEnvironment.cpp index 2502ffc6f395..ae9c6b4e8779 100644 --- a/xpcom/threads/nsEnvironment.cpp +++ b/xpcom/threads/nsEnvironment.cpp @@ -144,9 +144,9 @@ nsEnvironment::Set(const nsAString& aName, const nsAString& aValue) { } PR_SetEnv(newData.get()); - if (entry->mData) { - free(entry->mData); + if (entry->GetData()) { + free(entry->GetData()); } - entry->mData = newData.release(); + entry->SetData(newData.release()); return NS_OK; }