Bug 967929 - Remove nsSupportsHashtable. r=bsmedberg

This commit is contained in:
Andrew McCreight 2014-02-24 17:16:11 -08:00
parent 0afc7b1a2c
commit b9a671d070
2 changed files with 0 additions and 127 deletions

View File

@ -749,95 +749,3 @@ nsObjectHashtable::RemoveAndDelete(nsHashKey *aKey)
return !!(*mDestroyElementFun)(aKey, value, mDestroyElementClosure);
return false;
}
////////////////////////////////////////////////////////////////////////////////
// nsSupportsHashtable: an nsHashtable where the elements are nsISupports*
bool
nsSupportsHashtable::ReleaseElement(nsHashKey *aKey, void *aData, void* aClosure)
{
nsISupports* element = static_cast<nsISupports*>(aData);
NS_IF_RELEASE(element);
return true;
}
nsSupportsHashtable::~nsSupportsHashtable()
{
Enumerate(ReleaseElement, nullptr);
}
// Return true if we overwrote something
bool
nsSupportsHashtable::Put(nsHashKey *aKey, nsISupports* aData, nsISupports **value)
{
NS_IF_ADDREF(aData);
void *prev = nsHashtable::Put(aKey, aData);
nsISupports *old = reinterpret_cast<nsISupports *>(prev);
if (value) // pass own the ownership to the caller
*value = old;
else // the caller doesn't care, we do
NS_IF_RELEASE(old);
return prev != nullptr;
}
nsISupports *
nsSupportsHashtable::Get(nsHashKey *aKey)
{
void* data = nsHashtable::Get(aKey);
if (!data)
return nullptr;
nsISupports* element = reinterpret_cast<nsISupports*>(data);
NS_IF_ADDREF(element);
return element;
}
// Return true if we found something (useful for checks)
bool
nsSupportsHashtable::Remove(nsHashKey *aKey, nsISupports **value)
{
void* data = nsHashtable::Remove(aKey);
nsISupports* element = static_cast<nsISupports*>(data);
if (value) // caller wants it
*value = element;
else // caller doesn't care, we do
NS_IF_RELEASE(element);
return data != nullptr;
}
PLDHashOperator
nsSupportsHashtable::EnumerateCopy(PLDHashTable*,
PLDHashEntryHdr* hdr,
uint32_t i, void *arg)
{
nsHashtable *newHashtable = (nsHashtable *)arg;
HTEntry* entry = static_cast<HTEntry*>(hdr);
nsISupports* element = static_cast<nsISupports*>(entry->value);
NS_IF_ADDREF(element);
newHashtable->Put(entry->key, entry->value);
return PL_DHASH_NEXT;
}
nsHashtable*
nsSupportsHashtable::Clone()
{
if (!mHashtable.ops) return nullptr;
bool threadSafe = (mLock != nullptr);
nsSupportsHashtable* newHashTable =
new nsSupportsHashtable(mHashtable.entryCount, threadSafe);
PL_DHashTableEnumerate(&mHashtable, EnumerateCopy, newHashTable);
return newHashTable;
}
void
nsSupportsHashtable::Reset()
{
Enumerate(ReleaseElement, nullptr);
nsHashtable::Reset();
}
////////////////////////////////////////////////////////////////////////////////

View File

@ -152,41 +152,6 @@ class nsObjectHashtable : public nsHashtable {
void* mDestroyElementClosure;
};
////////////////////////////////////////////////////////////////////////////////
// nsSupportsHashtable: an nsHashtable where the elements are nsISupports*
class nsSupportsHashtable
: private nsHashtable
{
public:
nsSupportsHashtable(uint32_t aSize = 16, bool threadSafe = false)
: nsHashtable(aSize, threadSafe) {}
~nsSupportsHashtable();
int32_t Count(void) {
return nsHashtable::Count();
}
bool Exists(nsHashKey *aKey) {
return nsHashtable::Exists (aKey);
}
bool Put(nsHashKey *aKey,
nsISupports *aData,
nsISupports **value = nullptr);
nsISupports* Get(nsHashKey *aKey);
bool Remove(nsHashKey *aKey, nsISupports **value = nullptr);
nsHashtable *Clone();
void Enumerate(nsHashtableEnumFunc aEnumFunc, void* aClosure = nullptr) {
nsHashtable::Enumerate(aEnumFunc, aClosure);
}
void Reset();
private:
static bool ReleaseElement(nsHashKey *, void *, void *);
static PLDHashOperator EnumerateCopy(PLDHashTable*,
PLDHashEntryHdr* hdr,
uint32_t i, void *arg);
};
////////////////////////////////////////////////////////////////////////////////
// nsISupportsKey: Where keys are nsISupports objects that get refcounted.