Bug 1266639 - Don't separately heap-allocate PLDHashTables within XPCMaps. r=mrbkap.

Most of the XPCMap classes contain a |PLDHashTable*|. This can be changed to a
|PLDHashTable|, which avoids some malloc/free calls, removes the needs for
explicit destructors, and removes "can this pointer be null?" questions.

The patch also cleans up the iterators provided by XPCMap classes a little.

MozReview-Commit-ID: K0VdJdZSM7z

--HG--
extra : rebase_source : 9991c6510b86ef39d21009faa37c51a3f37e623d
This commit is contained in:
Nicholas Nethercote 2016-04-22 15:19:51 +10:00
Родитель fa4e4a6fd2
Коммит fbb397a1bf
2 изменённых файлов: 71 добавлений и 126 удалений

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

@ -164,21 +164,16 @@ Native2WrappedNativeMap::newMap(int length)
}
Native2WrappedNativeMap::Native2WrappedNativeMap(int length)
: mTable(new PLDHashTable(PLDHashTable::StubOps(), sizeof(Entry), length))
: mTable(PLDHashTable::StubOps(), sizeof(Entry), length)
{
}
Native2WrappedNativeMap::~Native2WrappedNativeMap()
{
delete mTable;
}
size_t
Native2WrappedNativeMap::SizeOfIncludingThis(mozilla::MallocSizeOf mallocSizeOf) const
{
size_t n = mallocSizeOf(this);
n += mTable->ShallowSizeOfIncludingThis(mallocSizeOf);
for (auto iter = mTable->Iter(); !iter.Done(); iter.Next()) {
n += mTable.ShallowSizeOfExcludingThis(mallocSizeOf);
for (auto iter = mTable.ConstIter(); !iter.Done(); iter.Next()) {
auto entry = static_cast<Native2WrappedNativeMap::Entry*>(iter.Get());
n += mallocSizeOf(entry->value);
}
@ -204,15 +199,10 @@ IID2WrappedJSClassMap::newMap(int length)
}
IID2WrappedJSClassMap::IID2WrappedJSClassMap(int length)
: mTable(new PLDHashTable(&Entry::sOps, sizeof(Entry), length))
: mTable(&Entry::sOps, sizeof(Entry), length)
{
}
IID2WrappedJSClassMap::~IID2WrappedJSClassMap()
{
delete mTable;
}
/***************************************************************************/
// implement IID2NativeInterfaceMap...
@ -232,21 +222,16 @@ IID2NativeInterfaceMap::newMap(int length)
}
IID2NativeInterfaceMap::IID2NativeInterfaceMap(int length)
: mTable(new PLDHashTable(&Entry::sOps, sizeof(Entry), length))
: mTable(&Entry::sOps, sizeof(Entry), length)
{
}
IID2NativeInterfaceMap::~IID2NativeInterfaceMap()
{
delete mTable;
}
size_t
IID2NativeInterfaceMap::SizeOfIncludingThis(mozilla::MallocSizeOf mallocSizeOf) const
{
size_t n = mallocSizeOf(this);
n += mTable->ShallowSizeOfIncludingThis(mallocSizeOf);
for (auto iter = mTable->Iter(); !iter.Done(); iter.Next()) {
n += mTable.ShallowSizeOfExcludingThis(mallocSizeOf);
for (auto iter = mTable.ConstIter(); !iter.Done(); iter.Next()) {
auto entry = static_cast<IID2NativeInterfaceMap::Entry*>(iter.Get());
n += entry->value->SizeOfIncludingThis(mallocSizeOf);
}
@ -264,20 +249,15 @@ ClassInfo2NativeSetMap::newMap(int length)
}
ClassInfo2NativeSetMap::ClassInfo2NativeSetMap(int length)
: mTable(new PLDHashTable(PLDHashTable::StubOps(), sizeof(Entry), length))
: mTable(PLDHashTable::StubOps(), sizeof(Entry), length)
{
}
ClassInfo2NativeSetMap::~ClassInfo2NativeSetMap()
{
delete mTable;
}
size_t
ClassInfo2NativeSetMap::ShallowSizeOfIncludingThis(mozilla::MallocSizeOf mallocSizeOf)
{
size_t n = mallocSizeOf(this);
n += mTable->ShallowSizeOfIncludingThis(mallocSizeOf);
n += mTable.ShallowSizeOfExcludingThis(mallocSizeOf);
return n;
}
@ -292,21 +272,16 @@ ClassInfo2WrappedNativeProtoMap::newMap(int length)
}
ClassInfo2WrappedNativeProtoMap::ClassInfo2WrappedNativeProtoMap(int length)
: mTable(new PLDHashTable(PLDHashTable::StubOps(), sizeof(Entry), length))
: mTable(PLDHashTable::StubOps(), sizeof(Entry), length)
{
}
ClassInfo2WrappedNativeProtoMap::~ClassInfo2WrappedNativeProtoMap()
{
delete mTable;
}
size_t
ClassInfo2WrappedNativeProtoMap::SizeOfIncludingThis(mozilla::MallocSizeOf mallocSizeOf) const
{
size_t n = mallocSizeOf(this);
n += mTable->ShallowSizeOfIncludingThis(mallocSizeOf);
for (auto iter = mTable->Iter(); !iter.Done(); iter.Next()) {
n += mTable.ShallowSizeOfExcludingThis(mallocSizeOf);
for (auto iter = mTable.ConstIter(); !iter.Done(); iter.Next()) {
auto entry = static_cast<ClassInfo2WrappedNativeProtoMap::Entry*>(iter.Get());
n += mallocSizeOf(entry->value);
}
@ -402,21 +377,16 @@ NativeSetMap::newMap(int length)
}
NativeSetMap::NativeSetMap(int length)
: mTable(new PLDHashTable(&Entry::sOps, sizeof(Entry), length))
: mTable(&Entry::sOps, sizeof(Entry), length)
{
}
NativeSetMap::~NativeSetMap()
{
delete mTable;
}
size_t
NativeSetMap::SizeOfIncludingThis(mozilla::MallocSizeOf mallocSizeOf) const
{
size_t n = mallocSizeOf(this);
n += mTable->ShallowSizeOfIncludingThis(mallocSizeOf);
for (auto iter = mTable->Iter(); !iter.Done(); iter.Next()) {
n += mTable.ShallowSizeOfExcludingThis(mallocSizeOf);
for (auto iter = mTable.ConstIter(); !iter.Done(); iter.Next()) {
auto entry = static_cast<NativeSetMap::Entry*>(iter.Get());
n += entry->key_value->SizeOfIncludingThis(mallocSizeOf);
}
@ -456,15 +426,10 @@ IID2ThisTranslatorMap::newMap(int length)
}
IID2ThisTranslatorMap::IID2ThisTranslatorMap(int length)
: mTable(new PLDHashTable(&Entry::sOps, sizeof(Entry), length))
: mTable(&Entry::sOps, sizeof(Entry), length)
{
}
IID2ThisTranslatorMap::~IID2ThisTranslatorMap()
{
delete mTable;
}
/***************************************************************************/
PLDHashNumber
@ -526,15 +491,10 @@ XPCNativeScriptableSharedMap::newMap(int length)
}
XPCNativeScriptableSharedMap::XPCNativeScriptableSharedMap(int length)
: mTable(new PLDHashTable(&Entry::sOps, sizeof(Entry), length))
: mTable(&Entry::sOps, sizeof(Entry), length)
{
}
XPCNativeScriptableSharedMap::~XPCNativeScriptableSharedMap()
{
delete mTable;
}
bool
XPCNativeScriptableSharedMap::GetNewOrUsed(uint32_t flags,
char* name,
@ -544,7 +504,7 @@ XPCNativeScriptableSharedMap::GetNewOrUsed(uint32_t flags,
NS_PRECONDITION(si,"bad param");
XPCNativeScriptableShared key(flags, name, /* populate = */ false);
auto entry = static_cast<Entry*>(mTable->Add(&key, fallible));
auto entry = static_cast<Entry*>(mTable.Add(&key, fallible));
if (!entry)
return false;
@ -579,14 +539,8 @@ XPCWrappedNativeProtoMap::newMap(int length)
}
XPCWrappedNativeProtoMap::XPCWrappedNativeProtoMap(int length)
: mTable(new PLDHashTable(PLDHashTable::StubOps(), sizeof(PLDHashEntryStub),
length))
: mTable(PLDHashTable::StubOps(), sizeof(PLDHashEntryStub), length)
{
}
XPCWrappedNativeProtoMap::~XPCWrappedNativeProtoMap()
{
delete mTable;
}
/***************************************************************************/

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

@ -115,7 +115,7 @@ public:
inline XPCWrappedNative* Find(nsISupports* Obj)
{
NS_PRECONDITION(Obj,"bad param");
auto entry = static_cast<Entry*>(mTable->Search(Obj));
auto entry = static_cast<Entry*>(mTable.Search(Obj));
return entry ? entry->value : nullptr;
}
@ -124,7 +124,7 @@ public:
NS_PRECONDITION(wrapper,"bad param");
nsISupports* obj = wrapper->GetIdentityObject();
MOZ_ASSERT(!Find(obj), "wrapper already in new scope!");
auto entry = static_cast<Entry*>(mTable->Add(obj, mozilla::fallible));
auto entry = static_cast<Entry*>(mTable.Add(obj, mozilla::fallible));
if (!entry)
return nullptr;
if (entry->key)
@ -144,21 +144,21 @@ public:
"nsISupports identity! This will most likely cause serious "
"problems!");
#endif
mTable->Remove(wrapper->GetIdentityObject());
mTable.Remove(wrapper->GetIdentityObject());
}
inline uint32_t Count() { return mTable->EntryCount(); }
inline uint32_t Count() { return mTable.EntryCount(); }
PLDHashTable::Iterator Iter() { return mTable.Iter(); }
PLDHashTable::Iterator Iter() const { return PLDHashTable::Iterator(mTable); }
size_t SizeOfIncludingThis(mozilla::MallocSizeOf mallocSizeOf) const;
~Native2WrappedNativeMap();
private:
Native2WrappedNativeMap(); // no implementation
explicit Native2WrappedNativeMap(int size);
private:
PLDHashTable* mTable;
PLDHashTable mTable;
};
/*************************/
@ -178,7 +178,7 @@ public:
inline nsXPCWrappedJSClass* Find(REFNSIID iid)
{
auto entry = static_cast<Entry*>(mTable->Search(&iid));
auto entry = static_cast<Entry*>(mTable.Search(&iid));
return entry ? entry->value : nullptr;
}
@ -186,7 +186,7 @@ public:
{
NS_PRECONDITION(clazz,"bad param");
const nsIID* iid = &clazz->GetIID();
auto entry = static_cast<Entry*>(mTable->Add(iid, mozilla::fallible));
auto entry = static_cast<Entry*>(mTable.Add(iid, mozilla::fallible));
if (!entry)
return nullptr;
if (entry->key)
@ -199,19 +199,20 @@ public:
inline void Remove(nsXPCWrappedJSClass* clazz)
{
NS_PRECONDITION(clazz,"bad param");
mTable->Remove(&clazz->GetIID());
mTable.Remove(&clazz->GetIID());
}
inline uint32_t Count() { return mTable->EntryCount(); }
inline uint32_t Count() { return mTable.EntryCount(); }
PLDHashTable::Iterator Iter() const { return PLDHashTable::Iterator(mTable); }
#ifdef DEBUG
PLDHashTable::Iterator Iter() { return mTable.Iter(); }
#endif
~IID2WrappedJSClassMap();
private:
IID2WrappedJSClassMap(); // no implementation
explicit IID2WrappedJSClassMap(int size);
private:
PLDHashTable* mTable;
PLDHashTable mTable;
};
/*************************/
@ -231,7 +232,7 @@ public:
inline XPCNativeInterface* Find(REFNSIID iid)
{
auto entry = static_cast<Entry*>(mTable->Search(&iid));
auto entry = static_cast<Entry*>(mTable.Search(&iid));
return entry ? entry->value : nullptr;
}
@ -239,7 +240,7 @@ public:
{
NS_PRECONDITION(iface,"bad param");
const nsIID* iid = iface->GetIID();
auto entry = static_cast<Entry*>(mTable->Add(iid, mozilla::fallible));
auto entry = static_cast<Entry*>(mTable.Add(iid, mozilla::fallible));
if (!entry)
return nullptr;
if (entry->key)
@ -252,22 +253,21 @@ public:
inline void Remove(XPCNativeInterface* iface)
{
NS_PRECONDITION(iface,"bad param");
mTable->Remove(iface->GetIID());
mTable.Remove(iface->GetIID());
}
inline uint32_t Count() { return mTable->EntryCount(); }
inline uint32_t Count() { return mTable.EntryCount(); }
PLDHashTable::Iterator Iter() { return PLDHashTable::Iterator(mTable); }
PLDHashTable::Iterator Iter() { return mTable.Iter(); }
size_t SizeOfIncludingThis(mozilla::MallocSizeOf mallocSizeOf) const;
~IID2NativeInterfaceMap();
private:
IID2NativeInterfaceMap(); // no implementation
explicit IID2NativeInterfaceMap(int size);
private:
PLDHashTable* mTable;
PLDHashTable mTable;
};
/*************************/
@ -285,14 +285,14 @@ public:
inline XPCNativeSet* Find(nsIClassInfo* info)
{
auto entry = static_cast<Entry*>(mTable->Search(info));
auto entry = static_cast<Entry*>(mTable.Search(info));
return entry ? entry->value : nullptr;
}
inline XPCNativeSet* Add(nsIClassInfo* info, XPCNativeSet* set)
{
NS_PRECONDITION(info,"bad param");
auto entry = static_cast<Entry*>(mTable->Add(info, mozilla::fallible));
auto entry = static_cast<Entry*>(mTable.Add(info, mozilla::fallible));
if (!entry)
return nullptr;
if (entry->key)
@ -305,12 +305,12 @@ public:
inline void Remove(nsIClassInfo* info)
{
NS_PRECONDITION(info,"bad param");
mTable->Remove(info);
mTable.Remove(info);
}
inline uint32_t Count() { return mTable->EntryCount(); }
inline uint32_t Count() { return mTable.EntryCount(); }
PLDHashTable::Iterator Iter() { return PLDHashTable::Iterator(mTable); }
PLDHashTable::Iterator Iter() { return mTable.Iter(); }
// ClassInfo2NativeSetMap holds pointers to *some* XPCNativeSets.
// So we don't want to count those XPCNativeSets, because they are better
@ -318,12 +318,11 @@ public:
// pointers to *all* XPCNativeSets). Hence the "Shallow".
size_t ShallowSizeOfIncludingThis(mozilla::MallocSizeOf mallocSizeOf);
~ClassInfo2NativeSetMap();
private:
ClassInfo2NativeSetMap(); // no implementation
explicit ClassInfo2NativeSetMap(int size);
private:
PLDHashTable* mTable;
PLDHashTable mTable;
};
/*************************/
@ -341,14 +340,14 @@ public:
inline XPCWrappedNativeProto* Find(nsIClassInfo* info)
{
auto entry = static_cast<Entry*>(mTable->Search(info));
auto entry = static_cast<Entry*>(mTable.Search(info));
return entry ? entry->value : nullptr;
}
inline XPCWrappedNativeProto* Add(nsIClassInfo* info, XPCWrappedNativeProto* proto)
{
NS_PRECONDITION(info,"bad param");
auto entry = static_cast<Entry*>(mTable->Add(info, mozilla::fallible));
auto entry = static_cast<Entry*>(mTable.Add(info, mozilla::fallible));
if (!entry)
return nullptr;
if (entry->key)
@ -361,23 +360,21 @@ public:
inline void Remove(nsIClassInfo* info)
{
NS_PRECONDITION(info,"bad param");
mTable->Remove(info);
mTable.Remove(info);
}
inline uint32_t Count() { return mTable->EntryCount(); }
inline uint32_t Count() { return mTable.EntryCount(); }
PLDHashTable::Iterator Iter() const { return PLDHashTable::Iterator(mTable); }
PLDHashTable::Iterator Iter() { return PLDHashTable::Iterator(mTable); }
PLDHashTable::Iterator Iter() { return mTable.Iter(); }
size_t SizeOfIncludingThis(mozilla::MallocSizeOf mallocSizeOf) const;
~ClassInfo2WrappedNativeProtoMap();
private:
ClassInfo2WrappedNativeProtoMap(); // no implementation
explicit ClassInfo2WrappedNativeProtoMap(int size);
private:
PLDHashTable* mTable;
PLDHashTable mTable;
};
/*************************/
@ -399,7 +396,7 @@ public:
inline XPCNativeSet* Find(XPCNativeSetKey* key)
{
auto entry = static_cast<Entry*>(mTable->Search(key));
auto entry = static_cast<Entry*>(mTable.Search(key));
return entry ? entry->key_value : nullptr;
}
@ -407,7 +404,7 @@ public:
{
NS_PRECONDITION(key,"bad param");
NS_PRECONDITION(set,"bad param");
auto entry = static_cast<Entry*>(mTable->Add(key, mozilla::fallible));
auto entry = static_cast<Entry*>(mTable.Add(key, mozilla::fallible));
if (!entry)
return nullptr;
if (entry->key_value)
@ -427,23 +424,21 @@ public:
NS_PRECONDITION(set,"bad param");
XPCNativeSetKey key(set, nullptr, 0);
mTable->Remove(&key);
mTable.Remove(&key);
}
inline uint32_t Count() { return mTable->EntryCount(); }
inline uint32_t Count() { return mTable.EntryCount(); }
PLDHashTable::Iterator Iter() const { return PLDHashTable::Iterator(mTable); }
PLDHashTable::Iterator Iter() { return PLDHashTable::Iterator(mTable); }
PLDHashTable::Iterator Iter() { return mTable.Iter(); }
size_t SizeOfIncludingThis(mozilla::MallocSizeOf mallocSizeOf) const;
~NativeSetMap();
private:
NativeSetMap(); // no implementation
explicit NativeSetMap(int size);
private:
PLDHashTable* mTable;
PLDHashTable mTable;
};
/***************************************************************************/
@ -469,14 +464,14 @@ public:
inline nsIXPCFunctionThisTranslator* Find(REFNSIID iid)
{
auto entry = static_cast<Entry*>(mTable->Search(&iid));
auto entry = static_cast<Entry*>(mTable.Search(&iid));
return entry ? entry->value : nullptr;
}
inline nsIXPCFunctionThisTranslator* Add(REFNSIID iid,
nsIXPCFunctionThisTranslator* obj)
{
auto entry = static_cast<Entry*>(mTable->Add(&iid, mozilla::fallible));
auto entry = static_cast<Entry*>(mTable.Add(&iid, mozilla::fallible));
if (!entry)
return nullptr;
entry->value = obj;
@ -486,17 +481,16 @@ public:
inline void Remove(REFNSIID iid)
{
mTable->Remove(&iid);
mTable.Remove(&iid);
}
inline uint32_t Count() { return mTable->EntryCount(); }
inline uint32_t Count() { return mTable.EntryCount(); }
~IID2ThisTranslatorMap();
private:
IID2ThisTranslatorMap(); // no implementation
explicit IID2ThisTranslatorMap(int size);
private:
PLDHashTable* mTable;
PLDHashTable mTable;
};
/***************************************************************************/
@ -521,16 +515,15 @@ public:
bool GetNewOrUsed(uint32_t flags, char* name, XPCNativeScriptableInfo* si);
inline uint32_t Count() { return mTable->EntryCount(); }
inline uint32_t Count() { return mTable.EntryCount(); }
PLDHashTable::Iterator Iter() { return PLDHashTable::Iterator(mTable); }
PLDHashTable::Iterator Iter() { return mTable.Iter(); }
~XPCNativeScriptableSharedMap();
private:
XPCNativeScriptableSharedMap(); // no implementation
explicit XPCNativeScriptableSharedMap(int size);
private:
PLDHashTable* mTable;
PLDHashTable mTable;
};
/***************************************************************************/
@ -546,7 +539,7 @@ public:
{
NS_PRECONDITION(proto,"bad param");
auto entry = static_cast<PLDHashEntryStub*>
(mTable->Add(proto, mozilla::fallible));
(mTable.Add(proto, mozilla::fallible));
if (!entry)
return nullptr;
if (entry->key)
@ -558,20 +551,18 @@ public:
inline void Remove(XPCWrappedNativeProto* proto)
{
NS_PRECONDITION(proto,"bad param");
mTable->Remove(proto);
mTable.Remove(proto);
}
inline uint32_t Count() { return mTable->EntryCount(); }
inline uint32_t Count() { return mTable.EntryCount(); }
PLDHashTable::Iterator Iter() const { return PLDHashTable::Iterator(mTable); }
PLDHashTable::Iterator Iter() { return PLDHashTable::Iterator(mTable); }
PLDHashTable::Iterator Iter() { return mTable.Iter(); }
~XPCWrappedNativeProtoMap();
private:
XPCWrappedNativeProtoMap(); // no implementation
explicit XPCWrappedNativeProtoMap(int size);
private:
PLDHashTable* mTable;
PLDHashTable mTable;
};
/***************************************************************************/