Bug 896414 - Make nsDirectoryService::mHashtable an nsInterfaceHashtable; r=bsmedberg
authorMs2ger <ms2ger@gmail.com>
Wed, 24 Jul 2013 09:40:40 +0200
changeset 151962 710fe670c1660e3e80fc6fdb4de8d76dcb63c353
parent 151961 a03dad6ac12a8542bf419871604b7e687e498dac
child 151963 dc2f8b38224158a31a14321a520f3e0b2f9d5436
push id2859
push userakeybl@mozilla.com
push dateMon, 16 Sep 2013 19:14:59 +0000
treeherdermozilla-beta@87d3c51cd2bf [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersbsmedberg
bugs896414
milestone25.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 896414 - Make nsDirectoryService::mHashtable an nsInterfaceHashtable; r=bsmedberg
xpcom/io/nsDirectoryService.cpp
xpcom/io/nsDirectoryService.h
--- a/xpcom/io/nsDirectoryService.cpp
+++ b/xpcom/io/nsDirectoryService.cpp
@@ -214,19 +214,19 @@ nsDirectoryService::GetCurrentProcessDir
     NS_RELEASE(localFile);
 
     NS_ERROR("unable to get current process directory");
     return NS_ERROR_FAILURE;
 } // GetCurrentProcessDirectory()
 
 nsDirectoryService* nsDirectoryService::gService = nullptr;
 
-nsDirectoryService::nsDirectoryService() :
-    mHashtable(256, true)
+nsDirectoryService::nsDirectoryService()
 {
+    mHashtable.Init(256);
 }
 
 nsresult
 nsDirectoryService::Create(nsISupports *outer, REFNSIID aIID, void **aResult)
 {
     NS_ENSURE_ARG_POINTER(aResult);
     NS_ENSURE_NO_AGGREGATION(outer);
 
@@ -271,41 +271,33 @@ nsDirectoryService::RealInit()
     
     // Let the list hold the only reference to the provider.
     nsAppFileLocationProvider *defaultProvider = new nsAppFileLocationProvider;
     self->mProviders.AppendElement(defaultProvider);
 
     self.swap(gService);
 }
 
-bool
-nsDirectoryService::ReleaseValues(nsHashKey* key, void* data, void* closure)
-{
-    nsISupports* value = (nsISupports*)data;
-    NS_IF_RELEASE(value);
-    return true;
-}
-
 nsDirectoryService::~nsDirectoryService()
 {
 }
 
 NS_IMPL_ISUPPORTS4(nsDirectoryService, nsIProperties, nsIDirectoryService, nsIDirectoryServiceProvider, nsIDirectoryServiceProvider2)
 
 
 NS_IMETHODIMP
 nsDirectoryService::Undefine(const char* prop)
 {
     NS_ENSURE_ARG(prop);
 
-    nsCStringKey key(prop);
-    if (!mHashtable.Exists(&key))
+    nsDependentCString key(prop);
+    if (!mHashtable.Get(key, nullptr))
         return NS_ERROR_FAILURE;
 
-    mHashtable.Remove (&key);
+    mHashtable.Remove(key);
     return NS_OK;
  }
 
 NS_IMETHODIMP
 nsDirectoryService::GetKeys(uint32_t *count, char ***keys)
 {
     return NS_ERROR_NOT_IMPLEMENTED;
 }
@@ -367,27 +359,22 @@ static bool FindProviderFile(nsIDirector
   return true;
 }
 
 NS_IMETHODIMP
 nsDirectoryService::Get(const char* prop, const nsIID & uuid, void* *result)
 {
     NS_ENSURE_ARG(prop);
 
-    nsCStringKey key(prop);
-    
-    nsCOMPtr<nsISupports> value = dont_AddRef(mHashtable.Get(&key));
-    
-    if (value)
-    {
+    nsDependentCString key(prop);
+
+    nsCOMPtr<nsIFile> cachedFile = mHashtable.Get(key);
+
+    if (cachedFile) {
         nsCOMPtr<nsIFile> cloneFile;
-        nsCOMPtr<nsIFile> cachedFile = do_QueryInterface(value);
-        NS_ASSERTION(cachedFile, 
-                     "nsDirectoryService::Get nsIFile expected");
-
         cachedFile->Clone(getter_AddRefs(cloneFile));
         return cloneFile->QueryInterface(uuid, result);
     }
 
     // it is not one of our defaults, lets check any providers
     FileData fileData(prop, uuid);
 
     for (int32_t i = mProviders.Length() - 1; i >= 0; i--) {
@@ -421,32 +408,31 @@ nsDirectoryService::Get(const char* prop
     return NS_ERROR_FAILURE;
 }
 
 NS_IMETHODIMP
 nsDirectoryService::Set(const char* prop, nsISupports* value)
 {
     NS_ENSURE_ARG(prop);
 
-    nsCStringKey key(prop);
-    if (mHashtable.Exists(&key) || value == nullptr)
+    nsDependentCString key(prop);
+    if (mHashtable.Get(key, nullptr) || !value) {
         return NS_ERROR_FAILURE;
+    }
 
-    nsCOMPtr<nsIFile> ourFile;
-    value->QueryInterface(NS_GET_IID(nsIFile), getter_AddRefs(ourFile));
-    if (ourFile)
-    {
+    nsCOMPtr<nsIFile> ourFile = do_QueryInterface(value);
+    if (ourFile) {
       nsCOMPtr<nsIFile> cloneFile;
       ourFile->Clone (getter_AddRefs (cloneFile));
-      mHashtable.Put(&key, cloneFile);
+      mHashtable.Put(key, cloneFile);
 
       return NS_OK;
     }
 
-    return NS_ERROR_FAILURE;   
+    return NS_ERROR_FAILURE;
 }
 
 NS_IMETHODIMP
 nsDirectoryService::Has(const char *prop, bool *_retval)
 {
     NS_ENSURE_ARG(prop);
 
     *_retval = false;
--- a/xpcom/io/nsDirectoryService.h
+++ b/xpcom/io/nsDirectoryService.h
@@ -2,17 +2,17 @@
 /* This Source Code Form is subject to the terms of the Mozilla Public
  * License, v. 2.0. If a copy of the MPL was not distributed with this
  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
 
 #ifndef nsDirectoryService_h___
 #define nsDirectoryService_h___
 
 #include "nsIDirectoryService.h"
-#include "nsHashtable.h"
+#include "nsInterfaceHashtable.h"
 #include "nsIFile.h"
 #include "nsIAtom.h"
 #include "nsTArray.h"
 #include "mozilla/Attributes.h"
 
 #define NS_XPCOM_INIT_CURRENT_PROCESS_DIR       "MozBinD"   // Can be used to set NS_XPCOM_CURRENT_PROCESS_DIR
                                                             // CANNOT be used to GET a location
 #define NS_DIRECTORY_SERVICE_CID  {0xf00152d0,0xb40b,0x11d3,{0x8c, 0x9c, 0x00, 0x00, 0x64, 0x65, 0x73, 0x74}}
@@ -43,18 +43,17 @@ class nsDirectoryService MOZ_FINAL : pub
   static nsresult
   Create(nsISupports *aOuter, REFNSIID aIID, void **aResult);
 
   static nsDirectoryService* gService;
 
 private:
     nsresult GetCurrentProcessDirectory(nsIFile** aFile);
     
-    static bool ReleaseValues(nsHashKey* key, void* data, void* closure);
-    nsSupportsHashtable mHashtable;
+    nsInterfaceHashtable<nsCStringHashKey, nsIFile> mHashtable;
     nsTArray<nsCOMPtr<nsIDirectoryServiceProvider> > mProviders;
 
 public:
 
 #define DIR_ATOM(name_, value_) static nsIAtom* name_;
 #include "nsDirectoryServiceAtomList.h"
 #undef DIR_ATOM