Skip to content

Commit

Permalink
Bug 1057912 - Privatize most of PLDHashTable's fields. r=roc.
Browse files Browse the repository at this point in the history
--HG--
extra : rebase_source : 0f55e70b63d9c191fbd9418cb1177ff534deeed9
  • Loading branch information
nnethercote committed Aug 25, 2014
1 parent 7d82bae commit df1c26a
Show file tree
Hide file tree
Showing 26 changed files with 439 additions and 330 deletions.
4 changes: 2 additions & 2 deletions content/base/src/nsContentList.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -993,7 +993,7 @@ nsContentList::RemoveFromHashtable()
&key,
PL_DHASH_REMOVE);

if (gContentListHashTable.entryCount == 0) {
if (gContentListHashTable.EntryCount() == 0) {
PL_DHashTableFinish(&gContentListHashTable);
gContentListHashTable.ops = nullptr;
}
Expand Down Expand Up @@ -1036,7 +1036,7 @@ nsCacheableFuncStringContentList::RemoveFromFuncStringHashtable()
&key,
PL_DHASH_REMOVE);

if (gFuncStringContentListHashTable.entryCount == 0) {
if (gFuncStringContentListHashTable.EntryCount() == 0) {
PL_DHashTableFinish(&gFuncStringContentListHashTable);
gFuncStringContentListHashTable.ops = nullptr;
}
Expand Down
4 changes: 2 additions & 2 deletions content/base/src/nsContentUtils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1781,7 +1781,7 @@ nsContentUtils::Shutdown()
sUserDefinedEvents = nullptr;

if (sEventListenerManagersHash.ops) {
NS_ASSERTION(sEventListenerManagersHash.entryCount == 0,
NS_ASSERTION(sEventListenerManagersHash.EntryCount() == 0,
"Event listener manager hash not empty at shutdown!");

// See comment above.
Expand All @@ -1793,7 +1793,7 @@ nsContentUtils::Shutdown()
// it could leave dangling references in DOMClassInfo's preserved
// wrapper table.

if (sEventListenerManagersHash.entryCount == 0) {
if (sEventListenerManagersHash.EntryCount() == 0) {
PL_DHashTableFinish(&sEventListenerManagersHash);
sEventListenerManagersHash.ops = nullptr;
}
Expand Down
6 changes: 3 additions & 3 deletions dom/plugins/base/nsJSNPRuntime.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -274,7 +274,7 @@ OnWrapperDestroyed()
}

if (sNPObjWrappers.ops) {
MOZ_ASSERT(sNPObjWrappers.entryCount == 0);
MOZ_ASSERT(sNPObjWrappers.EntryCount() == 0);

// No more wrappers, and our hash was initialized. Finish the
// hash to prevent leaking it.
Expand Down Expand Up @@ -1763,14 +1763,14 @@ nsNPObjWrapper::GetNewOrUsed(NPP npp, JSContext *cx, NPObject *npobj)
entry->mNPObj = npobj;
entry->mNpp = npp;

uint32_t generation = sNPObjWrappers.generation;
uint32_t generation = sNPObjWrappers.Generation();

// No existing JSObject, create one.

JS::Rooted<JSObject*> obj(cx, ::JS_NewObject(cx, &sNPObjectJSWrapperClass, JS::NullPtr(),
JS::NullPtr()));

if (generation != sNPObjWrappers.generation) {
if (generation != sNPObjWrappers.Generation()) {
// Reload entry if the JS_NewObject call caused a GC and reallocated
// the table (see bug 445229). This is guaranteed to succeed.

Expand Down
2 changes: 1 addition & 1 deletion js/xpconnect/src/XPCMaps.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -485,7 +485,7 @@ void
IID2ThisTranslatorMap::Entry::Clear(PLDHashTable *table, PLDHashEntryHdr *entry)
{
static_cast<Entry*>(entry)->value = nullptr;
memset(entry, 0, table->entrySize);
memset(entry, 0, table->EntrySize());
}

const struct PLDHashTableOps IID2ThisTranslatorMap::Entry::sOps =
Expand Down
18 changes: 9 additions & 9 deletions js/xpconnect/src/XPCMaps.h
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,7 @@ class Native2WrappedNativeMap
PL_DHashTableOperate(mTable, wrapper->GetIdentityObject(), PL_DHASH_REMOVE);
}

inline uint32_t Count() {return mTable->entryCount;}
inline uint32_t Count() { return mTable->EntryCount(); }
inline uint32_t Enumerate(PLDHashEnumerator f, void *arg)
{return PL_DHashTableEnumerate(mTable, f, arg);}

Expand Down Expand Up @@ -209,7 +209,7 @@ class IID2WrappedJSClassMap
PL_DHashTableOperate(mTable, &clazz->GetIID(), PL_DHASH_REMOVE);
}

inline uint32_t Count() {return mTable->entryCount;}
inline uint32_t Count() { return mTable->EntryCount(); }
inline uint32_t Enumerate(PLDHashEnumerator f, void *arg)
{return PL_DHashTableEnumerate(mTable, f, arg);}

Expand Down Expand Up @@ -266,7 +266,7 @@ class IID2NativeInterfaceMap
PL_DHashTableOperate(mTable, iface->GetIID(), PL_DHASH_REMOVE);
}

inline uint32_t Count() {return mTable->entryCount;}
inline uint32_t Count() { return mTable->EntryCount(); }
inline uint32_t Enumerate(PLDHashEnumerator f, void *arg)
{return PL_DHashTableEnumerate(mTable, f, arg);}

Expand Down Expand Up @@ -325,7 +325,7 @@ class ClassInfo2NativeSetMap
PL_DHashTableOperate(mTable, info, PL_DHASH_REMOVE);
}

inline uint32_t Count() {return mTable->entryCount;}
inline uint32_t Count() { return mTable->EntryCount(); }
inline uint32_t Enumerate(PLDHashEnumerator f, void *arg)
{return PL_DHashTableEnumerate(mTable, f, arg);}

Expand Down Expand Up @@ -385,7 +385,7 @@ class ClassInfo2WrappedNativeProtoMap
PL_DHashTableOperate(mTable, info, PL_DHASH_REMOVE);
}

inline uint32_t Count() {return mTable->entryCount;}
inline uint32_t Count() { return mTable->EntryCount(); }
inline uint32_t Enumerate(PLDHashEnumerator f, void *arg)
{return PL_DHashTableEnumerate(mTable, f, arg);}

Expand Down Expand Up @@ -458,7 +458,7 @@ class NativeSetMap
PL_DHashTableOperate(mTable, &key, PL_DHASH_REMOVE);
}

inline uint32_t Count() {return mTable->entryCount;}
inline uint32_t Count() { return mTable->EntryCount(); }
inline uint32_t Enumerate(PLDHashEnumerator f, void *arg)
{return PL_DHashTableEnumerate(mTable, f, arg);}

Expand Down Expand Up @@ -525,7 +525,7 @@ class IID2ThisTranslatorMap
PL_DHashTableOperate(mTable, &iid, PL_DHASH_REMOVE);
}

inline uint32_t Count() {return mTable->entryCount;}
inline uint32_t Count() { return mTable->EntryCount(); }
inline uint32_t Enumerate(PLDHashEnumerator f, void *arg)
{return PL_DHashTableEnumerate(mTable, f, arg);}

Expand Down Expand Up @@ -562,7 +562,7 @@ class XPCNativeScriptableSharedMap
bool GetNewOrUsed(uint32_t flags, char* name, uint32_t interfacesBitmap,
XPCNativeScriptableInfo* si);

inline uint32_t Count() {return mTable->entryCount;}
inline uint32_t Count() { return mTable->EntryCount(); }
inline uint32_t Enumerate(PLDHashEnumerator f, void *arg)
{return PL_DHashTableEnumerate(mTable, f, arg);}

Expand Down Expand Up @@ -600,7 +600,7 @@ class XPCWrappedNativeProtoMap
PL_DHashTableOperate(mTable, proto, PL_DHASH_REMOVE);
}

inline uint32_t Count() {return mTable->entryCount;}
inline uint32_t Count() { return mTable->EntryCount(); }
inline uint32_t Enumerate(PLDHashEnumerator f, void *arg)
{return PL_DHashTableEnumerate(mTable, f, arg);}

Expand Down
6 changes: 3 additions & 3 deletions layout/style/nsCSSRuleProcessor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2550,7 +2550,7 @@ nsCSSRuleProcessor::RulesMatching(AnonBoxRuleProcessorData* aData)
{
RuleCascadeData* cascade = GetRuleCascade(aData->mPresContext);

if (cascade && cascade->mAnonBoxRules.entryCount) {
if (cascade && cascade->mAnonBoxRules.EntryCount()) {
RuleHashTagTableEntry* entry = static_cast<RuleHashTagTableEntry*>
(PL_DHashTableOperate(&cascade->mAnonBoxRules, aData->mPseudoTag,
PL_DHASH_LOOKUP));
Expand All @@ -2571,7 +2571,7 @@ nsCSSRuleProcessor::RulesMatching(XULTreeRuleProcessorData* aData)
{
RuleCascadeData* cascade = GetRuleCascade(aData->mPresContext);

if (cascade && cascade->mXULTreeRules.entryCount) {
if (cascade && cascade->mXULTreeRules.EntryCount()) {
RuleHashTagTableEntry* entry = static_cast<RuleHashTagTableEntry*>
(PL_DHashTableOperate(&cascade->mXULTreeRules, aData->mPseudoTag,
PL_DHASH_LOOKUP));
Expand Down Expand Up @@ -3509,7 +3509,7 @@ nsCSSRuleProcessor::RefreshRuleCascade(nsPresContext* aPresContext)
}

// Sort the hash table of per-weight linked lists by weight.
uint32_t weightCount = data.mRulesByWeight.entryCount;
uint32_t weightCount = data.mRulesByWeight.EntryCount();
nsAutoArrayPtr<PerWeightData> weightArray(new PerWeightData[weightCount]);
FillWeightArrayData fwData(weightArray);
PL_DHashTableEnumerate(&data.mRulesByWeight, FillWeightArray, &fwData);
Expand Down
4 changes: 2 additions & 2 deletions layout/style/nsHTMLStyleSheet.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -500,12 +500,12 @@ nsHTMLStyleSheet::DropMappedAttributes(nsMappedAttributes* aMapped)

NS_ASSERTION(mMappedAttrTable.ops, "table uninitialized");
#ifdef DEBUG
uint32_t entryCount = mMappedAttrTable.entryCount - 1;
uint32_t entryCount = mMappedAttrTable.EntryCount() - 1;
#endif

PL_DHashTableOperate(&mMappedAttrTable, aMapped, PL_DHASH_REMOVE);

NS_ASSERTION(entryCount == mMappedAttrTable.entryCount, "not removed");
NS_ASSERTION(entryCount == mMappedAttrTable.EntryCount(), "not removed");
}

nsIStyleRule*
Expand Down
4 changes: 2 additions & 2 deletions layout/style/nsRuleNode.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9005,9 +9005,9 @@ nsRuleNode::SweepChildren(nsTArray<nsRuleNode*>& aSweepQueue)
nsRuleNode* survivorsWithChildren = nullptr;
if (ChildrenAreHashed()) {
PLDHashTable* children = ChildrenHash();
uint32_t oldChildCount = children->entryCount;
uint32_t oldChildCount = children->EntryCount();
PL_DHashTableEnumerate(children, SweepHashEntry, &survivorsWithChildren);
childrenDestroyed = oldChildCount - children->entryCount;
childrenDestroyed = oldChildCount - children->EntryCount();
if (childrenDestroyed == oldChildCount) {
PL_DHashTableDestroy(children);
mChildren.asVoid = nullptr;
Expand Down
6 changes: 3 additions & 3 deletions layout/tables/SpanningCellSorter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -153,20 +153,20 @@ SpanningCellSorter::GetNext(int32_t *aColSpan)
mEnumerationIndex = 0;
if (mHashTable.ops) {
HashTableEntry **sh =
new HashTableEntry*[mHashTable.entryCount];
new HashTableEntry*[mHashTable.EntryCount()];
if (!sh) {
// give up
mState = DONE;
return nullptr;
}
PL_DHashTableEnumerate(&mHashTable, FillSortedArray, sh);
NS_QuickSort(sh, mHashTable.entryCount, sizeof(sh[0]),
NS_QuickSort(sh, mHashTable.EntryCount(), sizeof(sh[0]),
SortArray, nullptr);
mSortedHashTable = sh;
}
/* fall through */
case ENUMERATING_HASH:
if (mHashTable.ops && mEnumerationIndex < mHashTable.entryCount) {
if (mHashTable.ops && mEnumerationIndex < mHashTable.EntryCount()) {
Item *result = mSortedHashTable[mEnumerationIndex]->mItems;
*aColSpan = mSortedHashTable[mEnumerationIndex]->mColSpan;
NS_ASSERTION(result, "holes in hash table");
Expand Down
10 changes: 5 additions & 5 deletions modules/libpref/Preferences.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -745,7 +745,7 @@ Preferences::GetPreference(PrefSetting* aPref)
void
Preferences::GetPreferences(InfallibleTArray<PrefSetting>* aPrefs)
{
aPrefs->SetCapacity(PL_DHASH_TABLE_CAPACITY(&gHashTable));
aPrefs->SetCapacity(gHashTable.Capacity());
PL_DHashTableEnumerate(&gHashTable, pref_GetPrefs, aPrefs);
}

Expand Down Expand Up @@ -971,8 +971,8 @@ Preferences::WritePrefFile(nsIFile* aFile)
if (NS_FAILED(rv))
return rv;

nsAutoArrayPtr<char*> valueArray(new char*[gHashTable.entryCount]);
memset(valueArray, 0, gHashTable.entryCount * sizeof(char*));
nsAutoArrayPtr<char*> valueArray(new char*[gHashTable.EntryCount()]);
memset(valueArray, 0, gHashTable.EntryCount() * sizeof(char*));
pref_saveArgs saveArgs;
saveArgs.prefArray = valueArray;
saveArgs.saveTypes = SAVE_ALL;
Expand All @@ -981,13 +981,13 @@ Preferences::WritePrefFile(nsIFile* aFile)
PL_DHashTableEnumerate(&gHashTable, pref_savePref, &saveArgs);

/* Sort the preferences to make a readable file on disk */
NS_QuickSort(valueArray, gHashTable.entryCount, sizeof(char *), pref_CompareStrings, nullptr);
NS_QuickSort(valueArray, gHashTable.EntryCount(), sizeof(char *), pref_CompareStrings, nullptr);

// write out the file header
outStream->Write(outHeader, sizeof(outHeader) - 1, &writeAmount);

char** walker = valueArray;
for (uint32_t valueIdx = 0; valueIdx < gHashTable.entryCount; valueIdx++, walker++) {
for (uint32_t valueIdx = 0; valueIdx < gHashTable.EntryCount(); valueIdx++, walker++) {
if (*walker) {
outStream->Write(*walker, strlen(*walker), &writeAmount);
outStream->Write(NS_LINEBREAK, NS_LINEBREAK_LEN, &writeAmount);
Expand Down
2 changes: 1 addition & 1 deletion modules/libpref/nsPrefBranch.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -895,4 +895,4 @@ NS_IMETHODIMP nsRelativeFilePref::SetRelativeToKey(const nsACString& aRelativeTo
return NS_OK;
}

#undef ENSURE_MAIN_PROCESS
#undef ENSURE_MAIN_PROCESS
4 changes: 2 additions & 2 deletions modules/libpref/prefapi.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ clearPrefEntry(PLDHashTable *table, PLDHashEntryHdr *entry)
// don't need to free this as it's allocated in memory owned by
// gPrefNameArena
pref->key = nullptr;
memset(entry, 0, table->entrySize);
memset(entry, 0, table->EntrySize());
}

static bool
Expand All @@ -65,7 +65,7 @@ matchPrefEntry(PLDHashTable*, const PLDHashEntryHdr* entry,
return (strcmp(prefEntry->key, otherKey) == 0);
}

PLDHashTable gHashTable = { nullptr };
PLDHashTable gHashTable;
static PLArenaPool gPrefNameArena;
bool gDirty = false;

Expand Down
16 changes: 8 additions & 8 deletions netwerk/base/src/nsLoadGroup.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -230,7 +230,7 @@ nsLoadGroup::Cancel(nsresult status)

NS_ASSERTION(NS_FAILED(status), "shouldn't cancel with a success code");
nsresult rv;
uint32_t count = mRequests.entryCount;
uint32_t count = mRequests.EntryCount();

nsAutoTArray<nsIRequest*, 8> requests;

Expand Down Expand Up @@ -301,7 +301,7 @@ nsLoadGroup::Cancel(nsresult status)
}

#if defined(DEBUG)
NS_ASSERTION(mRequests.entryCount == 0, "Request list is not empty.");
NS_ASSERTION(mRequests.EntryCount() == 0, "Request list is not empty.");
NS_ASSERTION(mForegroundCount == 0, "Foreground URLs are active.");
#endif

Expand All @@ -316,7 +316,7 @@ NS_IMETHODIMP
nsLoadGroup::Suspend()
{
nsresult rv, firstError;
uint32_t count = mRequests.entryCount;
uint32_t count = mRequests.EntryCount();

nsAutoTArray<nsIRequest*, 8> requests;

Expand Down Expand Up @@ -368,7 +368,7 @@ NS_IMETHODIMP
nsLoadGroup::Resume()
{
nsresult rv, firstError;
uint32_t count = mRequests.entryCount;
uint32_t count = mRequests.EntryCount();

nsAutoTArray<nsIRequest*, 8> requests;

Expand Down Expand Up @@ -489,7 +489,7 @@ nsLoadGroup::AddRequest(nsIRequest *request, nsISupports* ctxt)
nsAutoCString nameStr;
request->GetName(nameStr);
LOG(("LOADGROUP [%x]: Adding request %x %s (count=%d).\n",
this, request, nameStr.get(), mRequests.entryCount));
this, request, nameStr.get(), mRequests.EntryCount()));
}
#endif /* PR_LOGGING */

Expand Down Expand Up @@ -602,7 +602,7 @@ nsLoadGroup::RemoveRequest(nsIRequest *request, nsISupports* ctxt,
nsAutoCString nameStr;
request->GetName(nameStr);
LOG(("LOADGROUP [%x]: Removing request %x %s status %x (count=%d).\n",
this, request, nameStr.get(), aStatus, mRequests.entryCount-1));
this, request, nameStr.get(), aStatus, mRequests.EntryCount() - 1));
}
#endif

Expand Down Expand Up @@ -664,7 +664,7 @@ nsLoadGroup::RemoveRequest(nsIRequest *request, nsISupports* ctxt,
}
}

if (mRequests.entryCount == 0) {
if (mRequests.EntryCount() == 0) {
TelemetryReport();
}

Expand Down Expand Up @@ -720,7 +720,7 @@ NS_IMETHODIMP
nsLoadGroup::GetRequests(nsISimpleEnumerator * *aRequests)
{
nsCOMArray<nsIRequest> requests;
requests.SetCapacity(mRequests.entryCount);
requests.SetCapacity(mRequests.EntryCount());

PL_DHashTableEnumerate(&mRequests, AppendRequestsToCOMArray, &requests);

Expand Down
2 changes: 1 addition & 1 deletion netwerk/protocol/http/nsHttp.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ struct HttpHeapAtom {
char value[1];
};

static struct PLDHashTable sAtomTable = {0};
static struct PLDHashTable sAtomTable;
static struct HttpHeapAtom *sHeapAtoms = nullptr;
static Mutex *sLock = nullptr;

Expand Down
4 changes: 2 additions & 2 deletions parser/htmlparser/nsHTMLEntities.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -73,8 +73,8 @@ static const PLDHashTableOps UnicodeToEntityOps = {
nullptr,
};

static PLDHashTable gEntityToUnicode = { 0 };
static PLDHashTable gUnicodeToEntity = { 0 };
static PLDHashTable gEntityToUnicode;
static PLDHashTable gUnicodeToEntity;
static nsrefcnt gTableRefCnt = 0;

#define HTML_ENTITY(_name, _value) { #_name, _value },
Expand Down
Loading

0 comments on commit df1c26a

Please sign in to comment.