From adbb8bab14ffb782f98a7f7526c217a6d13222a9 Mon Sep 17 00:00:00 2001 From: Ms2ger Date: Wed, 24 Jul 2013 09:40:40 +0200 Subject: [PATCH] Bug 896414 - Make nsDirectoryService::mHashtable an nsInterfaceHashtable; r=bsmedberg --- xpcom/io/nsDirectoryService.cpp | 48 ++++++++++++--------------------- xpcom/io/nsDirectoryService.h | 5 ++-- 2 files changed, 19 insertions(+), 34 deletions(-) diff --git a/xpcom/io/nsDirectoryService.cpp b/xpcom/io/nsDirectoryService.cpp index 6f8fc9c6af6..8fb48169d05 100644 --- a/xpcom/io/nsDirectoryService.cpp +++ b/xpcom/io/nsDirectoryService.cpp @@ -219,9 +219,9 @@ nsDirectoryService::GetCurrentProcessDirectory(nsIFile** aFile) nsDirectoryService* nsDirectoryService::gService = nullptr; -nsDirectoryService::nsDirectoryService() : - mHashtable(256, true) +nsDirectoryService::nsDirectoryService() { + mHashtable.Init(256); } nsresult @@ -276,14 +276,6 @@ nsDirectoryService::RealInit() self.swap(gService); } -bool -nsDirectoryService::ReleaseValues(nsHashKey* key, void* data, void* closure) -{ - nsISupports* value = (nsISupports*)data; - NS_IF_RELEASE(value); - return true; -} - nsDirectoryService::~nsDirectoryService() { } @@ -296,11 +288,11 @@ 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; } @@ -372,17 +364,12 @@ nsDirectoryService::Get(const char* prop, const nsIID & uuid, void* *result) { NS_ENSURE_ARG(prop); - nsCStringKey key(prop); - - nsCOMPtr value = dont_AddRef(mHashtable.Get(&key)); - - if (value) - { - nsCOMPtr cloneFile; - nsCOMPtr cachedFile = do_QueryInterface(value); - NS_ASSERTION(cachedFile, - "nsDirectoryService::Get nsIFile expected"); + nsDependentCString key(prop); + nsCOMPtr cachedFile = mHashtable.Get(key); + + if (cachedFile) { + nsCOMPtr cloneFile; cachedFile->Clone(getter_AddRefs(cloneFile)); return cloneFile->QueryInterface(uuid, result); } @@ -426,22 +413,21 @@ 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 ourFile; - value->QueryInterface(NS_GET_IID(nsIFile), getter_AddRefs(ourFile)); - if (ourFile) - { + nsCOMPtr ourFile = do_QueryInterface(value); + if (ourFile) { nsCOMPtr 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 diff --git a/xpcom/io/nsDirectoryService.h b/xpcom/io/nsDirectoryService.h index d02abfe1dcc..f5123a81668 100644 --- a/xpcom/io/nsDirectoryService.h +++ b/xpcom/io/nsDirectoryService.h @@ -7,7 +7,7 @@ #define nsDirectoryService_h___ #include "nsIDirectoryService.h" -#include "nsHashtable.h" +#include "nsInterfaceHashtable.h" #include "nsIFile.h" #include "nsIAtom.h" #include "nsTArray.h" @@ -48,8 +48,7 @@ class nsDirectoryService MOZ_FINAL : public nsIDirectoryService, private: nsresult GetCurrentProcessDirectory(nsIFile** aFile); - static bool ReleaseValues(nsHashKey* key, void* data, void* closure); - nsSupportsHashtable mHashtable; + nsInterfaceHashtable mHashtable; nsTArray > mProviders; public: