Bug 1123151 (part 2) - Add PLDHashTable::IsInitialized(). r=froydnj.

This encapsulates most of the uses of PLDHashTable::ops.
This commit is contained in:
Nicholas Nethercote 2015-01-19 16:11:34 -08:00
parent fa52a2c4c9
commit 9a918a72c0
32 changed files with 153 additions and 140 deletions

View File

@ -215,14 +215,14 @@ NS_GetContentList(nsINode* aRootNode,
};
// Initialize the hashtable if needed.
if (!gContentListHashTable.ops) {
if (!gContentListHashTable.IsInitialized()) {
PL_DHashTableInit(&gContentListHashTable, &hash_table_ops,
sizeof(ContentListHashEntry));
}
ContentListHashEntry *entry = nullptr;
// First we look in our hashtable. Then we create a content list if needed
if (gContentListHashTable.ops) {
if (gContentListHashTable.IsInitialized()) {
// A PL_DHASH_ADD is equivalent to a PL_DHASH_LOOKUP for cases
// when the entry is already in the hashtable.
@ -325,14 +325,14 @@ GetFuncStringContentList(nsINode* aRootNode,
};
// Initialize the hashtable if needed.
if (!gFuncStringContentListHashTable.ops) {
if (!gFuncStringContentListHashTable.IsInitialized()) {
PL_DHashTableInit(&gFuncStringContentListHashTable, &hash_table_ops,
sizeof(FuncStringContentListHashEntry));
}
FuncStringContentListHashEntry *entry = nullptr;
// First we look in our hashtable. Then we create a content list if needed
if (gFuncStringContentListHashTable.ops) {
if (gFuncStringContentListHashTable.IsInitialized()) {
nsFuncStringCacheKey hashKey(aRootNode, aFunc, aString);
// A PL_DHASH_ADD is equivalent to a PL_DHASH_LOOKUP for cases
@ -977,7 +977,7 @@ nsContentList::RemoveFromHashtable()
sRecentlyUsedContentLists[recentlyUsedCacheIndex] = nullptr;
}
if (!gContentListHashTable.ops)
if (!gContentListHashTable.IsInitialized())
return;
PL_DHashTableRemove(&gContentListHashTable, &key);
@ -1015,7 +1015,7 @@ nsCacheableFuncStringContentList::~nsCacheableFuncStringContentList()
void
nsCacheableFuncStringContentList::RemoveFromFuncStringHashtable()
{
if (!gFuncStringContentListHashTable.ops) {
if (!gFuncStringContentListHashTable.IsInitialized()) {
return;
}

View File

@ -344,7 +344,7 @@ public:
{
// We don't measure the |EventListenerManager| objects pointed to by the
// entries because those references are non-owning.
int64_t amount = sEventListenerManagersHash.ops
int64_t amount = sEventListenerManagersHash.IsInitialized()
? PL_DHashTableSizeOfExcludingThis(
&sEventListenerManagersHash, nullptr, MallocSizeOf)
: 0;
@ -476,7 +476,7 @@ nsContentUtils::Init()
if (!InitializeEventTable())
return NS_ERROR_FAILURE;
if (!sEventListenerManagersHash.ops) {
if (!sEventListenerManagersHash.IsInitialized()) {
static const PLDHashTableOps hash_table_ops =
{
PL_DHashVoidPtrKeyStub,
@ -1761,7 +1761,7 @@ nsContentUtils::Shutdown()
delete sUserDefinedEvents;
sUserDefinedEvents = nullptr;
if (sEventListenerManagersHash.ops) {
if (sEventListenerManagersHash.IsInitialized()) {
NS_ASSERTION(sEventListenerManagersHash.EntryCount() == 0,
"Event listener manager hash not empty at shutdown!");
@ -3910,7 +3910,7 @@ ListenerEnumerator(PLDHashTable* aTable, PLDHashEntryHdr* aEntry,
void
nsContentUtils::UnmarkGrayJSListenersInCCGenerationDocuments(uint32_t aGeneration)
{
if (sEventListenerManagersHash.ops) {
if (sEventListenerManagersHash.IsInitialized()) {
PL_DHashTableEnumerate(&sEventListenerManagersHash, ListenerEnumerator,
&aGeneration);
}
@ -3921,7 +3921,7 @@ void
nsContentUtils::TraverseListenerManager(nsINode *aNode,
nsCycleCollectionTraversalCallback &cb)
{
if (!sEventListenerManagersHash.ops) {
if (!sEventListenerManagersHash.IsInitialized()) {
// We're already shut down, just return.
return;
}
@ -3938,7 +3938,7 @@ nsContentUtils::TraverseListenerManager(nsINode *aNode,
EventListenerManager*
nsContentUtils::GetListenerManagerForNode(nsINode *aNode)
{
if (!sEventListenerManagersHash.ops) {
if (!sEventListenerManagersHash.IsInitialized()) {
// We're already shut down, don't bother creating an event listener
// manager.
@ -3969,7 +3969,7 @@ nsContentUtils::GetExistingListenerManagerForNode(const nsINode *aNode)
return nullptr;
}
if (!sEventListenerManagersHash.ops) {
if (!sEventListenerManagersHash.IsInitialized()) {
// We're already shut down, don't bother creating an event listener
// manager.
@ -3990,7 +3990,7 @@ nsContentUtils::GetExistingListenerManagerForNode(const nsINode *aNode)
void
nsContentUtils::RemoveListenerManager(nsINode *aNode)
{
if (sEventListenerManagersHash.ops) {
if (sEventListenerManagersHash.IsInitialized()) {
EventListenerManagerMapEntry *entry =
static_cast<EventListenerManagerMapEntry *>
(PL_DHashTableLookup(&sEventListenerManagersHash, aNode));

View File

@ -2032,7 +2032,7 @@ NS_IMPL_CYCLE_COLLECTION_TRAVERSE_BEGIN_INTERNAL(nsDocument)
tmp->mAnimationController->Traverse(&cb);
}
if (tmp->mSubDocuments && tmp->mSubDocuments->ops) {
if (tmp->mSubDocuments && tmp->mSubDocuments->IsInitialized()) {
PL_DHashTableEnumerate(tmp->mSubDocuments, SubDocTraverser, &cb);
}

View File

@ -215,7 +215,7 @@ nsPropertyTable::SetPropertyInternal(nsPropertyOwner aObject,
} else {
propertyList = new PropertyList(aPropertyName, aPropDtorFunc,
aPropDtorData, aTransfer);
if (!propertyList || !propertyList->mObjectValueMap.ops) {
if (!propertyList || !propertyList->mObjectValueMap.IsInitialized()) {
delete propertyList;
return NS_ERROR_OUT_OF_MEMORY;
}

View File

@ -402,7 +402,7 @@ DestroyJSObjWrapperTable()
static bool
CreateNPObjWrapperTable()
{
MOZ_ASSERT(!sNPObjWrappers.ops);
MOZ_ASSERT(!sNPObjWrappers.IsInitialized());
if (!RegisterGCCallbacks()) {
return false;
@ -437,7 +437,7 @@ OnWrapperDestroyed()
DestroyJSObjWrapperTable();
}
if (sNPObjWrappers.ops) {
if (sNPObjWrappers.IsInitialized()) {
// No more wrappers, and our hash was initialized. Finish the
// hash to prevent leaking it.
DestroyNPObjWrapperTable();
@ -1747,7 +1747,7 @@ NPObjWrapper_Finalize(js::FreeOp *fop, JSObject *obj)
{
NPObject *npobj = (NPObject *)::JS_GetPrivate(obj);
if (npobj) {
if (sNPObjWrappers.ops) {
if (sNPObjWrappers.IsInitialized()) {
PL_DHashTableRemove(&sNPObjWrappers, npobj);
}
}
@ -1763,7 +1763,7 @@ NPObjWrapper_ObjectMoved(JSObject *obj, const JSObject *old)
// The wrapper JSObject has been moved, so we need to update the entry in the
// sNPObjWrappers hash table, if present.
if (!sNPObjWrappers.ops) {
if (!sNPObjWrappers.IsInitialized()) {
return;
}
@ -1822,7 +1822,7 @@ nsNPObjWrapper::OnDestroy(NPObject *npobj)
return;
}
if (!sNPObjWrappers.ops) {
if (!sNPObjWrappers.IsInitialized()) {
// No hash yet (or any more), no used wrappers available.
return;
@ -1872,7 +1872,7 @@ nsNPObjWrapper::GetNewOrUsed(NPP npp, JSContext *cx, NPObject *npobj)
return nullptr;
}
if (!sNPObjWrappers.ops) {
if (!sNPObjWrappers.IsInitialized()) {
// No hash yet (or any more), initialize it.
if (!CreateNPObjWrapperTable()) {
return nullptr;
@ -2028,7 +2028,7 @@ nsJSNPRuntime::OnPluginDestroy(NPP npp)
// Use the safe JSContext here as we're not always able to find the
// JSContext associated with the NPP any more.
AutoSafeJSContext cx;
if (sNPObjWrappers.ops) {
if (sNPObjWrappers.IsInitialized()) {
NppAndCx nppcx = { npp, cx };
PL_DHashTableEnumerate(&sNPObjWrappers,
NPObjWrapperPluginDestroyedCallback, &nppcx);

View File

@ -15,14 +15,14 @@ nsContentSupportMap::Init()
void
nsContentSupportMap::Finish()
{
if (mMap.ops)
if (mMap.IsInitialized())
PL_DHashTableFinish(&mMap);
}
nsresult
nsContentSupportMap::Remove(nsIContent* aElement)
{
if (!mMap.ops)
if (!mMap.IsInitialized())
return NS_ERROR_NOT_INITIALIZED;
nsIContent* child = aElement;

View File

@ -25,7 +25,7 @@ public:
~nsContentSupportMap() { Finish(); }
nsresult Put(nsIContent* aElement, nsTemplateMatch* aMatch) {
if (!mMap.ops)
if (!mMap.IsInitialized())
return NS_ERROR_NOT_INITIALIZED;
PLDHashEntryHdr* hdr = PL_DHashTableAdd(&mMap, aElement);
@ -39,7 +39,7 @@ public:
return NS_OK; }
bool Get(nsIContent* aElement, nsTemplateMatch** aMatch) {
if (!mMap.ops)
if (!mMap.IsInitialized())
return false;
PLDHashEntryHdr* hdr = PL_DHashTableLookup(&mMap, aElement);

View File

@ -640,7 +640,7 @@ public:
~FontNameCache()
{
if (!mMap.ops) {
if (!mMap.IsInitialized()) {
return;
}
if (!mWriteNeeded || !mCache) {
@ -656,7 +656,7 @@ public:
void Init()
{
if (!mMap.ops || !mCache) {
if (!mMap.IsInitialized() || !mCache) {
return;
}
uint32_t size;
@ -712,7 +712,7 @@ public:
GetInfoForFile(const nsCString& aFileName, nsCString& aFaceList,
uint32_t *aTimestamp, uint32_t *aFilesize)
{
if (!mMap.ops) {
if (!mMap.IsInitialized()) {
return;
}
PLDHashEntryHdr *hdr =
@ -736,7 +736,7 @@ public:
CacheFileInfo(const nsCString& aFileName, const nsCString& aFaceList,
uint32_t aTimestamp, uint32_t aFilesize)
{
if (!mMap.ops) {
if (!mMap.IsInitialized()) {
return;
}
FNCMapEntry* entry =

View File

@ -153,7 +153,7 @@ nsFrameManager::GetPlaceholderFrameFor(const nsIFrame* aFrame)
{
NS_PRECONDITION(aFrame, "null param unexpected");
if (mPlaceholderMap.ops) {
if (mPlaceholderMap.IsInitialized()) {
PlaceholderMapEntry *entry = static_cast<PlaceholderMapEntry*>
(PL_DHashTableLookup(const_cast<PLDHashTable*>(&mPlaceholderMap),
aFrame));
@ -171,7 +171,7 @@ nsFrameManager::RegisterPlaceholderFrame(nsPlaceholderFrame* aPlaceholderFrame)
NS_PRECONDITION(aPlaceholderFrame, "null param unexpected");
NS_PRECONDITION(nsGkAtoms::placeholderFrame == aPlaceholderFrame->GetType(),
"unexpected frame type");
if (!mPlaceholderMap.ops) {
if (!mPlaceholderMap.IsInitialized()) {
PL_DHashTableInit(&mPlaceholderMap, &PlaceholderMapOps,
sizeof(PlaceholderMapEntry));
}
@ -193,7 +193,7 @@ nsFrameManager::UnregisterPlaceholderFrame(nsPlaceholderFrame* aPlaceholderFrame
NS_PRECONDITION(nsGkAtoms::placeholderFrame == aPlaceholderFrame->GetType(),
"unexpected frame type");
if (mPlaceholderMap.ops) {
if (mPlaceholderMap.IsInitialized()) {
PL_DHashTableRemove(&mPlaceholderMap,
aPlaceholderFrame->GetOutOfFlowFrame());
}
@ -211,7 +211,7 @@ UnregisterPlaceholders(PLDHashTable* table, PLDHashEntryHdr* hdr,
void
nsFrameManager::ClearPlaceholderFrameMap()
{
if (mPlaceholderMap.ops) {
if (mPlaceholderMap.IsInitialized()) {
PL_DHashTableEnumerate(&mPlaceholderMap, UnregisterPlaceholders, nullptr);
PL_DHashTableFinish(&mPlaceholderMap);
}

View File

@ -555,16 +555,16 @@ RuleHash::~RuleHash()
delete [] mEnumList;
}
// delete arena for strings and small objects
if (mIdTable.ops) {
if (mIdTable.IsInitialized()) {
PL_DHashTableFinish(&mIdTable);
}
if (mClassTable.ops) {
if (mClassTable.IsInitialized()) {
PL_DHashTableFinish(&mClassTable);
}
if (mTagTable.ops) {
if (mTagTable.IsInitialized()) {
PL_DHashTableFinish(&mTagTable);
}
if (mNameSpaceTable.ops) {
if (mNameSpaceTable.IsInitialized()) {
PL_DHashTableFinish(&mNameSpaceTable);
}
}
@ -605,7 +605,7 @@ void RuleHash::AppendRule(const RuleSelectorPair& aRuleInfo)
selector = selector->mNext;
}
if (nullptr != selector->mIDList) {
if (!mIdTable.ops) {
if (!mIdTable.IsInitialized()) {
PL_DHashTableInit(&mIdTable,
mQuirksMode ? &RuleHash_IdTable_CIOps.ops
: &RuleHash_IdTable_CSOps.ops,
@ -615,7 +615,7 @@ void RuleHash::AppendRule(const RuleSelectorPair& aRuleInfo)
RULE_HASH_STAT_INCREMENT(mIdSelectors);
}
else if (nullptr != selector->mClassList) {
if (!mClassTable.ops) {
if (!mClassTable.IsInitialized()) {
PL_DHashTableInit(&mClassTable,
mQuirksMode ? &RuleHash_ClassTable_CIOps.ops
: &RuleHash_ClassTable_CSOps.ops,
@ -626,7 +626,7 @@ void RuleHash::AppendRule(const RuleSelectorPair& aRuleInfo)
}
else if (selector->mLowercaseTag) {
RuleValue ruleValue(aRuleInfo, mRuleCount++, mQuirksMode);
if (!mTagTable.ops) {
if (!mTagTable.IsInitialized()) {
PL_DHashTableInit(&mTagTable, &RuleHash_TagTable_Ops,
sizeof(RuleHashTagTableEntry));
}
@ -639,7 +639,7 @@ void RuleHash::AppendRule(const RuleSelectorPair& aRuleInfo)
}
}
else if (kNameSpaceID_Unknown != selector->mNameSpace) {
if (!mNameSpaceTable.ops) {
if (!mNameSpaceTable.IsInitialized()) {
PL_DHashTableInit(&mNameSpaceTable, &RuleHash_NameSpaceTable_Ops,
sizeof(RuleHashTableEntry));
}
@ -699,7 +699,7 @@ void RuleHash::EnumerateAllRules(Element* aElement, ElementDependentRuleProcesso
RULE_HASH_STAT_INCREMENT_LIST_COUNT(mUniversalRules, mElementUniversalCalls);
}
// universal rules within the namespace
if (kNameSpaceID_Unknown != nameSpace && mNameSpaceTable.ops) {
if (kNameSpaceID_Unknown != nameSpace && mNameSpaceTable.IsInitialized()) {
RuleHashTableEntry *entry = static_cast<RuleHashTableEntry*>
(PL_DHashTableLookup(&mNameSpaceTable, NS_INT32_TO_PTR(nameSpace)));
if (PL_DHASH_ENTRY_IS_BUSY(entry)) {
@ -707,7 +707,7 @@ void RuleHash::EnumerateAllRules(Element* aElement, ElementDependentRuleProcesso
RULE_HASH_STAT_INCREMENT_LIST_COUNT(entry->mRules, mElementNameSpaceCalls);
}
}
if (mTagTable.ops) {
if (mTagTable.IsInitialized()) {
RuleHashTableEntry *entry = static_cast<RuleHashTableEntry*>
(PL_DHashTableLookup(&mTagTable, tag));
if (PL_DHASH_ENTRY_IS_BUSY(entry)) {
@ -715,7 +715,7 @@ void RuleHash::EnumerateAllRules(Element* aElement, ElementDependentRuleProcesso
RULE_HASH_STAT_INCREMENT_LIST_COUNT(entry->mRules, mElementTagCalls);
}
}
if (id && mIdTable.ops) {
if (id && mIdTable.IsInitialized()) {
RuleHashTableEntry *entry = static_cast<RuleHashTableEntry*>
(PL_DHashTableLookup(&mIdTable, id));
if (PL_DHASH_ENTRY_IS_BUSY(entry)) {
@ -723,7 +723,7 @@ void RuleHash::EnumerateAllRules(Element* aElement, ElementDependentRuleProcesso
RULE_HASH_STAT_INCREMENT_LIST_COUNT(entry->mRules, mElementIdCalls);
}
}
if (mClassTable.ops) {
if (mClassTable.IsInitialized()) {
for (int32_t index = 0; index < classCount; ++index) {
RuleHashTableEntry *entry = static_cast<RuleHashTableEntry*>
(PL_DHashTableLookup(&mClassTable, classList->AtomAt(index)));
@ -786,25 +786,25 @@ RuleHash::SizeOfExcludingThis(MallocSizeOf aMallocSizeOf) const
{
size_t n = 0;
if (mIdTable.ops) {
if (mIdTable.IsInitialized()) {
n += PL_DHashTableSizeOfExcludingThis(&mIdTable,
SizeOfRuleHashTableEntry,
aMallocSizeOf);
}
if (mClassTable.ops) {
if (mClassTable.IsInitialized()) {
n += PL_DHashTableSizeOfExcludingThis(&mClassTable,
SizeOfRuleHashTableEntry,
aMallocSizeOf);
}
if (mTagTable.ops) {
if (mTagTable.IsInitialized()) {
n += PL_DHashTableSizeOfExcludingThis(&mTagTable,
SizeOfRuleHashTableEntry,
aMallocSizeOf);
}
if (mNameSpaceTable.ops) {
if (mNameSpaceTable.IsInitialized()) {
n += PL_DHashTableSizeOfExcludingThis(&mNameSpaceTable,
SizeOfRuleHashTableEntry,
aMallocSizeOf);
@ -3366,7 +3366,7 @@ struct CascadeEnumData {
~CascadeEnumData()
{
if (mRulesByWeight.ops)
if (mRulesByWeight.IsInitialized())
PL_DHashTableFinish(&mRulesByWeight);
PL_FinishArenaPool(&mArena);
}
@ -3580,7 +3580,7 @@ nsCSSRuleProcessor::RefreshRuleCascade(nsPresContext* aPresContext)
newCascade->mCounterStyleRules,
newCascade->mCacheKey,
mSheetType);
if (!data.mRulesByWeight.ops)
if (!data.mRulesByWeight.IsInitialized())
return; /* out of memory */
for (uint32_t i = 0; i < mSheets.Length(); ++i) {

View File

@ -242,10 +242,12 @@ nsHTMLStyleSheet::nsHTMLStyleSheet(nsIDocument* aDocument)
nsHTMLStyleSheet::~nsHTMLStyleSheet()
{
if (mLangRuleTable.ops)
if (mLangRuleTable.IsInitialized()) {
PL_DHashTableFinish(&mLangRuleTable);
if (mMappedAttrTable.ops)
}
if (mMappedAttrTable.IsInitialized()) {
PL_DHashTableFinish(&mMappedAttrTable);
}
}
NS_IMPL_ISUPPORTS(nsHTMLStyleSheet, nsIStyleRuleProcessor)
@ -423,10 +425,10 @@ nsHTMLStyleSheet::Reset()
mVisitedRule = nullptr;
mActiveRule = nullptr;
if (mLangRuleTable.ops) {
if (mLangRuleTable.IsInitialized()) {
PL_DHashTableFinish(&mLangRuleTable);
}
if (mMappedAttrTable.ops) {
if (mMappedAttrTable.IsInitialized()) {
PL_DHashTableFinish(&mMappedAttrTable);
}
}
@ -477,7 +479,7 @@ nsHTMLStyleSheet::SetVisitedLinkColor(nscolor aColor)
already_AddRefed<nsMappedAttributes>
nsHTMLStyleSheet::UniqueMappedAttributes(nsMappedAttributes* aMapped)
{
if (!mMappedAttrTable.ops) {
if (!mMappedAttrTable.IsInitialized()) {
PL_DHashTableInit(&mMappedAttrTable, &MappedAttrTable_Ops,
sizeof(MappedAttrTableEntry));
}
@ -498,7 +500,7 @@ nsHTMLStyleSheet::DropMappedAttributes(nsMappedAttributes* aMapped)
{
NS_ENSURE_TRUE_VOID(aMapped);
NS_ASSERTION(mMappedAttrTable.ops, "table uninitialized");
NS_ASSERTION(mMappedAttrTable.IsInitialized(), "table uninitialized");
#ifdef DEBUG
uint32_t entryCount = mMappedAttrTable.EntryCount() - 1;
#endif
@ -511,7 +513,7 @@ nsHTMLStyleSheet::DropMappedAttributes(nsMappedAttributes* aMapped)
nsIStyleRule*
nsHTMLStyleSheet::LangRuleFor(const nsString& aLanguage)
{
if (!mLangRuleTable.ops) {
if (!mLangRuleTable.IsInitialized()) {
PL_DHashTableInit(&mLangRuleTable, &LangRuleTable_Ops,
sizeof(LangRuleTableEntry));
}
@ -541,7 +543,7 @@ nsHTMLStyleSheet::DOMSizeOfIncludingThis(MallocSizeOf aMallocSizeOf) const
{
size_t n = aMallocSizeOf(this);
if (mMappedAttrTable.ops) {
if (mMappedAttrTable.IsInitialized()) {
n += PL_DHashTableSizeOfExcludingThis(&mMappedAttrTable,
SizeOfAttributesEntryExcludingThis,
aMallocSizeOf);

View File

@ -23,7 +23,7 @@ SpanningCellSorter::SpanningCellSorter()
SpanningCellSorter::~SpanningCellSorter()
{
if (mHashTable.ops) {
if (mHashTable.IsInitialized()) {
PL_DHashTableFinish(&mHashTable);
}
delete [] mSortedHashTable;
@ -70,7 +70,7 @@ SpanningCellSorter::AddCell(int32_t aColSpan, int32_t aRow, int32_t aCol)
i->next = mArray[index];
mArray[index] = i;
} else {
if (!mHashTable.ops) {
if (!mHashTable.IsInitialized()) {
PL_DHashTableInit(&mHashTable, &HashTableOps,
sizeof(HashTableEntry));
}
@ -145,7 +145,7 @@ SpanningCellSorter::GetNext(int32_t *aColSpan)
/* prepare to enumerate the hash */
mState = ENUMERATING_HASH;
mEnumerationIndex = 0;
if (mHashTable.ops) {
if (mHashTable.IsInitialized()) {
HashTableEntry **sh =
new HashTableEntry*[mHashTable.EntryCount()];
if (!sh) {
@ -160,7 +160,9 @@ SpanningCellSorter::GetNext(int32_t *aColSpan)
}
/* fall through */
case ENUMERATING_HASH:
if (mHashTable.ops && mEnumerationIndex < mHashTable.EntryCount()) {
if (mHashTable.IsInitialized() &&
mEnumerationIndex < mHashTable.EntryCount())
{
Item *result = mSortedHashTable[mEnumerationIndex]->mItems;
*aColSpan = mSortedHashTable[mEnumerationIndex]->mColSpan;
NS_ASSERTION(result, "holes in hash table");

View File

@ -235,7 +235,7 @@ Preferences::SizeOfIncludingThisAndOtherStuff(mozilla::MallocSizeOf aMallocSizeO
NS_ENSURE_TRUE(InitStaticMembers(), 0);
size_t n = aMallocSizeOf(sPreferences);
if (gHashTable.ops) {
if (gHashTable.IsInitialized()) {
// 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);
@ -955,7 +955,7 @@ Preferences::WritePrefFile(nsIFile* aFile)
uint32_t writeAmount;
nsresult rv;
if (!gHashTable.ops)
if (!gHashTable.IsInitialized())
return NS_ERROR_NOT_INITIALIZED;
// execute a "safe" save by saving through a tempfile

View File

@ -555,7 +555,7 @@ NS_IMETHODIMP nsPrefBranch::GetChildList(const char *aStartingAt, uint32_t *aCou
*aChildArray = nullptr;
*aCount = 0;
if (!gHashTable.ops)
if (!gHashTable.IsInitialized())
return NS_ERROR_NOT_INITIALIZED;
// this will contain a list of all the pref name strings

View File

@ -145,7 +145,7 @@ static nsresult pref_HashPref(const char *key, PrefValue value, PrefType type, u
nsresult PREF_Init()
{
if (!gHashTable.ops) {
if (!gHashTable.IsInitialized()) {
if (!PL_DHashTableInit(&gHashTable, &pref_HashTableOps,
sizeof(PrefHashEntry), fallible_t(),
PREF_HASHTABLE_INITIAL_LENGTH)) {
@ -181,7 +181,7 @@ void PREF_Cleanup()
/* Frees up all the objects except the callback list. */
void PREF_CleanupPrefs()
{
if (gHashTable.ops) {
if (gHashTable.IsInitialized()) {
PL_DHashTableFinish(&gHashTable);
PL_FinishArenaPool(&gPrefNameArena);
}
@ -464,7 +464,7 @@ pref_CompareStrings(const void *v1, const void *v2, void *unused)
bool PREF_HasUserPref(const char *pref_name)
{
if (!gHashTable.ops)
if (!gHashTable.IsInitialized())
return false;
PrefHashEntry *pref = pref_HashTableLookup(pref_name);
@ -478,7 +478,7 @@ bool PREF_HasUserPref(const char *pref_name)
nsresult
PREF_CopyCharPref(const char *pref_name, char ** return_buffer, bool get_default)
{
if (!gHashTable.ops)
if (!gHashTable.IsInitialized())
return NS_ERROR_NOT_INITIALIZED;
nsresult rv = NS_ERROR_UNEXPECTED;
@ -502,7 +502,7 @@ PREF_CopyCharPref(const char *pref_name, char ** return_buffer, bool get_default
nsresult PREF_GetIntPref(const char *pref_name,int32_t * return_int, bool get_default)
{
if (!gHashTable.ops)
if (!gHashTable.IsInitialized())
return NS_ERROR_NOT_INITIALIZED;
nsresult rv = NS_ERROR_UNEXPECTED;
@ -526,7 +526,7 @@ nsresult PREF_GetIntPref(const char *pref_name,int32_t * return_int, bool get_de
nsresult PREF_GetBoolPref(const char *pref_name, bool * return_value, bool get_default)
{
if (!gHashTable.ops)
if (!gHashTable.IsInitialized())
return NS_ERROR_NOT_INITIALIZED;
nsresult rv = NS_ERROR_UNEXPECTED;
@ -577,7 +577,7 @@ PREF_DeleteBranch(const char *branch_name)
int len = (int)strlen(branch_name);
if (!gHashTable.ops)
if (!gHashTable.IsInitialized())
return NS_ERROR_NOT_INITIALIZED;
/* The following check insures that if the branch name already has a "."
@ -600,7 +600,7 @@ PREF_DeleteBranch(const char *branch_name)
nsresult
PREF_ClearUserPref(const char *pref_name)
{
if (!gHashTable.ops)
if (!gHashTable.IsInitialized())
return NS_ERROR_NOT_INITIALIZED;
PrefHashEntry* pref = pref_HashTableLookup(pref_name);
@ -646,7 +646,7 @@ PREF_ClearAllUserPrefs()
MOZ_ASSERT(NS_IsMainThread());
#endif
if (!gHashTable.ops)
if (!gHashTable.IsInitialized())
return NS_ERROR_NOT_INITIALIZED;
PL_DHashTableEnumerate(&gHashTable, pref_ClearUserPref, nullptr);
@ -657,7 +657,7 @@ PREF_ClearAllUserPrefs()
nsresult PREF_LockPref(const char *key, bool lockit)
{
if (!gHashTable.ops)
if (!gHashTable.IsInitialized())
return NS_ERROR_NOT_INITIALIZED;
PrefHashEntry* pref = pref_HashTableLookup(key);
@ -743,7 +743,7 @@ nsresult pref_HashPref(const char *key, PrefValue value, PrefType type, uint32_t
MOZ_ASSERT(NS_IsMainThread());
#endif
if (!gHashTable.ops)
if (!gHashTable.IsInitialized())
return NS_ERROR_OUT_OF_MEMORY;
PrefHashEntry* pref = static_cast<PrefHashEntry*>(PL_DHashTableAdd(&gHashTable, key));
@ -834,7 +834,7 @@ pref_SizeOfPrivateData(MallocSizeOf aMallocSizeOf)
PrefType
PREF_GetPrefType(const char *pref_name)
{
if (gHashTable.ops)
if (gHashTable.IsInitialized())
{
PrefHashEntry* pref = pref_HashTableLookup(pref_name);
if (pref)
@ -856,7 +856,7 @@ bool
PREF_PrefIsLocked(const char *pref_name)
{
bool result = false;
if (gIsAnyPrefLocked && gHashTable.ops) {
if (gIsAnyPrefLocked && gHashTable.IsInitialized()) {
PrefHashEntry* pref = pref_HashTableLookup(pref_name);
if (pref && PREF_IS_LOCKED(pref))
result = true;

View File

@ -139,7 +139,7 @@ nsLoadGroup::~nsLoadGroup()
DebugOnly<nsresult> rv = Cancel(NS_BINDING_ABORTED);
NS_ASSERTION(NS_SUCCEEDED(rv), "Cancel failed");
if (mRequests.ops) {
if (mRequests.IsInitialized()) {
PL_DHashTableFinish(&mRequests);
}

View File

@ -96,7 +96,7 @@ static const PLDHashTableOps ops = {
nsresult
nsHttp::CreateAtomTable()
{
MOZ_ASSERT(!sAtomTable.ops, "atom table already initialized");
MOZ_ASSERT(!sAtomTable.IsInitialized(), "atom table already initialized");
if (!sLock) {
sLock = new Mutex("nsHttp.sLock");
@ -134,7 +134,7 @@ nsHttp::CreateAtomTable()
void
nsHttp::DestroyAtomTable()
{
if (sAtomTable.ops) {
if (sAtomTable.IsInitialized()) {
PL_DHashTableFinish(&sAtomTable);
}
@ -162,7 +162,7 @@ nsHttp::ResolveAtom(const char *str)
{
nsHttpAtom atom = { nullptr };
if (!str || !sAtomTable.ops)
if (!str || !sAtomTable.IsInitialized())
return atom;
MutexAutoLock lock(*sLock);

View File

@ -131,10 +131,10 @@ nsHTMLEntities::ReleaseTable(void)
if (--gTableRefCnt != 0)
return;
if (gEntityToUnicode.ops) {
if (gEntityToUnicode.IsInitialized()) {
PL_DHashTableFinish(&gEntityToUnicode);
}
if (gUnicodeToEntity.ops) {
if (gUnicodeToEntity.IsInitialized()) {
PL_DHashTableFinish(&gUnicodeToEntity);
}
}
@ -142,8 +142,9 @@ nsHTMLEntities::ReleaseTable(void)
int32_t
nsHTMLEntities::EntityToUnicode(const nsCString& aEntity)
{
NS_ASSERTION(gEntityToUnicode.ops, "no lookup table, needs addref");
if (!gEntityToUnicode.ops)
NS_ASSERTION(gEntityToUnicode.IsInitialized(),
"no lookup table, needs addref");
if (!gEntityToUnicode.IsInitialized())
return -1;
//this little piece of code exists because entities may or may not have the terminating ';'.
@ -180,7 +181,8 @@ nsHTMLEntities::EntityToUnicode(const nsAString& aEntity) {
const char*
nsHTMLEntities::UnicodeToEntity(int32_t aUnicode)
{
NS_ASSERTION(gUnicodeToEntity.ops, "no lookup table, needs addref");
NS_ASSERTION(gUnicodeToEntity.IsInitialized(),
"no lookup table, needs addref");
EntityNodeEntry* entry =
static_cast<EntityNodeEntry*>
(PL_DHashTableLookup(&gUnicodeToEntity, NS_INT32_TO_PTR(aUnicode)));

View File

@ -807,7 +807,7 @@ InMemoryDataSource::~InMemoryDataSource()
fprintf(stdout, "%d - RDF: InMemoryDataSource\n", gInstanceCount);
#endif
if (mForwardArcs.ops) {
if (mForwardArcs.IsInitialized()) {
// This'll release all of the Assertion objects that are
// associated with this data source. We only need to do this
// for the forward arcs, because the reverse arcs table
@ -815,7 +815,7 @@ InMemoryDataSource::~InMemoryDataSource()
PL_DHashTableEnumerate(&mForwardArcs, DeleteForwardArcsEntry, nullptr);
PL_DHashTableFinish(&mForwardArcs);
}
if (mReverseArcs.ops)
if (mReverseArcs.IsInitialized())
PL_DHashTableFinish(&mReverseArcs);
PR_LOG(gLog, PR_LOG_NOTICE,

View File

@ -770,15 +770,15 @@ RDFServiceImpl::~RDFServiceImpl()
PL_HashTableDestroy(mNamedDataSources);
mNamedDataSources = nullptr;
}
if (mResources.ops)
if (mResources.IsInitialized())
PL_DHashTableFinish(&mResources);
if (mLiterals.ops)
if (mLiterals.IsInitialized())
PL_DHashTableFinish(&mLiterals);
if (mInts.ops)
if (mInts.IsInitialized())
PL_DHashTableFinish(&mInts);
if (mDates.ops)
if (mDates.IsInitialized())
PL_DHashTableFinish(&mDates);
if (mBlobs.ops)
if (mBlobs.IsInitialized())
PL_DHashTableFinish(&mBlobs);
gRDFService = nullptr;
}

View File

@ -133,7 +133,7 @@ nsSecureBrowserUIImpl::nsSecureBrowserUIImpl()
nsSecureBrowserUIImpl::~nsSecureBrowserUIImpl()
{
if (mTransferringRequests.ops) {
if (mTransferringRequests.IsInitialized()) {
PL_DHashTableFinish(&mTransferringRequests);
}
}
@ -467,7 +467,7 @@ void nsSecureBrowserUIImpl::ResetStateTracking()
ReentrantMonitorAutoEnter lock(mReentrantMonitor);
mDocumentRequestsInProgress = 0;
if (mTransferringRequests.ops) {
if (mTransferringRequests.IsInitialized()) {
PL_DHashTableFinish(&mTransferringRequests);
}
PL_DHashTableInit(&mTransferringRequests, &gMapOps, sizeof(RequestHashEntry));

View File

@ -173,7 +173,7 @@ nsCertTree::nsCertTree() : mTreeArray(nullptr)
void nsCertTree::ClearCompareHash()
{
if (mCompareCache.ops) {
if (mCompareCache.IsInitialized()) {
PL_DHashTableFinish(&mCompareCache);
}
}

View File

@ -53,10 +53,10 @@ nsNSSShutDownList::nsNSSShutDownList()
nsNSSShutDownList::~nsNSSShutDownList()
{
if (mObjects.ops) {
if (mObjects.IsInitialized()) {
PL_DHashTableFinish(&mObjects);
}
if (mPK11LogoutCancelObjects.ops) {
if (mPK11LogoutCancelObjects.IsInitialized()) {
PL_DHashTableFinish(&mPK11LogoutCancelObjects);
}
PR_ASSERT(this == singleton);

View File

@ -139,7 +139,7 @@ nsDocLoader::SetDocLoaderParent(nsDocLoader *aParent)
nsresult
nsDocLoader::Init()
{
if (!mRequestInfoHash.ops) {
if (!mRequestInfoHash.IsInitialized()) {
return NS_ERROR_OUT_OF_MEMORY;
}
@ -172,7 +172,7 @@ nsDocLoader::~nsDocLoader()
PR_LOG(gDocLoaderLog, PR_LOG_DEBUG,
("DocLoader:%p: deleted.\n", this));
if (mRequestInfoHash.ops) {
if (mRequestInfoHash.IsInitialized()) {
PL_DHashTableFinish(&mRequestInfoHash);
}
}
@ -1380,7 +1380,7 @@ RemoveInfoCallback(PLDHashTable *table, PLDHashEntryHdr *hdr, uint32_t number,
void nsDocLoader::ClearRequestInfoHash(void)
{
if (!mRequestInfoHash.ops || !mRequestInfoHash.EntryCount()) {
if (!mRequestInfoHash.IsInitialized() || !mRequestInfoHash.EntryCount()) {
// No hash, or the hash is empty, nothing to do here then...
return;

View File

@ -836,7 +836,7 @@ public:
~CCGraph()
{
if (mPtrToNodeMap.ops) {
if (mPtrToNodeMap.IsInitialized()) {
PL_DHashTableFinish(&mPtrToNodeMap);
}
}
@ -862,7 +862,7 @@ public:
{
return mNodes.IsEmpty() && mEdges.IsEmpty() &&
mWeakMaps.IsEmpty() && mRootCount == 0 &&
!mPtrToNodeMap.ops;
!mPtrToNodeMap.IsInitialized();
}
#endif

View File

@ -40,8 +40,6 @@ using namespace mozilla;
* XXX This should be manipulated in a threadsafe way or we should make
* sure it's only manipulated from the main thread. Probably the latter
* is better, since the former would hurt performance.
*
* If |gAtomTable.ops| is 0, then the table is uninitialized.
*/
static PLDHashTable gAtomTable;
@ -342,7 +340,7 @@ NS_PurgeAtomTable()
{
delete gStaticAtomTable;
if (gAtomTable.ops) {
if (gAtomTable.IsInitialized()) {
#ifdef DEBUG
const char* dumpAtomLeaks = PR_GetEnv("MOZ_DUMP_ATOM_LEAKS");
if (dumpAtomLeaks && *dumpAtomLeaks) {
@ -402,14 +400,14 @@ AtomImpl::AtomImpl(nsStringBuffer* aStringBuffer, uint32_t aLength,
AtomImpl::~AtomImpl()
{
NS_PRECONDITION(gAtomTable.ops, "uninitialized atom hashtable");
NS_PRECONDITION(gAtomTable.IsInitialized(), "uninitialized atom hashtable");
// Permanent atoms are removed from the hashtable at shutdown, and we
// don't want to remove them twice. See comment above in
// |AtomTableClearEntry|.
if (!IsPermanentInDestructor()) {
AtomTableKey key(mString, mLength, mHash);
PL_DHashTableRemove(&gAtomTable, &key);
if (gAtomTable.ops && gAtomTable.EntryCount() == 0) {
if (gAtomTable.IsInitialized() && gAtomTable.EntryCount() == 0) {
PL_DHashTableFinish(&gAtomTable);
NS_ASSERTION(gAtomTable.EntryCount() == 0,
"PL_DHashTableFinish changed the entry count");
@ -528,7 +526,7 @@ void
NS_SizeOfAtomTablesIncludingThis(MallocSizeOf aMallocSizeOf,
size_t* aMain, size_t* aStatic)
{
*aMain = gAtomTable.ops
*aMain = gAtomTable.IsInitialized()
? PL_DHashTableSizeOfExcludingThis(&gAtomTable,
SizeOfAtomTableEntryExcludingThis,
aMallocSizeOf)
@ -546,7 +544,7 @@ NS_SizeOfAtomTablesIncludingThis(MallocSizeOf aMallocSizeOf,
static inline void
EnsureTableExists()
{
if (!gAtomTable.ops) {
if (!gAtomTable.IsInitialized()) {
PL_DHashTableInit(&gAtomTable, &AtomTableOps,
sizeof(AtomTableEntry), ATOM_HASHTABLE_INITIAL_LENGTH);
}

View File

@ -469,7 +469,7 @@ nsPersistentProperties::nsPersistentProperties()
nsPersistentProperties::~nsPersistentProperties()
{
PL_FinishArenaPool(&mArena);
if (mTable.ops) {
if (mTable.IsInitialized()) {
PL_DHashTableFinish(&mTable);
}
}

View File

@ -117,7 +117,7 @@ nsStaticCaseInsensitiveNameTable::~nsStaticCaseInsensitiveNameTable()
}
nsMemory::Free((void*)mNameArray);
}
if (mNameTable.ops) {
if (mNameTable.IsInitialized()) {
PL_DHashTableFinish(&mNameTable);
}
MOZ_COUNT_DTOR(nsStaticCaseInsensitiveNameTable);
@ -128,7 +128,7 @@ nsStaticCaseInsensitiveNameTable::Init(const char* const aNames[],
int32_t aLength)
{
NS_ASSERTION(!mNameArray, "double Init");
NS_ASSERTION(!mNameTable.ops, "double Init");
NS_ASSERTION(!mNameTable.IsInitialized(), "double Init");
NS_ASSERTION(aNames, "null name table");
NS_ASSERTION(aLength, "0 length");
@ -185,7 +185,7 @@ int32_t
nsStaticCaseInsensitiveNameTable::Lookup(const nsACString& aName)
{
NS_ASSERTION(mNameArray, "not inited");
NS_ASSERTION(mNameTable.ops, "not inited");
NS_ASSERTION(mNameTable.IsInitialized(), "not inited");
const nsAFlatCString& str = PromiseFlatCString(aName);
@ -203,7 +203,7 @@ int32_t
nsStaticCaseInsensitiveNameTable::Lookup(const nsAString& aName)
{
NS_ASSERTION(mNameArray, "not inited");
NS_ASSERTION(mNameTable.ops, "not inited");
NS_ASSERTION(mNameTable.IsInitialized(), "not inited");
const nsAFlatString& str = PromiseFlatString(aName);
@ -221,7 +221,7 @@ const nsAFlatCString&
nsStaticCaseInsensitiveNameTable::GetStringValue(int32_t aIndex)
{
NS_ASSERTION(mNameArray, "not inited");
NS_ASSERTION(mNameTable.ops, "not inited");
NS_ASSERTION(mNameTable.IsInitialized(), "not inited");
if ((NOT_FOUND < aIndex) && ((uint32_t)aIndex < mNameTable.EntryCount())) {
return mNameArray[aIndex];

View File

@ -167,7 +167,7 @@ public:
*/
uint32_t EnumerateRead(EnumReadFunction aEnumFunc, void* aUserArg) const
{
NS_ASSERTION(this->mTable.ops,
NS_ASSERTION(this->mTable.IsInitialized(),
"nsBaseHashtable was not initialized properly.");
s_EnumReadArgs enumData = { aEnumFunc, aUserArg };
@ -199,7 +199,7 @@ public:
*/
uint32_t Enumerate(EnumFunction aEnumFunc, void* aUserArg)
{
NS_ASSERTION(this->mTable.ops,
NS_ASSERTION(this->mTable.IsInitialized(),
"nsBaseHashtable was not initialized properly.");
s_EnumArgs enumData = { aEnumFunc, aUserArg };

View File

@ -126,7 +126,8 @@ public:
*/
EntryType* GetEntry(KeyType aKey) const
{
NS_ASSERTION(mTable.ops, "nsTHashtable was not initialized properly.");
NS_ASSERTION(mTable.IsInitialized(),
"nsTHashtable was not initialized properly.");
EntryType* entry = reinterpret_cast<EntryType*>(
PL_DHashTableLookup(const_cast<PLDHashTable*>(&mTable),
@ -157,7 +158,8 @@ public:
}
EntryType* PutEntry(KeyType aKey, const fallible_t&) NS_WARN_UNUSED_RESULT {
NS_ASSERTION(mTable.ops, "nsTHashtable was not initialized properly.");
NS_ASSERTION(mTable.IsInitialized(),
"nsTHashtable was not initialized properly.");
return static_cast<EntryType*>(PL_DHashTableAdd(
&mTable, EntryType::KeyToPointer(aKey)));
@ -169,7 +171,8 @@ public:
*/
void RemoveEntry(KeyType aKey)
{
NS_ASSERTION(mTable.ops, "nsTHashtable was not initialized properly.");
NS_ASSERTION(mTable.IsInitialized(),
"nsTHashtable was not initialized properly.");
PL_DHashTableRemove(&mTable,
EntryType::KeyToPointer(aKey));
@ -209,7 +212,8 @@ public:
*/
uint32_t EnumerateEntries(Enumerator aEnumFunc, void* aUserArg)
{
NS_ASSERTION(mTable.ops, "nsTHashtable was not initialized properly.");
NS_ASSERTION(mTable.IsInitialized(),
"nsTHashtable was not initialized properly.");
s_EnumArgs args = { aEnumFunc, aUserArg };
return PL_DHashTableEnumerate(&mTable, s_EnumStub, &args);
@ -220,7 +224,8 @@ public:
*/
void Clear()
{
NS_ASSERTION(mTable.ops, "nsTHashtable was not initialized properly.");
NS_ASSERTION(mTable.IsInitialized(),
"nsTHashtable was not initialized properly.");
PL_DHashTableEnumerate(&mTable, PL_DHashStubEnumRemove, nullptr);
}
@ -309,7 +314,8 @@ public:
*/
void MarkImmutable()
{
NS_ASSERTION(mTable.ops, "nsTHashtable was not initialized properly.");
NS_ASSERTION(mTable.IsInitialized(),
"nsTHashtable was not initialized properly.");
PL_DHashMarkTableImmutable(&mTable);
}
@ -408,7 +414,7 @@ nsTHashtable<EntryType>::nsTHashtable(nsTHashtable<EntryType>&& aOther)
template<class EntryType>
nsTHashtable<EntryType>::~nsTHashtable()
{
if (mTable.ops) {
if (mTable.IsInitialized()) {
PL_DHashTableFinish(&mTable);
}
}

View File

@ -222,8 +222,9 @@ private:
#endif
public:
// All the other fields are initialized in Init(), but we zero |ops| here
// because it's used to determine if Init() has been called.
// The most important thing here is that we zero |ops| because it's used to
// determine if Init() has been called. (The use of MOZ_CONSTEXPR means all
// the other members must be initialized too.)
MOZ_CONSTEXPR PLDHashTable()
: ops(nullptr)
, mHashShift(0)
@ -238,6 +239,8 @@ public:
#endif
{}
bool IsInitialized() const { return !!ops; }
/*
* Size in entries (gross, not net of free and removed sentinels) for table.
* We store mHashShift rather than sizeLog2 to optimize the collision-free

View File

@ -19,7 +19,7 @@ static bool test_pldhash_Init_capacity_ok()
PLDHashTable t;
// Check that the constructor nulls |ops|.
if (t.ops) {
if (t.IsInitialized()) {
return false;
}
@ -32,13 +32,13 @@ static bool test_pldhash_Init_capacity_ok()
}
// Check that Init() sets |ops|.
if (!t.ops) {
if (!t.IsInitialized()) {
return false;
}
// Check that Finish() nulls |ops|.
PL_DHashTableFinish(&t);
if (t.ops) {
if (t.IsInitialized()) {
return false;
}
@ -50,7 +50,7 @@ static bool test_pldhash_Init_capacity_too_large()
PLDHashTable t;
// Check that the constructor nulls |ops|.
if (t.ops) {
if (t.IsInitialized()) {
return false;
}
@ -64,7 +64,7 @@ static bool test_pldhash_Init_capacity_too_large()
// Don't call PL_DHashTableFinish() here; it's not safe after Init() failure.
// Check that |ops| is still null.
if (t.ops) {
if (t.IsInitialized()) {
return false;
}
@ -76,7 +76,7 @@ static bool test_pldhash_Init_overflow()
PLDHashTable t;
// Check that the constructor nulls |ops|.
if (t.ops) {
if (t.IsInitialized()) {
return false;
}
@ -99,7 +99,7 @@ static bool test_pldhash_Init_overflow()
// Don't call PL_DHashTableFinish() here; it's not safe after Init() failure.
// Check that |ops| is still null.
if (t.ops) {
if (t.IsInitialized()) {
return false;
}
@ -130,8 +130,8 @@ static bool test_pldhash_grow_to_max_capacity()
// This is infallible.
PLDHashTable* t = PL_NewDHashTable(&ops, sizeof(PLDHashEntryStub), 128);
// Check that New() sets |ops|.
if (!t->ops) {
// Check that New() sets |t->ops|.
if (!t->IsInitialized()) {
return false;
}