Bug 1118024 - Add explicit PL_DHashTable{Add,Lookup,Remove} functions. r=nfroyd

This commit is contained in:
Michael Pruett 2015-01-05 20:26:50 -06:00
Родитель e3953dff5f
Коммит 62960a5119
8 изменённых файлов: 49 добавлений и 25 удалений

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

@ -898,8 +898,7 @@ PtrInfo*
CCGraph::FindNode(void* aPtr)
{
PtrToNodeEntry* e =
static_cast<PtrToNodeEntry*>(PL_DHashTableOperate(&mPtrToNodeMap, aPtr,
PL_DHASH_LOOKUP));
static_cast<PtrToNodeEntry*>(PL_DHashTableLookup(&mPtrToNodeMap, aPtr));
if (!PL_DHASH_ENTRY_IS_BUSY(e)) {
return nullptr;
}
@ -911,8 +910,7 @@ CCGraph::AddNodeToMap(void* aPtr)
{
JS::AutoSuppressGCAnalysis suppress;
PtrToNodeEntry* e =
static_cast<PtrToNodeEntry*>(PL_DHashTableOperate(&mPtrToNodeMap, aPtr,
PL_DHASH_ADD));
static_cast<PtrToNodeEntry*>(PL_DHashTableAdd(&mPtrToNodeMap, aPtr));
if (!e) {
// Caller should track OOMs
return nullptr;
@ -923,7 +921,7 @@ CCGraph::AddNodeToMap(void* aPtr)
void
CCGraph::RemoveNodeFromMap(void* aPtr)
{
PL_DHashTableOperate(&mPtrToNodeMap, aPtr, PL_DHASH_REMOVE);
PL_DHashTableRemove(&mPtrToNodeMap, aPtr);
}

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

@ -404,7 +404,7 @@ AtomImpl::~AtomImpl()
// |AtomTableClearEntry|.
if (!IsPermanentInDestructor()) {
AtomTableKey key(mString, mLength, mHash);
PL_DHashTableOperate(&gAtomTable, &key, PL_DHASH_REMOVE);
PL_DHashTableRemove(&gAtomTable, &key);
if (gAtomTable.ops && gAtomTable.EntryCount() == 0) {
PL_DHashTableFinish(&gAtomTable);
NS_ASSERTION(gAtomTable.EntryCount() == 0,
@ -555,7 +555,7 @@ GetAtomHashEntry(const char* aString, uint32_t aLength, uint32_t* aHashOut)
EnsureTableExists();
AtomTableKey key(aString, aLength, aHashOut);
AtomTableEntry* e = static_cast<AtomTableEntry*>(
PL_DHashTableOperate(&gAtomTable, &key, PL_DHASH_ADD));
PL_DHashTableAdd(&gAtomTable, &key));
if (!e) {
NS_ABORT_OOM(gAtomTable.EntryCount() * gAtomTable.EntrySize());
}
@ -569,7 +569,7 @@ GetAtomHashEntry(const char16_t* aString, uint32_t aLength, uint32_t* aHashOut)
EnsureTableExists();
AtomTableKey key(aString, aLength, aHashOut);
AtomTableEntry* e = static_cast<AtomTableEntry*>(
PL_DHashTableOperate(&gAtomTable, &key, PL_DHASH_ADD));
PL_DHashTableAdd(&gAtomTable, &key));
if (!e) {
NS_ABORT_OOM(gAtomTable.EntryCount() * gAtomTable.EntrySize());
}

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

@ -533,7 +533,7 @@ nsPersistentProperties::SetStringProperty(const nsACString& aKey,
{
const nsAFlatCString& flatKey = PromiseFlatCString(aKey);
PropertyTableEntry* entry = static_cast<PropertyTableEntry*>(
PL_DHashTableOperate(&mTable, flatKey.get(), PL_DHASH_ADD));
PL_DHashTableAdd(&mTable, flatKey.get()));
if (entry->mKey) {
aOldValue = entry->mValue;
@ -572,7 +572,7 @@ nsPersistentProperties::GetStringProperty(const nsACString& aKey,
const nsAFlatCString& flatKey = PromiseFlatCString(aKey);
PropertyTableEntry* entry = static_cast<PropertyTableEntry*>(
PL_DHashTableOperate(&mTable, flatKey.get(), PL_DHASH_LOOKUP));
PL_DHashTableLookup(&mTable, flatKey.get()));
if (PL_DHASH_ENTRY_IS_FREE(entry)) {
return NS_ERROR_FAILURE;
@ -644,7 +644,7 @@ NS_IMETHODIMP
nsPersistentProperties::Has(const char* aProp, bool* aResult)
{
PropertyTableEntry* entry = static_cast<PropertyTableEntry*>(
PL_DHashTableOperate(&mTable, aProp, PL_DHASH_LOOKUP));
PL_DHashTableLookup(&mTable, aProp));
*aResult = (entry && PL_DHASH_ENTRY_IS_BUSY(entry));
return NS_OK;
}

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

@ -170,8 +170,7 @@ nsStaticCaseInsensitiveNameTable::Init(const char* const aNames[],
NameTableKey key(strPtr);
NameTableEntry* entry =
static_cast<NameTableEntry*>(PL_DHashTableOperate(&mNameTable, &key,
PL_DHASH_ADD));
static_cast<NameTableEntry*>(PL_DHashTableAdd(&mNameTable, &key));
if (!entry) {
continue;
}
@ -197,8 +196,7 @@ nsStaticCaseInsensitiveNameTable::Lookup(const nsACString& aName)
NameTableKey key(&str);
NameTableEntry* entry =
static_cast<NameTableEntry*>(PL_DHashTableOperate(&mNameTable, &key,
PL_DHASH_LOOKUP));
static_cast<NameTableEntry*>(PL_DHashTableLookup(&mNameTable, &key));
if (PL_DHASH_ENTRY_IS_FREE(entry)) {
return nsStaticCaseInsensitiveNameTable::NOT_FOUND;
}
@ -216,8 +214,7 @@ nsStaticCaseInsensitiveNameTable::Lookup(const nsAString& aName)
NameTableKey key(&str);
NameTableEntry* entry =
static_cast<NameTableEntry*>(PL_DHashTableOperate(&mNameTable, &key,
PL_DHASH_LOOKUP));
static_cast<NameTableEntry*>(PL_DHashTableLookup(&mNameTable, &key));
if (PL_DHASH_ENTRY_IS_FREE(entry)) {
return nsStaticCaseInsensitiveNameTable::NOT_FOUND;
}

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

@ -128,8 +128,8 @@ public:
NS_ASSERTION(mTable.ops, "nsTHashtable was not initialized properly.");
EntryType* entry = reinterpret_cast<EntryType*>(
PL_DHashTableOperate(const_cast<PLDHashTable*>(&mTable),
EntryType::KeyToPointer(aKey), PL_DHASH_LOOKUP));
PL_DHashTableLookup(const_cast<PLDHashTable*>(&mTable),
EntryType::KeyToPointer(aKey)));
return PL_DHASH_ENTRY_IS_BUSY(entry) ? entry : nullptr;
}
@ -158,8 +158,8 @@ public:
EntryType* PutEntry(KeyType aKey, const fallible_t&) NS_WARN_UNUSED_RESULT {
NS_ASSERTION(mTable.ops, "nsTHashtable was not initialized properly.");
return static_cast<EntryType*>(PL_DHashTableOperate(
&mTable, EntryType::KeyToPointer(aKey), PL_DHASH_ADD));
return static_cast<EntryType*>(PL_DHashTableAdd(
&mTable, EntryType::KeyToPointer(aKey)));
}
/**
@ -170,9 +170,8 @@ public:
{
NS_ASSERTION(mTable.ops, "nsTHashtable was not initialized properly.");
PL_DHashTableOperate(&mTable,
EntryType::KeyToPointer(aKey),
PL_DHASH_REMOVE);
PL_DHashTableRemove(&mTable,
EntryType::KeyToPointer(aKey));
}
/**

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

@ -667,6 +667,24 @@ PL_DHashTableOperate(PLDHashTable* aTable, const void* aKey, PLDHashOperator aOp
return aTable->Operate(aKey, aOp);
}
PLDHashEntryHdr* PL_DHASH_FASTCALL
PL_DHashTableLookup(PLDHashTable* aTable, const void* aKey)
{
return aTable->Operate(aKey, PL_DHASH_LOOKUP);
}
PLDHashEntryHdr* PL_DHASH_FASTCALL
PL_DHashTableAdd(PLDHashTable* aTable, const void* aKey)
{
return aTable->Operate(aKey, PL_DHASH_ADD);
}
void PL_DHASH_FASTCALL
PL_DHashTableRemove(PLDHashTable* aTable, const void* aKey)
{
aTable->Operate(aKey, PL_DHASH_REMOVE);
}
MOZ_ALWAYS_INLINE void
PLDHashTable::RawRemove(PLDHashEntryHdr* aEntry)
{

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

@ -527,6 +527,18 @@ PLDHashEntryHdr* PL_DHASH_FASTCALL
PL_DHashTableOperate(PLDHashTable* aTable, const void* aKey,
PLDHashOperator aOp);
/* Look up a key in table. */
PLDHashEntryHdr* PL_DHASH_FASTCALL
PL_DHashTableLookup(PLDHashTable* aTable, const void* aKey);
/* Add an entry identified by key to table. */
PLDHashEntryHdr* PL_DHASH_FASTCALL
PL_DHashTableAdd(PLDHashTable* aTable, const void* aKey);
/* Remove an entry identified by key from table. */
void PL_DHASH_FASTCALL
PL_DHashTableRemove(PLDHashTable* aTable, const void* aKey);
/*
* Remove an entry already accessed via LOOKUP or ADD.
*

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

@ -99,7 +99,7 @@ static bool test_pldhash_grow_to_max_capacity()
// Keep inserting elements until failure occurs because the table is full.
size_t numInserted = 0;
while (true) {
if (!PL_DHashTableOperate(&t, (const void*)numInserted, PL_DHASH_ADD)) {
if (!PL_DHashTableAdd(&t, (const void*)numInserted)) {
break;
}
numInserted++;