Bug 967929 - Remove nsSupportsHashtable. r=bsmedberg
authorAndrew McCreight <continuation@gmail.com>
Mon, 24 Feb 2014 17:16:11 -0800
changeset 170658 3b32d0f94b57685ad54ba47aa8dadc29c9824bf1
parent 170657 68c714066b0cacd5602b8ff94a8bd0c44f080aef
child 170659 9f28160c038fd6048b7c689b951349fbd27b7d2b
push id270
push userpvanderbeken@mozilla.com
push dateThu, 06 Mar 2014 09:24:21 +0000
reviewersbsmedberg
bugs967929
milestone30.0a1
Bug 967929 - Remove nsSupportsHashtable. r=bsmedberg
xpcom/ds/nsHashtable.cpp
xpcom/ds/nsHashtable.h
--- a/xpcom/ds/nsHashtable.cpp
+++ b/xpcom/ds/nsHashtable.cpp
@@ -744,100 +744,8 @@ nsObjectHashtable::Reset()
 bool
 nsObjectHashtable::RemoveAndDelete(nsHashKey *aKey)
 {
     void *value = Remove(aKey);
     if (value && mDestroyElementFun)
         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();
-}
-
-////////////////////////////////////////////////////////////////////////////////
--- a/xpcom/ds/nsHashtable.h
+++ b/xpcom/ds/nsHashtable.h
@@ -148,51 +148,16 @@ class nsObjectHashtable : public nsHasht
 
     nsHashtableCloneElementFunc mCloneElementFun;
     void*                       mCloneElementClosure;
     nsHashtableEnumFunc         mDestroyElementFun;
     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.
 
 class nsISupportsKey : public nsHashKey {
   protected:
     nsISupports* mKey;
 
   public:
     nsISupportsKey(const nsISupportsKey& aKey) : mKey(aKey.mKey) {