Bug 1189156 (part 1) - Don't use enumeration style for PLDHashTable::SizeOf{In,Ex}cludingThis(). r=froydnj.

After this change, we have PLDHashTable::ShallowSizeOf{In,Ex}cludingThis(),
which don't do anything to measure children. (They can be combined with
iteration to measure children.)

This patch also removes the PL_DHashTableSizeOf{In,Ex}cludingThis() functions.
They're not necessary because the methods can be used instead.

Finally, the patch deliberately converts some SizeOfExcludingThis() calls to
SizeOfIncludingThis(). These are all done on heap pointers so this change is
valid.

--HG--
extra : rebase_source : b1d51096a8e7dcac29d7efd92e28938836ff5481
This commit is contained in:
Nicholas Nethercote 2015-07-29 22:28:20 -07:00
Родитель 7f5b0ef0cf
Коммит 2d56c1f52e
16 изменённых файлов: 122 добавлений и 282 удалений

Просмотреть файл

@ -364,8 +364,8 @@ public:
// We don't measure the |EventListenerManager| objects pointed to by the
// entries because those references are non-owning.
int64_t amount = sEventListenerManagersHash
? PL_DHashTableSizeOfExcludingThis(
sEventListenerManagersHash, nullptr, MallocSizeOf)
? sEventListenerManagersHash->ShallowSizeOfIncludingThis(
MallocSizeOf)
: 0;
return MOZ_COLLECT_REPORT(

Просмотреть файл

@ -313,7 +313,7 @@ size_t
nsPropertyTable::PropertyList::SizeOfIncludingThis(mozilla::MallocSizeOf aMallocSizeOf)
{
size_t n = aMallocSizeOf(this);
n += PL_DHashTableSizeOfExcludingThis(&mObjectValueMap, nullptr, aMallocSizeOf);
n += mObjectValueMap.ShallowSizeOfExcludingThis(aMallocSizeOf);
return n;
}

Просмотреть файл

@ -725,14 +725,6 @@ nsScriptNameSpaceManager::RegisterNavigatorDOMConstructor(
}
}
static size_t
SizeOfEntryExcludingThis(PLDHashEntryHdr *aHdr, MallocSizeOf aMallocSizeOf,
void *aArg)
{
GlobalNameMapEntry* entry = static_cast<GlobalNameMapEntry*>(aHdr);
return entry->SizeOfExcludingThis(aMallocSizeOf);
}
MOZ_DEFINE_MALLOC_SIZE_OF(ScriptNameSpaceManagerMallocSizeOf)
NS_IMETHODIMP
@ -746,12 +738,22 @@ nsScriptNameSpaceManager::CollectReports(
}
size_t
nsScriptNameSpaceManager::SizeOfIncludingThis(mozilla::MallocSizeOf aMallocSizeOf)
nsScriptNameSpaceManager::SizeOfIncludingThis(
mozilla::MallocSizeOf aMallocSizeOf) const
{
size_t n = 0;
n += PL_DHashTableSizeOfExcludingThis(&mGlobalNames,
SizeOfEntryExcludingThis, aMallocSizeOf);
n += PL_DHashTableSizeOfExcludingThis(&mNavigatorNames,
SizeOfEntryExcludingThis, aMallocSizeOf);
n += mGlobalNames.ShallowSizeOfExcludingThis(aMallocSizeOf);
for (auto iter = mGlobalNames.ConstIter(); !iter.Done(); iter.Next()) {
auto entry = static_cast<GlobalNameMapEntry*>(iter.Get());
n += entry->SizeOfExcludingThis(aMallocSizeOf);
}
n += mNavigatorNames.ShallowSizeOfExcludingThis(aMallocSizeOf);
for (auto iter = mNavigatorNames.ConstIter(); !iter.Done(); iter.Next()) {
auto entry = static_cast<GlobalNameMapEntry*>(iter.Get());
n += entry->SizeOfExcludingThis(aMallocSizeOf);
}
return n;
}

Просмотреть файл

@ -206,7 +206,7 @@ public:
NameIterator GlobalNameIter() { return NameIterator(&mGlobalNames); }
NameIterator NavigatorNameIter() { return NameIterator(&mNavigatorNames); }
size_t SizeOfIncludingThis(mozilla::MallocSizeOf aMallocSizeOf);
size_t SizeOfIncludingThis(mozilla::MallocSizeOf aMallocSizeOf) const;
private:
virtual ~nsScriptNameSpaceManager();

Просмотреть файл

@ -183,21 +183,17 @@ Native2WrappedNativeMap::~Native2WrappedNativeMap()
}
size_t
Native2WrappedNativeMap::SizeOfIncludingThis(mozilla::MallocSizeOf mallocSizeOf)
Native2WrappedNativeMap::SizeOfIncludingThis(mozilla::MallocSizeOf mallocSizeOf) const
{
size_t n = 0;
n += mallocSizeOf(this);
n += PL_DHashTableSizeOfIncludingThis(mTable, SizeOfEntryExcludingThis, mallocSizeOf);
size_t n = mallocSizeOf(this);
n += mTable->ShallowSizeOfIncludingThis(mallocSizeOf);
for (auto iter = mTable->Iter(); !iter.Done(); iter.Next()) {
auto entry = static_cast<Native2WrappedNativeMap::Entry*>(iter.Get());
n += mallocSizeOf(entry->value);
}
return n;
}
/* static */ size_t
Native2WrappedNativeMap::SizeOfEntryExcludingThis(PLDHashEntryHdr* hdr,
mozilla::MallocSizeOf mallocSizeOf, void*)
{
return mallocSizeOf(((Native2WrappedNativeMap::Entry*)hdr)->value);
}
/***************************************************************************/
// implement IID2WrappedJSClassMap...
@ -255,22 +251,17 @@ IID2NativeInterfaceMap::~IID2NativeInterfaceMap()
}
size_t
IID2NativeInterfaceMap::SizeOfIncludingThis(mozilla::MallocSizeOf mallocSizeOf)
IID2NativeInterfaceMap::SizeOfIncludingThis(mozilla::MallocSizeOf mallocSizeOf) const
{
size_t n = 0;
n += mallocSizeOf(this);
n += PL_DHashTableSizeOfIncludingThis(mTable, SizeOfEntryExcludingThis, mallocSizeOf);
size_t n = mallocSizeOf(this);
n += mTable->ShallowSizeOfIncludingThis(mallocSizeOf);
for (auto iter = mTable->Iter(); !iter.Done(); iter.Next()) {
auto entry = static_cast<IID2NativeInterfaceMap::Entry*>(iter.Get());
n += entry->value->SizeOfIncludingThis(mallocSizeOf);
}
return n;
}
/* static */ size_t
IID2NativeInterfaceMap::SizeOfEntryExcludingThis(PLDHashEntryHdr* hdr,
mozilla::MallocSizeOf mallocSizeOf, void*)
{
XPCNativeInterface* iface = ((IID2NativeInterfaceMap::Entry*)hdr)->value;
return iface->SizeOfIncludingThis(mallocSizeOf);
}
/***************************************************************************/
// implement ClassInfo2NativeSetMap...
@ -294,10 +285,8 @@ ClassInfo2NativeSetMap::~ClassInfo2NativeSetMap()
size_t
ClassInfo2NativeSetMap::ShallowSizeOfIncludingThis(mozilla::MallocSizeOf mallocSizeOf)
{
size_t n = 0;
n += mallocSizeOf(this);
// The second arg is nullptr because this is a "shallow" measurement of the map.
n += PL_DHashTableSizeOfIncludingThis(mTable, nullptr, mallocSizeOf);
size_t n = mallocSizeOf(this);
n += mTable->ShallowSizeOfIncludingThis(mallocSizeOf);
return n;
}
@ -322,21 +311,17 @@ ClassInfo2WrappedNativeProtoMap::~ClassInfo2WrappedNativeProtoMap()
}
size_t
ClassInfo2WrappedNativeProtoMap::SizeOfIncludingThis(mozilla::MallocSizeOf mallocSizeOf)
ClassInfo2WrappedNativeProtoMap::SizeOfIncludingThis(mozilla::MallocSizeOf mallocSizeOf) const
{
size_t n = 0;
n += mallocSizeOf(this);
n += PL_DHashTableSizeOfIncludingThis(mTable, SizeOfEntryExcludingThis, mallocSizeOf);
size_t n = mallocSizeOf(this);
n += mTable->ShallowSizeOfIncludingThis(mallocSizeOf);
for (auto iter = mTable->Iter(); !iter.Done(); iter.Next()) {
auto entry = static_cast<ClassInfo2WrappedNativeProtoMap::Entry*>(iter.Get());
n += mallocSizeOf(entry->value);
}
return n;
}
/* static */ size_t
ClassInfo2WrappedNativeProtoMap::SizeOfEntryExcludingThis(PLDHashEntryHdr* hdr,
mozilla::MallocSizeOf mallocSizeOf, void*)
{
return mallocSizeOf(((ClassInfo2WrappedNativeProtoMap::Entry*)hdr)->value);
}
/***************************************************************************/
// implement NativeSetMap...
@ -438,21 +423,17 @@ NativeSetMap::~NativeSetMap()
}
size_t
NativeSetMap::SizeOfIncludingThis(mozilla::MallocSizeOf mallocSizeOf)
NativeSetMap::SizeOfIncludingThis(mozilla::MallocSizeOf mallocSizeOf) const
{
size_t n = 0;
n += mallocSizeOf(this);
n += PL_DHashTableSizeOfIncludingThis(mTable, SizeOfEntryExcludingThis, mallocSizeOf);
size_t n = mallocSizeOf(this);
n += mTable->ShallowSizeOfIncludingThis(mallocSizeOf);
for (auto iter = mTable->Iter(); !iter.Done(); iter.Next()) {
auto entry = static_cast<NativeSetMap::Entry*>(iter.Get());
n += entry->key_value->SizeOfIncludingThis(mallocSizeOf);
}
return n;
}
/* static */ size_t
NativeSetMap::SizeOfEntryExcludingThis(PLDHashEntryHdr* hdr, mozilla::MallocSizeOf mallocSizeOf, void*)
{
XPCNativeSet* set = ((NativeSetMap::Entry*)hdr)->key_value;
return set->SizeOfIncludingThis(mallocSizeOf);
}
/***************************************************************************/
// implement IID2ThisTranslatorMap...

Просмотреть файл

@ -150,15 +150,13 @@ public:
inline uint32_t Count() { return mTable->EntryCount(); }
PLDHashTable::Iterator Iter() const { return PLDHashTable::Iterator(mTable); }
size_t SizeOfIncludingThis(mozilla::MallocSizeOf mallocSizeOf);
size_t SizeOfIncludingThis(mozilla::MallocSizeOf mallocSizeOf) const;
~Native2WrappedNativeMap();
private:
Native2WrappedNativeMap(); // no implementation
explicit Native2WrappedNativeMap(int size);
static size_t SizeOfEntryExcludingThis(PLDHashEntryHdr* hdr, mozilla::MallocSizeOf mallocSizeOf, void*);
private:
PLDHashTable* mTable;
};
@ -263,15 +261,13 @@ public:
PLDHashTable::Iterator Iter() { return PLDHashTable::Iterator(mTable); }
size_t SizeOfIncludingThis(mozilla::MallocSizeOf mallocSizeOf);
size_t SizeOfIncludingThis(mozilla::MallocSizeOf mallocSizeOf) const;
~IID2NativeInterfaceMap();
private:
IID2NativeInterfaceMap(); // no implementation
explicit IID2NativeInterfaceMap(int size);
static size_t SizeOfEntryExcludingThis(PLDHashEntryHdr* hdr, mozilla::MallocSizeOf mallocSizeOf, void*);
private:
PLDHashTable* mTable;
};
@ -377,15 +373,13 @@ public:
PLDHashTable::Iterator Iter() const { return PLDHashTable::Iterator(mTable); }
PLDHashTable::Iterator Iter() { return PLDHashTable::Iterator(mTable); }
size_t SizeOfIncludingThis(mozilla::MallocSizeOf mallocSizeOf);
size_t SizeOfIncludingThis(mozilla::MallocSizeOf mallocSizeOf) const;
~ClassInfo2WrappedNativeProtoMap();
private:
ClassInfo2WrappedNativeProtoMap(); // no implementation
explicit ClassInfo2WrappedNativeProtoMap(int size);
static size_t SizeOfEntryExcludingThis(PLDHashEntryHdr* hdr, mozilla::MallocSizeOf mallocSizeOf, void*);
private:
PLDHashTable* mTable;
};
@ -448,15 +442,13 @@ public:
PLDHashTable::Iterator Iter() const { return PLDHashTable::Iterator(mTable); }
PLDHashTable::Iterator Iter() { return PLDHashTable::Iterator(mTable); }
size_t SizeOfIncludingThis(mozilla::MallocSizeOf mallocSizeOf);
size_t SizeOfIncludingThis(mozilla::MallocSizeOf mallocSizeOf) const;
~NativeSetMap();
private:
NativeSetMap(); // no implementation
explicit NativeSetMap(int size);
static size_t SizeOfEntryExcludingThis(PLDHashEntryHdr* hdr, mozilla::MallocSizeOf mallocSizeOf, void*);
private:
PLDHashTable* mTable;
};

Просмотреть файл

@ -171,7 +171,7 @@ private:
// Uses any of the sets of ops below.
struct RuleHashTableEntry : public PLDHashEntryHdr {
// If you add members that have heap allocated memory be sure to change the
// logic in SizeOfRuleHashTableEntry().
// logic in SizeOfRuleHashTable().
// Auto length 1, because we always have at least one entry in mRules.
nsAutoTArray<RuleValue, 1> mRules;
};
@ -746,10 +746,14 @@ void RuleHash::EnumerateAllRules(Element* aElement, ElementDependentRuleProcesso
}
static size_t
SizeOfRuleHashTableEntry(PLDHashEntryHdr* aHdr, MallocSizeOf aMallocSizeOf, void *)
SizeOfRuleHashTable(const PLDHashTable& aTable, MallocSizeOf aMallocSizeOf)
{
RuleHashTableEntry* entry = static_cast<RuleHashTableEntry*>(aHdr);
return entry->mRules.ShallowSizeOfExcludingThis(aMallocSizeOf);
size_t n = aTable.ShallowSizeOfExcludingThis(aMallocSizeOf);
for (auto iter = aTable.ConstIter(); !iter.Done(); iter.Next()) {
auto entry = static_cast<RuleHashTableEntry*>(iter.Get());
n += entry->mRules.ShallowSizeOfExcludingThis(aMallocSizeOf);
}
return n;
}
size_t
@ -757,21 +761,13 @@ RuleHash::SizeOfExcludingThis(MallocSizeOf aMallocSizeOf) const
{
size_t n = 0;
n += PL_DHashTableSizeOfExcludingThis(&mIdTable,
SizeOfRuleHashTableEntry,
aMallocSizeOf);
n += SizeOfRuleHashTable(mIdTable, aMallocSizeOf);
n += PL_DHashTableSizeOfExcludingThis(&mClassTable,
SizeOfRuleHashTableEntry,
aMallocSizeOf);
n += SizeOfRuleHashTable(mClassTable, aMallocSizeOf);
n += PL_DHashTableSizeOfExcludingThis(&mTagTable,
SizeOfRuleHashTableEntry,
aMallocSizeOf);
n += SizeOfRuleHashTable(mTagTable, aMallocSizeOf);
n += PL_DHashTableSizeOfExcludingThis(&mNameSpaceTable,
SizeOfRuleHashTableEntry,
aMallocSizeOf);
n += SizeOfRuleHashTable(mNameSpaceTable, aMallocSizeOf);
n += mUniversalRules.ShallowSizeOfExcludingThis(aMallocSizeOf);
@ -923,10 +919,14 @@ struct RuleCascadeData {
};
static size_t
SizeOfSelectorsEntry(PLDHashEntryHdr* aHdr, MallocSizeOf aMallocSizeOf, void *)
SizeOfSelectorsHashTable(const PLDHashTable& aTable, MallocSizeOf aMallocSizeOf)
{
AtomSelectorEntry* entry = static_cast<AtomSelectorEntry*>(aHdr);
return entry->mSelectors.ShallowSizeOfExcludingThis(aMallocSizeOf);
size_t n = aTable.ShallowSizeOfExcludingThis(aMallocSizeOf);
for (auto iter = aTable.ConstIter(); !iter.Done(); iter.Next()) {
auto entry = static_cast<AtomSelectorEntry*>(iter.Get());
n += entry->mSelectors.ShallowSizeOfExcludingThis(aMallocSizeOf);
}
return n;
}
static size_t
@ -958,21 +958,16 @@ RuleCascadeData::SizeOfIncludingThis(MallocSizeOf aMallocSizeOf) const
n += mStateSelectors.ShallowSizeOfExcludingThis(aMallocSizeOf);
n += PL_DHashTableSizeOfExcludingThis(&mIdSelectors,
SizeOfSelectorsEntry, aMallocSizeOf);
n += PL_DHashTableSizeOfExcludingThis(&mClassSelectors,
SizeOfSelectorsEntry, aMallocSizeOf);
n += SizeOfSelectorsHashTable(mIdSelectors, aMallocSizeOf);
n += SizeOfSelectorsHashTable(mClassSelectors, aMallocSizeOf);
n += mPossiblyNegatedClassSelectors.ShallowSizeOfExcludingThis(aMallocSizeOf);
n += mPossiblyNegatedIDSelectors.ShallowSizeOfExcludingThis(aMallocSizeOf);
n += PL_DHashTableSizeOfExcludingThis(&mAttributeSelectors,
SizeOfSelectorsEntry, aMallocSizeOf);
n += PL_DHashTableSizeOfExcludingThis(&mAnonBoxRules,
SizeOfRuleHashTableEntry, aMallocSizeOf);
n += SizeOfSelectorsHashTable(mAttributeSelectors, aMallocSizeOf);
n += SizeOfRuleHashTable(mAnonBoxRules, aMallocSizeOf);
#ifdef MOZ_XUL
n += PL_DHashTableSizeOfExcludingThis(&mXULTreeRules,
SizeOfRuleHashTableEntry, aMallocSizeOf);
n += SizeOfRuleHashTable(mXULTreeRules, aMallocSizeOf);
#endif
n += mFontFaceRules.ShallowSizeOfExcludingThis(aMallocSizeOf);

Просмотреть файл

@ -508,26 +508,16 @@ nsHTMLStyleSheet::LangRuleFor(const nsString& aLanguage)
return entry->mRule;
}
static size_t
SizeOfAttributesEntryExcludingThis(PLDHashEntryHdr* aEntry,
MallocSizeOf aMallocSizeOf,
void* aArg)
{
NS_PRECONDITION(aEntry, "The entry should not be null!");
MappedAttrTableEntry* entry = static_cast<MappedAttrTableEntry*>(aEntry);
NS_ASSERTION(entry->mAttributes, "entry->mAttributes should not be null!");
return entry->mAttributes->SizeOfIncludingThis(aMallocSizeOf);
}
size_t
nsHTMLStyleSheet::DOMSizeOfIncludingThis(MallocSizeOf aMallocSizeOf) const
{
size_t n = aMallocSizeOf(this);
n += PL_DHashTableSizeOfExcludingThis(&mMappedAttrTable,
SizeOfAttributesEntryExcludingThis,
aMallocSizeOf);
n += mMappedAttrTable.ShallowSizeOfExcludingThis(aMallocSizeOf);
for (auto iter = mMappedAttrTable.ConstIter(); !iter.Done(); iter.Next()) {
auto entry = static_cast<MappedAttrTableEntry*>(iter.Get());
n += entry->mAttributes->SizeOfIncludingThis(aMallocSizeOf);
}
// Measurement of the following members may be added later if DMD finds it is
// worthwhile:

Просмотреть файл

@ -241,7 +241,7 @@ Preferences::SizeOfIncludingThisAndOtherStuff(mozilla::MallocSizeOf aMallocSizeO
if (gHashTable) {
// pref keys are allocated in a private arena, which we count elsewhere.
// pref stringvals are allocated out of the same private arena.
n += PL_DHashTableSizeOfExcludingThis(gHashTable, nullptr, aMallocSizeOf);
n += gHashTable->ShallowSizeOfIncludingThis(aMallocSizeOf);
}
if (gCacheData) {
n += gCacheData->ShallowSizeOfIncludingThis(aMallocSizeOf);

Просмотреть файл

@ -1356,22 +1356,18 @@ nsHostResolver::CancelAsyncRequest(const char *host,
}
}
static size_t
SizeOfHostDBEntExcludingThis(PLDHashEntryHdr* hdr, MallocSizeOf mallocSizeOf,
void*)
{
nsHostDBEnt* ent = static_cast<nsHostDBEnt*>(hdr);
return ent->rec->SizeOfIncludingThis(mallocSizeOf);
}
size_t
nsHostResolver::SizeOfIncludingThis(MallocSizeOf mallocSizeOf) const
{
MutexAutoLock lock(mLock);
size_t n = mallocSizeOf(this);
n += PL_DHashTableSizeOfExcludingThis(&mDB, SizeOfHostDBEntExcludingThis,
mallocSizeOf);
n += mDB.ShallowSizeOfExcludingThis(mallocSizeOf);
for (auto iter = mDB.ConstIter(); !iter.Done(); iter.Next()) {
auto entry = static_cast<nsHostDBEnt*>(iter.Get());
n += entry->rec->SizeOfIncludingThis(mallocSizeOf);
}
// The following fields aren't measured.
// - mHighQ, mMediumQ, mLowQ, mEvictionQ, because they just point to

Просмотреть файл

@ -503,24 +503,18 @@ AtomImpl::SizeOfIncludingThis(MallocSizeOf aMallocSizeOf)
//----------------------------------------------------------------------
static size_t
SizeOfAtomTableEntryExcludingThis(PLDHashEntryHdr* aHdr,
MallocSizeOf aMallocSizeOf,
void* aArg)
{
AtomTableEntry* entry = static_cast<AtomTableEntry*>(aHdr);
return entry->mAtom->SizeOfIncludingThis(aMallocSizeOf);
}
void
NS_SizeOfAtomTablesIncludingThis(MallocSizeOf aMallocSizeOf,
size_t* aMain, size_t* aStatic)
{
*aMain = gAtomTable
? PL_DHashTableSizeOfExcludingThis(gAtomTable,
SizeOfAtomTableEntryExcludingThis,
aMallocSizeOf)
: 0;
*aMain = 0;
if (gAtomTable) {
*aMain += gAtomTable->ShallowSizeOfIncludingThis(aMallocSizeOf);
for (auto iter = gAtomTable->Iter(); !iter.Done(); iter.Next()) {
auto entry = static_cast<AtomTableEntry*>(iter.Get());
*aMain += entry->mAtom->SizeOfIncludingThis(aMallocSizeOf);
}
}
// The atoms in the this table are almost certainly stored in static data, so
// we don't need a SizeOfEntry function.

Просмотреть файл

@ -318,29 +318,20 @@ public:
mozilla::MallocSizeOf aMallocSizeOf,
void* aUserArg = nullptr) const
{
size_t n = 0;
n += this->mTable.ShallowSizeOfExcludingThis(aMallocSizeOf);
if (aSizeOfEntryExcludingThis) {
s_SizeOfArgs args = { aSizeOfEntryExcludingThis, aUserArg };
return PL_DHashTableSizeOfExcludingThis(&this->mTable, s_SizeOfStub,
aMallocSizeOf, &args);
for (auto iter = ConstIter(); !iter.Done(); iter.Next()) {
n += aSizeOfEntryExcludingThis(iter.Key(), iter.Data(), aMallocSizeOf,
aUserArg);
}
}
return PL_DHashTableSizeOfExcludingThis(&this->mTable, nullptr,
aMallocSizeOf);
return n;
}
#ifdef DEBUG
using nsTHashtable<EntryType>::MarkImmutable;
#endif
protected:
struct s_SizeOfArgs
{
SizeOfEntryExcludingThisFun func;
void* userArg;
};
static size_t s_SizeOfStub(PLDHashEntryHdr* aEntry,
mozilla::MallocSizeOf aMallocSizeOf,
void* aArg);
};
//
@ -367,20 +358,4 @@ nsBaseHashtableET<KeyClass, DataType>::~nsBaseHashtableET()
{
}
//
// nsBaseHashtable definitions
//
template<class KeyClass, class DataType, class UserDataType>
size_t
nsBaseHashtable<KeyClass, DataType, UserDataType>::s_SizeOfStub(
PLDHashEntryHdr* aHdr, mozilla::MallocSizeOf aMallocSizeOf, void* aArg)
{
EntryType* ent = static_cast<EntryType*>(aHdr);
s_SizeOfArgs* eargs = static_cast<s_SizeOfArgs*>(aArg);
return (eargs->func)(ent->GetKey(), ent->mData, aMallocSizeOf, eargs->userArg);
}
#endif // nsBaseHashtable_h__

Просмотреть файл

@ -300,12 +300,14 @@ public:
mozilla::MallocSizeOf aMallocSizeOf,
void* aUserArg = nullptr) const
{
size_t n = 0;
n += mTable.ShallowSizeOfExcludingThis(aMallocSizeOf);
if (aSizeOfEntryExcludingThis) {
s_SizeOfArgs args = { aSizeOfEntryExcludingThis, aUserArg };
return PL_DHashTableSizeOfExcludingThis(&mTable, s_SizeOfStub,
aMallocSizeOf, &args);
for (auto iter = ConstIter(); !iter.Done(); iter.Next()) {
n += aSizeOfEntryExcludingThis(iter.Get(), aMallocSizeOf, aUserArg);
}
}
return PL_DHashTableSizeOfExcludingThis(&mTable, nullptr, aMallocSizeOf);
return n;
}
/**
@ -377,22 +379,6 @@ protected:
static void s_InitEntry(PLDHashEntryHdr* aEntry, const void* aKey);
/**
* passed internally during sizeOf counting. Allocated on the stack.
*
* @param userFunc the SizeOfEntryExcludingThisFun passed to
* SizeOf{In,Ex}cludingThis by the client
* @param userArg the userArg passed unaltered
*/
struct s_SizeOfArgs
{
SizeOfEntryExcludingThisFun userFunc;
void* userArg;
};
static size_t s_SizeOfStub(PLDHashEntryHdr* aEntry,
mozilla::MallocSizeOf aMallocSizeOf, void* aArg);
private:
// copy constructor, not implemented
nsTHashtable(nsTHashtable<EntryType>& aToCopy) = delete;
@ -509,19 +495,6 @@ nsTHashtable<EntryType>::s_InitEntry(PLDHashEntryHdr* aEntry,
new (aEntry) EntryType(reinterpret_cast<KeyTypePointer>(aKey));
}
template<class EntryType>
size_t
nsTHashtable<EntryType>::s_SizeOfStub(PLDHashEntryHdr* aEntry,
mozilla::MallocSizeOf aMallocSizeOf,
void* aArg)
{
// dereferences the function-pointer to the user's enumeration function
return (*reinterpret_cast<s_SizeOfArgs*>(aArg)->userFunc)(
static_cast<EntryType*>(aEntry),
aMallocSizeOf,
reinterpret_cast<s_SizeOfArgs*>(aArg)->userArg);
}
class nsCycleCollectionTraversalCallback;
template<class EntryType>

Просмотреть файл

@ -748,56 +748,20 @@ PLDHashTable::ShrinkIfAppropriate()
}
}
MOZ_ALWAYS_INLINE size_t
PLDHashTable::SizeOfExcludingThis(
PLDHashSizeOfEntryExcludingThisFun aSizeOfEntryExcludingThis,
MallocSizeOf aMallocSizeOf, void* aArg /* = nullptr */) const
size_t
PLDHashTable::ShallowSizeOfExcludingThis(MallocSizeOf aMallocSizeOf) const
{
#ifdef DEBUG
AutoReadOp op(mChecker);
#endif
if (!mEntryStore.Get()) {
return 0;
}
size_t n = aMallocSizeOf(mEntryStore.Get());
if (aSizeOfEntryExcludingThis) {
for (auto iter = ConstIter(); !iter.Done(); iter.Next()) {
n += aSizeOfEntryExcludingThis(iter.Get(), aMallocSizeOf, aArg);
}
}
return n;
}
MOZ_ALWAYS_INLINE size_t
PLDHashTable::SizeOfIncludingThis(
PLDHashSizeOfEntryExcludingThisFun aSizeOfEntryExcludingThis,
MallocSizeOf aMallocSizeOf, void* aArg /* = nullptr */) const
{
return aMallocSizeOf(this) +
SizeOfExcludingThis(aSizeOfEntryExcludingThis, aMallocSizeOf, aArg);
return aMallocSizeOf(mEntryStore.Get());
}
size_t
PL_DHashTableSizeOfExcludingThis(
const PLDHashTable* aTable,
PLDHashSizeOfEntryExcludingThisFun aSizeOfEntryExcludingThis,
MallocSizeOf aMallocSizeOf, void* aArg /* = nullptr */)
PLDHashTable::ShallowSizeOfIncludingThis(MallocSizeOf aMallocSizeOf) const
{
return aTable->SizeOfExcludingThis(aSizeOfEntryExcludingThis,
aMallocSizeOf, aArg);
}
size_t
PL_DHashTableSizeOfIncludingThis(
const PLDHashTable* aTable,
PLDHashSizeOfEntryExcludingThisFun aSizeOfEntryExcludingThis,
MallocSizeOf aMallocSizeOf, void* aArg /* = nullptr */)
{
return aTable->SizeOfIncludingThis(aSizeOfEntryExcludingThis,
aMallocSizeOf, aArg);
return aMallocSizeOf(this) + ShallowSizeOfExcludingThis(aMallocSizeOf);
}
PLDHashTable::Iterator::Iterator(Iterator&& aOther)

Просмотреть файл

@ -52,9 +52,6 @@ private:
PLDHashNumber mKeyHash;
};
typedef size_t (*PLDHashSizeOfEntryExcludingThisFun)(
PLDHashEntryHdr* aHdr, mozilla::MallocSizeOf aMallocSizeOf, void* aArg);
#ifdef DEBUG
// This class does three kinds of checking:
@ -375,17 +372,13 @@ public:
// a new |aLength| argument.
void ClearAndPrepareForLength(uint32_t aLength);
// Measure the size of the table's entry storage, and if
// |aSizeOfEntryExcludingThis| is non-nullptr, measure the size of things
// pointed to by entries.
size_t SizeOfIncludingThis(
PLDHashSizeOfEntryExcludingThisFun aSizeOfEntryExcludingThis,
mozilla::MallocSizeOf aMallocSizeOf, void* aArg = nullptr) const;
// Measure the size of the table's entry storage. If the entries contain
// pointers to other heap blocks, you have to iterate over the table and
// measure those separately; hence the "Shallow" prefix.
size_t ShallowSizeOfIncludingThis(mozilla::MallocSizeOf aMallocSizeOf) const;
// Like SizeOfExcludingThis(), but includes sizeof(*this).
size_t SizeOfExcludingThis(
PLDHashSizeOfEntryExcludingThisFun aSizeOfEntryExcludingThis,
mozilla::MallocSizeOf aMallocSizeOf, void* aArg = nullptr) const;
// Like ShallowSizeOfExcludingThis(), but includes sizeof(*this).
size_t ShallowSizeOfExcludingThis(mozilla::MallocSizeOf aMallocSizeOf) const;
#ifdef DEBUG
// Mark a table as immutable for the remainder of its lifetime. This
@ -635,18 +628,6 @@ PL_DHashTableRemove(PLDHashTable* aTable, const void* aKey);
void
PL_DHashTableRawRemove(PLDHashTable* aTable, PLDHashEntryHdr* aEntry);
size_t
PL_DHashTableSizeOfExcludingThis(
const PLDHashTable* aTable,
PLDHashSizeOfEntryExcludingThisFun aSizeOfEntryExcludingThis,
mozilla::MallocSizeOf aMallocSizeOf, void* aArg = nullptr);
size_t
PL_DHashTableSizeOfIncludingThis(
const PLDHashTable* aTable,
PLDHashSizeOfEntryExcludingThisFun aSizeOfEntryExcludingThis,
mozilla::MallocSizeOf aMallocSizeOf, void* aArg = nullptr);
#ifdef DEBUG
void
PL_DHashMarkTableImmutable(PLDHashTable* aTable);

Просмотреть файл

@ -137,10 +137,7 @@ TEST(PLDHashTableTest, LazyStorage)
ASSERT_TRUE(false); // shouldn't hit this on an empty table
}
// Using a null |mallocSizeOf| should be fine because it shouldn't be called
// for an empty table.
mozilla::MallocSizeOf mallocSizeOf = nullptr;
ASSERT_EQ(PL_DHashTableSizeOfExcludingThis(&t, nullptr, mallocSizeOf), 0u);
ASSERT_EQ(t.ShallowSizeOfExcludingThis(moz_malloc_size_of), 0u);
}
// A trivial hash function is good enough here. It's also super-fast for