From e8279b37bc965a80352aa4587afe545a2d67fd59 Mon Sep 17 00:00:00 2001 From: "valeski%netscape.com" Date: Fri, 16 Jul 1999 17:41:29 +0000 Subject: [PATCH] necko - adjusted hash table initialization location to the constructor git-svn-id: svn://10.0.0.236/trunk@39710 18797224-902f-48f8-a5cc-f745e15eee43 --- mozilla/xpcom/ds/nsProperties.cpp | 40 ++++++++++++++++--------------- 1 file changed, 21 insertions(+), 19 deletions(-) diff --git a/mozilla/xpcom/ds/nsProperties.cpp b/mozilla/xpcom/ds/nsProperties.cpp index 918d24ac436..f0dd07412a0 100644 --- a/mozilla/xpcom/ds/nsProperties.cpp +++ b/mozilla/xpcom/ds/nsProperties.cpp @@ -153,13 +153,27 @@ NS_NewIProperties(nsIProperties* *result) #include "nsProperties.h" #include "pratom.h" +static PLHashNumber +HashKey(const PRUnichar *aString) +{ + return (PLHashNumber) nsCRT::HashValue(aString); +} + +static PRIntn +CompareKeys(const PRUnichar *aStr1, const PRUnichar *aStr2) +{ + return nsCRT::strcmp(aStr1, aStr2) == 0; +} + nsPersistentProperties::nsPersistentProperties() { NS_INIT_REFCNT(); mIn = nsnull; mSubclass = NS_STATIC_CAST(nsIPersistentProperties*, this); - mTable = nsnull; + mTable = PL_NewHashTable(8, (PLHashFunction) HashKey, + (PLHashComparator) CompareKeys, + (PLHashComparator) nsnull, nsnull, nsnull); } PR_STATIC_CALLBACK(PRIntn) @@ -272,18 +286,6 @@ nsPersistentProperties::Load(nsIInputStream *aIn) return NS_OK; } -static PLHashNumber -HashKey(const PRUnichar *aString) -{ - return (PLHashNumber) nsCRT::HashValue(aString); -} - -static PRIntn -CompareKeys(const PRUnichar *aStr1, const PRUnichar *aStr2) -{ - return nsCRT::strcmp(aStr1, aStr2) == 0; -} - NS_IMETHODIMP nsPersistentProperties::SetProperty(const nsString& aKey, nsString& aNewValue, nsString& aOldValue) @@ -294,12 +296,7 @@ nsPersistentProperties::SetProperty(const nsString& aKey, nsString& aNewValue, cout << "will add " << aKey.ToNewCString() << "=" << aNewValue.ToNewCString() << endl; #endif if (!mTable) { - mTable = PL_NewHashTable(8, (PLHashFunction) HashKey, - (PLHashComparator) CompareKeys, - (PLHashComparator) nsnull, nsnull, nsnull); - if (!mTable) { - return NS_ERROR_OUT_OF_MEMORY; - } + return NS_ERROR_FAILURE; } const PRUnichar *key = aKey.GetUnicode(); // returns internal pointer (not a copy) @@ -342,6 +339,11 @@ NS_IMETHODIMP nsPersistentProperties::GetProperty(const nsString& aKey, nsString& aValue) { const PRUnichar *key = aKey.GetUnicode(); + + if (!mTable) { + return NS_ERROR_FAILURE; + } + PRUint32 len; PRUint32 hashValue = nsCRT::HashValue(key, &len); PLHashEntry **hep = PL_HashTableRawLookup(mTable, hashValue, key);