Bug 896414 - Make nsDirectoryService::mHashtable an nsInterfaceHashtable; r=bsmedberg

This commit is contained in:
Ms2ger 2013-07-24 09:40:40 +02:00
parent 4f51466484
commit adbb8bab14
2 changed files with 19 additions and 34 deletions

View File

@ -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);
nsDependentCString key(prop);
nsCOMPtr<nsISupports> value = dont_AddRef(mHashtable.Get(&key));
nsCOMPtr<nsIFile> cachedFile = mHashtable.Get(key);
if (value)
{
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);
}
@ -426,17 +413,16 @@ 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;
}

View File

@ -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<nsCStringHashKey, nsIFile> mHashtable;
nsTArray<nsCOMPtr<nsIDirectoryServiceProvider> > mProviders;
public: