use xpcom;s nsVoidPtrHashKey, r=aaronlev, sr=neil
authorsurkov.alexander@gmail.com
Fri, 13 Jul 2007 20:09:42 -0700
changeset 3466 2a9f4fda63beb7b5d1876d561184100fdffc1ee2
parent 3465 c6d5a23dc9451853f6d667e63e2e3b8bfc7523f4
child 3467 3f116f44e93f4f3c367bb477dbdb1a82fd56e62c
push id1
push userbsmedberg@mozilla.com
push dateThu, 20 Mar 2008 16:49:24 +0000
treeherderautoland@61007906a1f8 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersaaronlev, neil
milestone1.9a7pre
use xpcom;s nsVoidPtrHashKey, r=aaronlev, sr=neil
accessible/src/base/nsAccessNode.cpp
accessible/src/base/nsAccessNode.h
accessible/src/base/nsDocAccessible.h
accessible/src/xul/nsXULTreeAccessible.cpp
accessible/src/xul/nsXULTreeAccessible.h
--- a/accessible/src/base/nsAccessNode.cpp
+++ b/accessible/src/base/nsAccessNode.cpp
@@ -82,17 +82,17 @@
 
 nsIStringBundle *nsAccessNode::gStringBundle = 0;
 nsIStringBundle *nsAccessNode::gKeyStringBundle = 0;
 nsITimer *nsAccessNode::gDoCommandTimer = 0;
 nsIDOMNode *nsAccessNode::gLastFocusedNode = 0;
 PRBool nsAccessNode::gIsAccessibilityActive = PR_FALSE;
 PRBool nsAccessNode::gIsCacheDisabled = PR_FALSE;
 PRBool nsAccessNode::gIsFormFillEnabled = PR_FALSE;
-nsInterfaceHashtable<nsVoidHashKey, nsIAccessNode> nsAccessNode::gGlobalDocAccessibleCache;
+nsAccessNodeHashtable nsAccessNode::gGlobalDocAccessibleCache;
 
 nsApplicationAccessibleWrap *nsAccessNode::gApplicationAccessible = nsnull;
 
 nsIAccessibilityService *nsAccessNode::sAccService = nsnull;
 nsIAccessibilityService *nsAccessNode::GetAccService()
 {
   if (!sAccService) {
     nsresult rv = CallGetService("@mozilla.org/accessibilityService;1",
@@ -757,44 +757,47 @@ nsAccessNode::GetDOMNodeForContainer(nsI
         CallQueryInterface(doc.get(), &node);
       }
     }
   }
 
   return node;
 }
 
-void nsAccessNode::PutCacheEntry(nsInterfaceHashtable<nsVoidHashKey, nsIAccessNode> &aCache, 
-                                 void* aUniqueID, 
-                                 nsIAccessNode *aAccessNode)
+void
+nsAccessNode::PutCacheEntry(nsAccessNodeHashtable& aCache,
+                            void* aUniqueID,
+                            nsIAccessNode *aAccessNode)
 {
 #ifdef DEBUG_A11Y
   nsCOMPtr<nsIAccessNode> oldAccessNode;
   GetCacheEntry(aCache, aUniqueID, getter_AddRefs(oldAccessNode));
   NS_ASSERTION(!oldAccessNode, "This cache entry shouldn't exist already");
 #endif
   aCache.Put(aUniqueID, aAccessNode);
 }
 
-void nsAccessNode::GetCacheEntry(nsInterfaceHashtable<nsVoidHashKey, nsIAccessNode> &aCache, 
-                                 void* aUniqueID, 
-                                 nsIAccessNode **aAccessNode)
+void
+nsAccessNode::GetCacheEntry(nsAccessNodeHashtable& aCache,
+                            void* aUniqueID,
+                            nsIAccessNode **aAccessNode)
 {
   aCache.Get(aUniqueID, aAccessNode);  // AddRefs for us
 }
 
 PLDHashOperator nsAccessNode::ClearCacheEntry(const void* aKey, nsCOMPtr<nsIAccessNode>& aAccessNode, void* aUserArg)
 {
   nsCOMPtr<nsPIAccessNode> privateAccessNode(do_QueryInterface(aAccessNode));
   privateAccessNode->Shutdown();
 
   return PL_DHASH_REMOVE;
 }
 
-void nsAccessNode::ClearCache(nsInterfaceHashtable<nsVoidHashKey, nsIAccessNode> &aCache)
+void
+nsAccessNode::ClearCache(nsAccessNodeHashtable& aCache)
 {
   aCache.Enumerate(ClearCacheEntry, nsnull);
 }
 
 already_AddRefed<nsIDOMNode> nsAccessNode::GetCurrentFocus()
 {
   nsCOMPtr<nsIPresShell> shell = GetPresShellFor(mDOMNode);
   NS_ENSURE_TRUE(shell, nsnull);
--- a/accessible/src/base/nsAccessNode.h
+++ b/accessible/src/base/nsAccessNode.h
@@ -64,40 +64,18 @@ class nsIFrame;
 class nsIDOMNodeList;
 class nsITimer;
 class nsRootAccessible;
 class nsApplicationAccessibleWrap;
 
 #define ACCESSIBLE_BUNDLE_URL "chrome://global-platform/locale/accessible.properties"
 #define PLATFORM_KEYS_BUNDLE_URL "chrome://global-platform/locale/platformKeys.properties"
 
-/* hashkey wrapper using void* KeyType
- *
- * @see nsTHashtable::EntryType for specification
- */
-class nsVoidHashKey : public PLDHashEntryHdr
-{
-public:
-  typedef const void* KeyType;
-  typedef const void* KeyTypePointer;
-  
-  nsVoidHashKey(KeyTypePointer aKey) : mValue(aKey) { }
-  nsVoidHashKey(const nsVoidHashKey& toCopy) : mValue(toCopy.mValue) { }
-  ~nsVoidHashKey() { }
-
-  KeyType GetKey() const { return mValue; }
-  PRBool KeyEquals(KeyTypePointer aKey) const { return aKey == mValue; }
-
-  static KeyTypePointer KeyToPointer(KeyType aKey) { return aKey; }
-  static PLDHashNumber HashKey(KeyTypePointer aKey) { return NS_PTR_TO_INT32(aKey) >> 2; }
-  enum { ALLOW_MEMMOVE = PR_TRUE };
-
-private:
-  const void* mValue;
-};
+typedef nsInterfaceHashtable<nsVoidPtrHashKey, nsIAccessNode>
+        nsAccessNodeHashtable;
 
 class nsAccessNode: public nsIAccessNode, public nsPIAccessNode
 {
   public: // construction, destruction
     nsAccessNode(nsIDOMNode *, nsIWeakReference* aShell);
     virtual ~nsAccessNode();
 
     NS_DECL_ISUPPORTS
@@ -108,21 +86,21 @@ class nsAccessNode: public nsIAccessNode
     static void ShutdownXPAccessibility();
 
     /**
      * Return an application accessible.
      */
     static already_AddRefed<nsApplicationAccessibleWrap> GetApplicationAccessible();
 
     // Static methods for handling per-document cache
-    static void PutCacheEntry(nsInterfaceHashtable<nsVoidHashKey, nsIAccessNode>& aCache, 
+    static void PutCacheEntry(nsAccessNodeHashtable& aCache,
                               void* aUniqueID, nsIAccessNode *aAccessNode);
-    static void GetCacheEntry(nsInterfaceHashtable<nsVoidHashKey, nsIAccessNode>& aCache, void* aUniqueID, 
-                              nsIAccessNode **aAccessNode);
-    static void ClearCache(nsInterfaceHashtable<nsVoidHashKey, nsIAccessNode>& aCache);
+    static void GetCacheEntry(nsAccessNodeHashtable& aCache,
+                              void* aUniqueID, nsIAccessNode **aAccessNode);
+    static void ClearCache(nsAccessNodeHashtable& aCache);
 
     static PLDHashOperator PR_CALLBACK ClearCacheEntry(const void* aKey, nsCOMPtr<nsIAccessNode>& aAccessNode, void* aUserArg);
 
     // Static cache methods for global document cache
     static already_AddRefed<nsIAccessibleDocument> GetDocAccessibleFor(nsIWeakReference *aPresShell);
     static already_AddRefed<nsIAccessibleDocument> GetDocAccessibleFor(nsISupports *aContainer, PRBool aCanCreate = PR_FALSE);
     static already_AddRefed<nsIAccessibleDocument> GetDocAccessibleFor(nsIDOMNode *aNode);
 
@@ -179,17 +157,17 @@ protected:
     // Static data, we do our own refcounting for our static data
     static nsIStringBundle *gStringBundle;
     static nsIStringBundle *gKeyStringBundle;
     static nsITimer *gDoCommandTimer;
     static PRBool gIsAccessibilityActive;
     static PRBool gIsCacheDisabled;
     static PRBool gIsFormFillEnabled;
 
-    static nsInterfaceHashtable<nsVoidHashKey, nsIAccessNode> gGlobalDocAccessibleCache;
+    static nsAccessNodeHashtable gGlobalDocAccessibleCache;
 
 private:
   static nsIAccessibilityService *sAccService;
   static nsApplicationAccessibleWrap *gApplicationAccessible;
 };
 
 #endif
 
--- a/accessible/src/base/nsDocAccessible.h
+++ b/accessible/src/base/nsDocAccessible.h
@@ -130,17 +130,17 @@ class nsDocAccessible : public nsHyperTe
     /**
      * Fires accessible events when ARIA attribute is chaned.
      *
      * @param aContent - node that attribute is changed for
      * @param aAttribute - changed attribute
      */
     void ARIAAttributeChanged(nsIContent* aContent, nsIAtom* aAttribute);
 
-    nsInterfaceHashtable<nsVoidHashKey, nsIAccessNode> mAccessNodeCache;
+    nsAccessNodeHashtable mAccessNodeCache;
     void *mWnd;
     nsCOMPtr<nsIDocument> mDocument;
     nsCOMPtr<nsITimer> mScrollWatchTimer;
     nsCOMPtr<nsITimer> mFireEventTimer;
     PRUint16 mScrollPositionChangedTicks; // Used for tracking scroll events
     PRPackedBool mIsContentLoaded;
     nsCOMArray<nsIAccessibleEvent> mEventsToFire;
     nsCOMPtr<nsIEditor> mEditor;
--- a/accessible/src/xul/nsXULTreeAccessible.cpp
+++ b/accessible/src/xul/nsXULTreeAccessible.cpp
@@ -127,17 +127,17 @@ nsXULTreeAccessible::nsXULTreeAccessible
 nsXULSelectableAccessible(aDOMNode, aShell),
 mAccessNodeCache(nsnull)
 
 {
   GetTreeBoxObject(aDOMNode, getter_AddRefs(mTree));
   if (mTree)
     mTree->GetView(getter_AddRefs(mTreeView));
   NS_ASSERTION(mTree && mTreeView, "Can't get mTree or mTreeView!\n");
-  mAccessNodeCache = new nsInterfaceHashtable<nsVoidHashKey, nsIAccessNode>;
+  mAccessNodeCache = new nsAccessNodeHashtable;
   mAccessNodeCache->Init(kDefaultTreeCacheSize);
 }
 
 NS_IMPL_ISUPPORTS_INHERITED1(nsXULTreeAccessible, nsXULSelectableAccessible, nsIAccessibleTreeCache)
                                                                                                        
 
 
 // Get the nsITreeBoxObject interface from any levels DOMNode under the <tree>
--- a/accessible/src/xul/nsXULTreeAccessible.h
+++ b/accessible/src/xul/nsXULTreeAccessible.h
@@ -79,17 +79,17 @@ public:
   static PRBool IsColumnHidden(nsITreeColumn *aColumn);
   static already_AddRefed<nsITreeColumn> GetNextVisibleColumn(nsITreeColumn *aColumn);
   static already_AddRefed<nsITreeColumn> GetFirstVisibleColumn(nsITreeBoxObject *aTree);
   static already_AddRefed<nsITreeColumn> GetLastVisibleColumn(nsITreeBoxObject *aTree);
 
 protected:
   nsCOMPtr<nsITreeBoxObject> mTree;
   nsCOMPtr<nsITreeView> mTreeView;
-  nsInterfaceHashtable<nsVoidHashKey, nsIAccessNode> *mAccessNodeCache;
+  nsAccessNodeHashtable *mAccessNodeCache;
 
   NS_IMETHOD ChangeSelection(PRInt32 aIndex, PRUint8 aMethod, PRBool *aSelState);
 };
 
 /**
   * Treeitems -- used in Trees
   */
 class nsXULTreeitemAccessible : public nsLeafAccessible