Bug 1161377 (part 3, attempt 2) - Convert some easy PL_DHashTable{Init,Finish} cases. r=froydnj.

This commit is contained in:
Nicholas Nethercote 2015-05-12 17:33:26 -07:00
parent dca9bdb5a5
commit 058f304862
9 changed files with 58 additions and 125 deletions

View File

@ -287,21 +287,18 @@ nsPropertyTable::PropertyList::PropertyList(nsIAtom *aName,
void *aDtorData,
bool aTransfer)
: mName(aName),
mObjectValueMap(PL_DHashGetStubOps(), sizeof(PropertyListMapEntry)),
mDtorFunc(aDtorFunc),
mDtorData(aDtorData),
mTransfer(aTransfer),
mNext(nullptr)
{
PL_DHashTableInit(&mObjectValueMap, PL_DHashGetStubOps(),
sizeof(PropertyListMapEntry));
}
nsPropertyTable::PropertyList::~PropertyList()
{
PL_DHashTableFinish(&mObjectValueMap);
}
static PLDHashOperator
DestroyPropertyEnumerator(PLDHashTable *table, PLDHashEntryHdr *hdr,
uint32_t number, void *arg)

View File

@ -617,18 +617,9 @@ FT2FontFamily::AddFacesToFontList(InfallibleTArray<FontListEntry>* aFontList,
class FontNameCache {
public:
FontNameCache()
: mWriteNeeded(false)
: mMap(&sMapOps, sizeof(FNCMapEntry), 0)
, mWriteNeeded(false)
{
mOps = (PLDHashTableOps) {
StringHash,
HashMatchEntry,
MoveEntry,
PL_DHashClearEntryStub,
nullptr
};
PL_DHashTableInit(&mMap, &mOps, sizeof(FNCMapEntry), 0);
MOZ_ASSERT(XRE_GetProcessType() == GeckoProcessType_Default,
"StartupCacheFontNameCache should only be used in chrome "
"process");
@ -639,17 +630,12 @@ public:
~FontNameCache()
{
if (!mMap.IsInitialized()) {
return;
}
if (!mWriteNeeded || !mCache) {
PL_DHashTableFinish(&mMap);
return;
}
nsAutoCString buf;
PL_DHashTableEnumerate(&mMap, WriteOutMap, &buf);
PL_DHashTableFinish(&mMap);
mCache->PutBuffer(CACHE_KEY, buf.get(), buf.Length() + 1);
}
@ -751,7 +737,7 @@ private:
PLDHashTable mMap;
bool mWriteNeeded;
PLDHashTableOps mOps;
static const PLDHashTableOps sMapOps;
static PLDHashOperator WriteOutMap(PLDHashTable *aTable,
PLDHashEntryHdr *aHdr,
@ -810,6 +796,15 @@ private:
}
};
/* static */ const PLDHashTableOps FontNameCache::sMapOps =
{
FontNameCache::StringHash,
FontNameCache::HashMatchEntry,
FontNameCache::MoveEntry,
PL_DHashClearEntryStub,
nullptr
};
/***************************************************************
*
* gfxFT2FontList

View File

@ -489,6 +489,14 @@ protected:
RuleHash::RuleHash(bool aQuirksMode)
: mRuleCount(0),
mIdTable(aQuirksMode ? &RuleHash_IdTable_CIOps.ops
: &RuleHash_IdTable_CSOps.ops,
sizeof(RuleHashTableEntry)),
mClassTable(aQuirksMode ? &RuleHash_ClassTable_CIOps.ops
: &RuleHash_ClassTable_CSOps.ops,
sizeof(RuleHashTableEntry)),
mTagTable(&RuleHash_TagTable_Ops, sizeof(RuleHashTagTableEntry)),
mNameSpaceTable(&RuleHash_NameSpaceTable_Ops, sizeof(RuleHashTableEntry)),
mUniversalRules(0),
mEnumList(nullptr), mEnumListSize(0),
mQuirksMode(aQuirksMode)
@ -508,20 +516,6 @@ RuleHash::RuleHash(bool aQuirksMode)
#endif
{
MOZ_COUNT_CTOR(RuleHash);
PL_DHashTableInit(&mIdTable, aQuirksMode ? &RuleHash_IdTable_CIOps.ops
: &RuleHash_IdTable_CSOps.ops,
sizeof(RuleHashTableEntry));
PL_DHashTableInit(&mClassTable, aQuirksMode ? &RuleHash_ClassTable_CIOps.ops
: &RuleHash_ClassTable_CSOps.ops,
sizeof(RuleHashTableEntry));
PL_DHashTableInit(&mTagTable, &RuleHash_TagTable_Ops,
sizeof(RuleHashTagTableEntry));
PL_DHashTableInit(&mNameSpaceTable, &RuleHash_NameSpaceTable_Ops,
sizeof(RuleHashTableEntry));
}
RuleHash::~RuleHash()
@ -563,11 +557,6 @@ RuleHash::~RuleHash()
if (nullptr != mEnumList) {
delete [] mEnumList;
}
// delete arena for strings and small objects
PL_DHashTableFinish(&mIdTable);
PL_DHashTableFinish(&mClassTable);
PL_DHashTableFinish(&mTagTable);
PL_DHashTableFinish(&mNameSpaceTable);
}
void RuleHash::AppendRuleToTable(PLDHashTable* aTable, const void* aKey,
@ -866,42 +855,31 @@ struct RuleCascadeData {
: mRuleHash(aQuirksMode),
mStateSelectors(),
mSelectorDocumentStates(0),
mClassSelectors(aQuirksMode ? &AtomSelector_CIOps.ops
: &AtomSelector_CSOps,
sizeof(AtomSelectorEntry)),
mIdSelectors(aQuirksMode ? &AtomSelector_CIOps.ops
: &AtomSelector_CSOps,
sizeof(AtomSelectorEntry)),
// mAttributeSelectors is matching on the attribute _name_, not the
// value, and we case-fold names at parse-time, so this is a
// case-sensitive match.
mAttributeSelectors(&AtomSelector_CSOps, sizeof(AtomSelectorEntry)),
mAnonBoxRules(&RuleHash_TagTable_Ops, sizeof(RuleHashTagTableEntry)),
#ifdef MOZ_XUL
mXULTreeRules(&RuleHash_TagTable_Ops, sizeof(RuleHashTagTableEntry)),
#endif
mKeyframesRuleTable(),
mCounterStyleRuleTable(),
mCacheKey(aMedium),
mNext(nullptr),
mQuirksMode(aQuirksMode)
{
// mAttributeSelectors is matching on the attribute _name_, not the value,
// and we case-fold names at parse-time, so this is a case-sensitive match.
PL_DHashTableInit(&mAttributeSelectors, &AtomSelector_CSOps,
sizeof(AtomSelectorEntry));
PL_DHashTableInit(&mAnonBoxRules, &RuleHash_TagTable_Ops,
sizeof(RuleHashTagTableEntry));
PL_DHashTableInit(&mIdSelectors,
aQuirksMode ? &AtomSelector_CIOps.ops :
&AtomSelector_CSOps,
sizeof(AtomSelectorEntry));
PL_DHashTableInit(&mClassSelectors,
aQuirksMode ? &AtomSelector_CIOps.ops :
&AtomSelector_CSOps,
sizeof(AtomSelectorEntry));
memset(mPseudoElementRuleHashes, 0, sizeof(mPseudoElementRuleHashes));
#ifdef MOZ_XUL
PL_DHashTableInit(&mXULTreeRules, &RuleHash_TagTable_Ops,
sizeof(RuleHashTagTableEntry));
#endif
}
~RuleCascadeData()
{
PL_DHashTableFinish(&mAttributeSelectors);
PL_DHashTableFinish(&mAnonBoxRules);
PL_DHashTableFinish(&mIdSelectors);
PL_DHashTableFinish(&mClassSelectors);
#ifdef MOZ_XUL
PL_DHashTableFinish(&mXULTreeRules);
#endif
for (uint32_t i = 0; i < ArrayLength(mPseudoElementRuleHashes); ++i) {
delete mPseudoElementRuleHashes[i];
}
@ -3320,11 +3298,9 @@ struct CascadeEnumData {
mPageRules(aPageRules),
mCounterStyleRules(aCounterStyleRules),
mCacheKey(aKey),
mRulesByWeight(&gRulesByWeightOps, sizeof(RuleByWeightEntry), 32),
mSheetType(aSheetType)
{
PL_DHashTableInit(&mRulesByWeight, &gRulesByWeightOps,
sizeof(RuleByWeightEntry), 32);
// Initialize our arena
PL_INIT_ARENA_POOL(&mArena, "CascadeEnumDataArena",
NS_CASCADEENUMDATA_ARENA_BLOCK_SIZE);
@ -3332,8 +3308,6 @@ struct CascadeEnumData {
~CascadeEnumData()
{
if (mRulesByWeight.IsInitialized())
PL_DHashTableFinish(&mRulesByWeight);
PL_FinishArenaPool(&mArena);
}

View File

@ -39,22 +39,15 @@ static const PLDHashTableOps gSetOps = {
nsNSSShutDownList *nsNSSShutDownList::singleton = nullptr;
nsNSSShutDownList::nsNSSShutDownList()
:mListLock("nsNSSShutDownList.mListLock")
: mListLock("nsNSSShutDownList.mListLock")
, mActiveSSLSockets(0)
, mObjects(&gSetOps, sizeof(ObjectHashEntry))
, mPK11LogoutCancelObjects(&gSetOps, sizeof(ObjectHashEntry))
{
mActiveSSLSockets = 0;
PL_DHashTableInit(&mObjects, &gSetOps, sizeof(ObjectHashEntry));
PL_DHashTableInit(&mPK11LogoutCancelObjects, &gSetOps,
sizeof(ObjectHashEntry));
}
nsNSSShutDownList::~nsNSSShutDownList()
{
if (mObjects.IsInitialized()) {
PL_DHashTableFinish(&mObjects);
}
if (mPK11LogoutCancelObjects.IsInitialized()) {
PL_DHashTableFinish(&mPK11LogoutCancelObjects);
}
PR_ASSERT(this == singleton);
singleton = nullptr;
}

View File

@ -157,8 +157,8 @@ private:
protected:
mozilla::Mutex mListLock;
static nsNSSShutDownList *singleton;
PLDHashTable mObjects;
uint32_t mActiveSSLSockets;
PLDHashTable mObjects;
PLDHashTable mPK11LogoutCancelObjects;
nsNSSActivityState mActivityState;
};

View File

@ -91,12 +91,22 @@ class nsDefaultComparator <nsDocLoader::nsListenerInfo, nsIWebProgressListener*>
}
};
/* static */ const PLDHashTableOps nsDocLoader::sRequestInfoHashOps =
{
PL_DHashVoidPtrKeyStub,
PL_DHashMatchEntryStub,
PL_DHashMoveEntryStub,
nsDocLoader::RequestInfoHashClearEntry,
nsDocLoader::RequestInfoHashInitEntry
};
nsDocLoader::nsDocLoader()
: mParent(nullptr),
mCurrentSelfProgress(0),
mMaxSelfProgress(0),
mCurrentTotalProgress(0),
mMaxTotalProgress(0),
mRequestInfoHash(&sRequestInfoHashOps, sizeof(nsRequestInfo)),
mCompletedTotalProgress(0),
mIsLoadingDocument(false),
mIsRestoringDocument(false),
@ -107,17 +117,6 @@ nsDocLoader::nsDocLoader()
gDocLoaderLog = PR_NewLogModule("DocLoader");
}
static const PLDHashTableOps hash_table_ops =
{
PL_DHashVoidPtrKeyStub,
PL_DHashMatchEntryStub,
PL_DHashMoveEntryStub,
RequestInfoHashClearEntry,
RequestInfoHashInitEntry
};
PL_DHashTableInit(&mRequestInfoHash, &hash_table_ops, sizeof(nsRequestInfo));
ClearInternalProgress();
PR_LOG(gDocLoaderLog, PR_LOG_DEBUG,
@ -134,10 +133,6 @@ nsDocLoader::SetDocLoaderParent(nsDocLoader *aParent)
nsresult
nsDocLoader::Init()
{
if (!mRequestInfoHash.IsInitialized()) {
return NS_ERROR_OUT_OF_MEMORY;
}
nsresult rv = NS_NewLoadGroup(getter_AddRefs(mLoadGroup), this);
if (NS_FAILED(rv)) return rv;
@ -166,10 +161,6 @@ nsDocLoader::~nsDocLoader()
PR_LOG(gDocLoaderLog, PR_LOG_DEBUG,
("DocLoader:%p: deleted.\n", this));
if (mRequestInfoHash.IsInitialized()) {
PL_DHashTableFinish(&mRequestInfoHash);
}
}
@ -1361,12 +1352,6 @@ RemoveInfoCallback(PLDHashTable *table, PLDHashEntryHdr *hdr, uint32_t number,
void nsDocLoader::ClearRequestInfoHash(void)
{
if (!mRequestInfoHash.IsInitialized() || !mRequestInfoHash.EntryCount()) {
// No hash, or the hash is empty, nothing to do here then...
return;
}
PL_DHashTableEnumerate(&mRequestInfoHash, RemoveInfoCallback, nullptr);
}

View File

@ -302,6 +302,8 @@ protected:
bool mIsFlushingLayout;
private:
static const PLDHashTableOps sRequestInfoHashOps;
// A list of kids that are in the middle of their onload calls and will let
// us know once they're done. We don't want to fire onload for "normal"
// DocLoaderIsEmpty calls (those coming from requests finishing in our

View File

@ -460,19 +460,14 @@ nsPropertiesParser::ParseBuffer(const char16_t* aBuffer,
nsPersistentProperties::nsPersistentProperties()
: mIn(nullptr)
, mTable(&property_HashTableOps, sizeof(PropertyTableEntry), 16)
{
PL_DHashTableInit(&mTable, &property_HashTableOps,
sizeof(PropertyTableEntry), 16);
PL_INIT_ARENA_POOL(&mArena, "PersistentPropertyArena", 2048);
}
nsPersistentProperties::~nsPersistentProperties()
{
PL_FinishArenaPool(&mArena);
if (mTable.IsInitialized()) {
PL_DHashTableFinish(&mTable);
}
}
nsresult

View File

@ -53,8 +53,7 @@ static bool test_pldhash_Init_capacity_ok()
static bool test_pldhash_lazy_storage()
{
PLDHashTable t;
PL_DHashTableInit(&t, PL_DHashGetStubOps(), sizeof(PLDHashEntryStub));
PLDHashTable t(PL_DHashGetStubOps(), sizeof(PLDHashEntryStub));
// PLDHashTable allocates entry storage lazily. Check that all the non-add
// operations work appropriately when the table is empty and the storage
@ -107,8 +106,6 @@ static bool test_pldhash_lazy_storage()
return false; // size is non-zero?
}
PL_DHashTableFinish(&t);
return true;
}
@ -131,19 +128,15 @@ static bool test_pldhash_move_semantics()
nullptr
};
PLDHashTable t1, t2;
PL_DHashTableInit(&t1, &ops, sizeof(PLDHashEntryStub));
PLDHashTable t1(&ops, sizeof(PLDHashEntryStub));
PL_DHashTableAdd(&t1, (const void*)88);
PL_DHashTableInit(&t2, &ops, sizeof(PLDHashEntryStub));
PLDHashTable t2(&ops, sizeof(PLDHashEntryStub));
PL_DHashTableAdd(&t2, (const void*)99);
t1 = mozilla::Move(t1); // self-move
t1 = mozilla::Move(t2); // inited overwritten with inited
PL_DHashTableFinish(&t1);
PL_DHashTableFinish(&t2);
PLDHashTable t3, t4;
PL_DHashTableInit(&t3, &ops, sizeof(PLDHashEntryStub));
PL_DHashTableAdd(&t3, (const void*)88);
@ -165,8 +158,7 @@ static bool test_pldhash_move_semantics()
PLDHashTable t7;
PLDHashTable t8(mozilla::Move(t7)); // new table constructed with uninited
PLDHashTable t9;
PL_DHashTableInit(&t9, &ops, sizeof(PLDHashEntryStub));
PLDHashTable t9(&ops, sizeof(PLDHashEntryStub));
PL_DHashTableAdd(&t9, (const void*)88);
PLDHashTable t10(mozilla::Move(t9)); // new table constructed with inited