зеркало из https://github.com/mozilla/gecko-dev.git
Bug 1123151 (part 3) - Make PLDHashTable::ops private. r=froydnj.
This required adding a getter and a setter, but they're used sparingly. --HG-- extra : rebase_source : 2a40e459de2a7a9e2bb6d65b046e4a920b212326
This commit is contained in:
Родитель
8bd1f6f072
Коммит
2116ab605f
|
@ -1958,8 +1958,8 @@ NPObjWrapperPluginDestroyedCallback(PLDHashTable *table, PLDHashEntryHdr *hdr,
|
|||
if (entry->mNpp == nppcx->npp) {
|
||||
// Prevent invalidate() and deallocate() from touching the hash
|
||||
// we're enumerating.
|
||||
const PLDHashTableOps *ops = table->ops;
|
||||
table->ops = nullptr;
|
||||
const PLDHashTableOps *ops = table->Ops();
|
||||
table->SetOps(nullptr);
|
||||
|
||||
NPObject *npobj = entry->mNPObj;
|
||||
|
||||
|
@ -1987,7 +1987,7 @@ NPObjWrapperPluginDestroyedCallback(PLDHashTable *table, PLDHashEntryHdr *hdr,
|
|||
|
||||
::JS_SetPrivate(entry->mJSObj, nullptr);
|
||||
|
||||
table->ops = ops;
|
||||
table->SetOps(ops);
|
||||
|
||||
if (sDelayedReleases && sDelayedReleases->RemoveElement(npobj)) {
|
||||
OnWrapperDestroyed();
|
||||
|
|
|
@ -218,7 +218,7 @@ RuleHash_CIMatchEntry(PLDHashTable *table, const PLDHashEntryHdr *hdr,
|
|||
nsIAtom *match_atom = const_cast<nsIAtom*>(static_cast<const nsIAtom*>
|
||||
(key));
|
||||
// Use our extra |getKey| callback to avoid code duplication.
|
||||
nsIAtom *entry_atom = ToLocalOps(table->ops)->getKey(table, hdr);
|
||||
nsIAtom *entry_atom = ToLocalOps(table->Ops())->getKey(table, hdr);
|
||||
|
||||
// Check for case-sensitive match first.
|
||||
if (match_atom == entry_atom)
|
||||
|
@ -240,7 +240,7 @@ RuleHash_CSMatchEntry(PLDHashTable *table, const PLDHashEntryHdr *hdr,
|
|||
nsIAtom *match_atom = const_cast<nsIAtom*>(static_cast<const nsIAtom*>
|
||||
(key));
|
||||
// Use our extra |getKey| callback to avoid code duplication.
|
||||
nsIAtom *entry_atom = ToLocalOps(table->ops)->getKey(table, hdr);
|
||||
nsIAtom *entry_atom = ToLocalOps(table->Ops())->getKey(table, hdr);
|
||||
|
||||
return match_atom == entry_atom;
|
||||
}
|
||||
|
|
|
@ -300,8 +300,8 @@ public:
|
|||
*/
|
||||
void SwapElements(nsTHashtable<EntryType>& aOther)
|
||||
{
|
||||
MOZ_ASSERT_IF(this->mTable.ops && aOther.mTable.ops,
|
||||
this->mTable.ops == aOther.mTable.ops);
|
||||
MOZ_ASSERT_IF(this->mTable.Ops() && aOther.mTable.Ops(),
|
||||
this->mTable.Ops() == aOther.mTable.Ops());
|
||||
mozilla::Swap(this->mTable, aOther.mTable);
|
||||
}
|
||||
|
||||
|
@ -408,7 +408,7 @@ nsTHashtable<EntryType>::nsTHashtable(nsTHashtable<EntryType>&& aOther)
|
|||
|
||||
// Indicate that aOther is not initialized. This will make its destructor a
|
||||
// nop, which is what we want.
|
||||
aOther.mTable.ops = nullptr;
|
||||
aOther.mTable.SetOps(nullptr);
|
||||
}
|
||||
|
||||
template<class EntryType>
|
||||
|
|
|
@ -27,7 +27,7 @@
|
|||
|
||||
/*
|
||||
* The following DEBUG-only code is used to assert that calls to one of
|
||||
* table->ops or to an enumerator do not cause re-entry into a call that
|
||||
* table->mOps or to an enumerator do not cause re-entry into a call that
|
||||
* can mutate the table.
|
||||
*/
|
||||
#ifdef DEBUG
|
||||
|
@ -255,7 +255,7 @@ PLDHashTable::Init(const PLDHashTableOps* aOps,
|
|||
METER(memset(&mStats, 0, sizeof(mStats)));
|
||||
|
||||
// Set this only once we reach a point where we know we can't fail.
|
||||
ops = aOps;
|
||||
mOps = aOps;
|
||||
|
||||
#ifdef DEBUG
|
||||
mRecursionLevel = 0;
|
||||
|
@ -330,12 +330,12 @@ PLDHashTable::Finish()
|
|||
PLDHashEntryHdr* entry = (PLDHashEntryHdr*)entryAddr;
|
||||
if (ENTRY_IS_LIVE(entry)) {
|
||||
METER(mStats.mRemoveEnums++);
|
||||
ops->clearEntry(this, entry);
|
||||
mOps->clearEntry(this, entry);
|
||||
}
|
||||
entryAddr += mEntrySize;
|
||||
}
|
||||
|
||||
ops = nullptr;
|
||||
mOps = nullptr;
|
||||
|
||||
DECREMENT_RECURSION_LEVEL(this);
|
||||
MOZ_ASSERT(RECURSION_LEVEL_SAFE_TO_FINISH(this));
|
||||
|
@ -369,7 +369,7 @@ PLDHashTable::SearchTable(const void* aKey, PLDHashNumber aKeyHash,
|
|||
}
|
||||
|
||||
/* Hit: return entry. */
|
||||
PLDHashMatchEntry matchEntry = ops->matchEntry;
|
||||
PLDHashMatchEntry matchEntry = mOps->matchEntry;
|
||||
if (MATCH_ENTRY_KEYHASH(entry, aKeyHash) &&
|
||||
matchEntry(this, entry, aKey)) {
|
||||
METER(mStats.mHits++);
|
||||
|
@ -503,7 +503,7 @@ PLDHashTable::ChangeTable(int aDeltaLog2)
|
|||
char* oldEntryAddr;
|
||||
oldEntryAddr = oldEntryStore = mEntryStore;
|
||||
mEntryStore = newEntryStore;
|
||||
PLDHashMoveEntry moveEntry = ops->moveEntry;
|
||||
PLDHashMoveEntry moveEntry = mOps->moveEntry;
|
||||
#ifdef DEBUG
|
||||
mRecursionLevel = recursionLevelTmp;
|
||||
#endif
|
||||
|
@ -535,7 +535,7 @@ PLDHashTable::Operate(const void* aKey, PLDHashOperator aOp)
|
|||
MOZ_ASSERT(aOp == PL_DHASH_LOOKUP || mRecursionLevel == 0);
|
||||
INCREMENT_RECURSION_LEVEL(this);
|
||||
|
||||
PLDHashNumber keyHash = ops->hashKey(this, aKey);
|
||||
PLDHashNumber keyHash = mOps->hashKey(this, aKey);
|
||||
keyHash *= PL_DHASH_GOLDEN_RATIO;
|
||||
|
||||
/* Avoid 0 and 1 hash codes, they indicate free and removed entries. */
|
||||
|
@ -592,7 +592,7 @@ PLDHashTable::Operate(const void* aKey, PLDHashOperator aOp)
|
|||
mRemovedCount--;
|
||||
keyHash |= COLLISION_FLAG;
|
||||
}
|
||||
if (ops->initEntry && !ops->initEntry(this, entry, aKey)) {
|
||||
if (mOps->initEntry && !mOps->initEntry(this, entry, aKey)) {
|
||||
/* We haven't claimed entry yet; fail with null return. */
|
||||
memset(entry + 1, 0, mEntrySize - sizeof(*entry));
|
||||
entry = nullptr;
|
||||
|
@ -683,7 +683,7 @@ PLDHashTable::RawRemove(PLDHashEntryHdr* aEntry)
|
|||
|
||||
/* Load keyHash first in case clearEntry() goofs it. */
|
||||
PLDHashNumber keyHash = aEntry->keyHash;
|
||||
ops->clearEntry(this, aEntry);
|
||||
mOps->clearEntry(this, aEntry);
|
||||
if (keyHash & COLLISION_FLAG) {
|
||||
MARK_ENTRY_REMOVED(aEntry);
|
||||
mRemovedCount++;
|
||||
|
|
|
@ -128,7 +128,7 @@ typedef enum PLDHashOperator
|
|||
*
|
||||
* The return value, op, is treated as a set of flags. If op is PL_DHASH_NEXT,
|
||||
* then continue enumerating. If op contains PL_DHASH_REMOVE, then clear (via
|
||||
* aTable->ops->clearEntry) and free entry. Then we check whether op contains
|
||||
* aTable->mOps->clearEntry) and free entry. Then we check whether op contains
|
||||
* PL_DHASH_STOP; if so, stop enumerating and return the number of live entries
|
||||
* that were enumerated so far. Return the total number of live entries when
|
||||
* enumeration completes normally.
|
||||
|
@ -176,14 +176,8 @@ typedef size_t (*PLDHashSizeOfEntryExcludingThisFun)(
|
|||
*/
|
||||
class PLDHashTable
|
||||
{
|
||||
public:
|
||||
/*
|
||||
* Virtual operations; see below. This field is public because it's commonly
|
||||
* zeroed to indicate that a table is no longer live.
|
||||
*/
|
||||
const PLDHashTableOps* ops;
|
||||
|
||||
private:
|
||||
const PLDHashTableOps* mOps; /* Virtual operations; see below. */
|
||||
int16_t mHashShift; /* multiplicative hash shift */
|
||||
/*
|
||||
* |mRecursionLevel| is only used in debug builds, but is present in opt
|
||||
|
@ -222,11 +216,11 @@ private:
|
|||
#endif
|
||||
|
||||
public:
|
||||
// The most important thing here is that we zero |ops| because it's used to
|
||||
// The most important thing here is that we zero |mOps| 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)
|
||||
: mOps(nullptr)
|
||||
, mHashShift(0)
|
||||
, mRecursionLevel(0)
|
||||
, mEntrySize(0)
|
||||
|
@ -239,7 +233,11 @@ public:
|
|||
#endif
|
||||
{}
|
||||
|
||||
bool IsInitialized() const { return !!ops; }
|
||||
bool IsInitialized() const { return !!mOps; }
|
||||
|
||||
// These should be used rarely.
|
||||
const PLDHashTableOps* const Ops() { return mOps; }
|
||||
void SetOps(const PLDHashTableOps* aOps) { mOps = aOps; }
|
||||
|
||||
/*
|
||||
* Size in entries (gross, not net of free and removed sentinels) for table.
|
||||
|
@ -400,7 +398,7 @@ struct PLDHashTableOps
|
|||
};
|
||||
|
||||
/*
|
||||
* Default implementations for the above ops.
|
||||
* Default implementations for the above mOps.
|
||||
*/
|
||||
|
||||
PLDHashNumber PL_DHashStringKey(PLDHashTable* aTable, const void* aKey);
|
||||
|
@ -448,7 +446,7 @@ PLDHashTable* PL_NewDHashTable(
|
|||
|
||||
/*
|
||||
* Free |aTable|'s entry storage and |aTable| itself (both via
|
||||
* aTable->ops->freeTable). Use this function to destroy a PLDHashTable that
|
||||
* aTable->mOps->freeTable). Use this function to destroy a PLDHashTable that
|
||||
* was allocated on the heap via PL_NewDHashTable().
|
||||
*/
|
||||
void PL_DHashTableDestroy(PLDHashTable* aTable);
|
||||
|
@ -475,9 +473,9 @@ MOZ_WARN_UNUSED_RESULT bool PL_DHashTableInit(
|
|||
uint32_t aLength = PL_DHASH_DEFAULT_INITIAL_LENGTH);
|
||||
|
||||
/*
|
||||
* Free |aTable|'s entry storage (via aTable->ops->freeTable). Use this function
|
||||
* to destroy a PLDHashTable that is allocated on the stack or in static memory
|
||||
* and was created via PL_DHashTableInit().
|
||||
* Free |aTable|'s entry storage (via aTable->mOps->freeTable). Use this
|
||||
* function to destroy a PLDHashTable that is allocated on the stack or in
|
||||
* static memory and was created via PL_DHashTableInit().
|
||||
*/
|
||||
void PL_DHashTableFinish(PLDHashTable* aTable);
|
||||
|
||||
|
@ -499,7 +497,7 @@ PL_DHashTableLookup(PLDHashTable* aTable, const void* aKey);
|
|||
*
|
||||
* If entry is null upon return, then either the table is severely overloaded,
|
||||
* and memory can't be allocated for entry storage. Or if
|
||||
* aTable->ops->initEntry is non-null, the aTable->ops->initEntry op may have
|
||||
* aTable->mOps->initEntry is non-null, the aTable->mOps->initEntry op may have
|
||||
* returned false.
|
||||
*
|
||||
* Otherwise, aEntry->keyHash has been set so that PL_DHASH_ENTRY_IS_BUSY(entry)
|
||||
|
@ -515,7 +513,7 @@ PL_DHashTableAdd(PLDHashTable* aTable, const void* aKey);
|
|||
*
|
||||
* PL_DHashTableRemove(table, key);
|
||||
*
|
||||
* If key's entry is found, it is cleared (via table->ops->clearEntry) and
|
||||
* If key's entry is found, it is cleared (via table->mOps->clearEntry) and
|
||||
* the entry is marked so that PL_DHASH_ENTRY_IS_FREE(entry). This operation
|
||||
* returns null unconditionally; you should ignore its return value.
|
||||
*/
|
||||
|
@ -540,7 +538,7 @@ PL_DHashTableEnumerate(PLDHashTable* aTable, PLDHashEnumerator aEtor,
|
|||
/**
|
||||
* Measure the size of the table's entry storage, and if
|
||||
* |aSizeOfEntryExcludingThis| is non-nullptr, measure the size of things
|
||||
* pointed to by entries. Doesn't measure |ops| because it's often shared
|
||||
* pointed to by entries. Doesn't measure |mOps| because it's often shared
|
||||
* between tables.
|
||||
*/
|
||||
size_t PL_DHashTableSizeOfExcludingThis(
|
||||
|
|
Загрузка…
Ссылка в новой задаче