diff --git a/mozilla/caps/include/nsScriptSecurityManager.h b/mozilla/caps/include/nsScriptSecurityManager.h index d0d5bfb263f..09a17b56402 100644 --- a/mozilla/caps/include/nsScriptSecurityManager.h +++ b/mozilla/caps/include/nsScriptSecurityManager.h @@ -62,7 +62,7 @@ public: NS_IF_RELEASE(mKey); } - PRUint32 HashValue(void) const { + PRUint32 HashCode(void) const { PRUint32 hash; mKey->HashValue(&hash); return hash; diff --git a/mozilla/caps/src/nsBasePrincipal.cpp b/mozilla/caps/src/nsBasePrincipal.cpp index 4be9bfcd8e4..2ef88b7c447 100644 --- a/mozilla/caps/src/nsBasePrincipal.cpp +++ b/mozilla/caps/src/nsBasePrincipal.cpp @@ -73,7 +73,7 @@ nsBasePrincipal::CanEnableCapability(const char *capability, PRInt16 *result) } else // If this principal is marked invalid, can't enable any capabilities { - nsStringKey invalidKey(Invalid); + nsCStringKey invalidKey(Invalid); if (mCapabilities->Exists(&invalidKey)) { *result = nsIPrincipal::ENABLE_DENIED; @@ -87,7 +87,7 @@ nsBasePrincipal::CanEnableCapability(const char *capability, PRInt16 *result) const char *space = PL_strchr(start, ' '); int len = space ? space - start : nsCRT::strlen(start); nsCAutoString capString(start, len); - nsStringKey key(capString); + nsCStringKey key(capString); PRInt16 value = (PRInt16)(PRInt32)mCapabilities->Get(&key); if (value == 0) value = nsIPrincipal::ENABLE_UNKNOWN; @@ -110,7 +110,7 @@ nsBasePrincipal::SetCanEnableCapability(const char *capability, } else // If this principal is marked invalid, can't enable any capabilities { - nsStringKey invalidKey(Invalid); + nsCStringKey invalidKey(Invalid); if (mCapabilities->Exists(&invalidKey)) return NS_OK; } @@ -123,7 +123,7 @@ nsBasePrincipal::SetCanEnableCapability(const char *capability, const char *space = PL_strchr(start, ' '); int len = space ? space - start : nsCRT::strlen(start); nsCAutoString capString(start, len); - nsStringKey key(capString); + nsCStringKey key(capString); mCapabilities->Put(&key, (void *) canEnable); if (!space) return NS_OK; @@ -145,7 +145,7 @@ nsBasePrincipal::IsCapabilityEnabled(const char *capability, void *annotation, const char *space = PL_strchr(start, ' '); int len = space ? space - start : nsCRT::strlen(start); nsCAutoString capString(start, len); - nsStringKey key(capString); + nsCStringKey key(capString); *result = (ht->Get(&key) == (void *) AnnotationEnabled); if (!*result) { // If any single capability is not enabled, then return false. @@ -180,7 +180,7 @@ nsBasePrincipal::RevertCapability(const char *capability, void **annotation) const char *space = PL_strchr(start, ' '); int len = space ? space - start : nsCRT::strlen(start); nsCAutoString capString(start, len); - nsStringKey key(capString); + nsCStringKey key(capString); ht->Remove(&key); if (!space) return NS_OK; @@ -208,7 +208,7 @@ nsBasePrincipal::SetCapability(const char *capability, void **annotation, const char *space = PL_strchr(start, ' '); int len = space ? space - start : nsCRT::strlen(start); nsCAutoString capString(start, len); - nsStringKey key(capString); + nsCStringKey key(capString); nsHashtable *ht = (nsHashtable *) *annotation; ht->Put(&key, (void *) value); if (!space) @@ -260,15 +260,16 @@ AppendCapability(nsHashKey *aKey, void *aData, void *capListPtr) { CapabilityList* capList = (CapabilityList*)capListPtr; PRInt16 value = (PRInt16)(PRInt32)aData; + nsCStringKey* key = (nsCStringKey *)aKey; if (value == nsIPrincipal::ENABLE_GRANTED) { - capList->granted->AppendWithConversion(((nsStringKey *) aKey)->GetString()); - capList->granted->Append(' '); + capList->granted->Append(key->GetString(), key->GetStringLength()); + capList->granted += ' '; } else if (value == nsIPrincipal::ENABLE_DENIED) { - capList->denied->AppendWithConversion(((nsStringKey *) aKey)->GetString()); - capList->denied->Append(' '); + capList->denied->Append(key->GetString(), key->GetStringLength()); + capList->denied += ' '; } return PR_TRUE; } diff --git a/mozilla/caps/src/nsCertificatePrincipal.cpp b/mozilla/caps/src/nsCertificatePrincipal.cpp index ce71cbeceb0..5c290205d7d 100644 --- a/mozilla/caps/src/nsCertificatePrincipal.cpp +++ b/mozilla/caps/src/nsCertificatePrincipal.cpp @@ -133,7 +133,7 @@ nsCertificatePrincipal::HashValue(PRUint32 *result) { char* str; if (NS_FAILED(ToString(&str)) || !str) return NS_ERROR_FAILURE; - *result = nsCRT::HashValue(str); + *result = nsCRT::HashCode(str, nsCRT::strlen(str)); nsCRT::free(str); return NS_OK; } diff --git a/mozilla/caps/src/nsCodebasePrincipal.cpp b/mozilla/caps/src/nsCodebasePrincipal.cpp index cf04867d04e..e6980d38f6b 100644 --- a/mozilla/caps/src/nsCodebasePrincipal.cpp +++ b/mozilla/caps/src/nsCodebasePrincipal.cpp @@ -74,7 +74,7 @@ nsCodebasePrincipal::HashValue(PRUint32 *result) nsXPIDLCString origin; if (NS_FAILED(GetOrigin(getter_Copies(origin)))) return NS_ERROR_FAILURE; - *result = nsCRT::HashValue(origin); + *result = nsCRT::HashCode(origin, nsCRT::strlen(origin)); return NS_OK; } diff --git a/mozilla/caps/src/nsScriptSecurityManager.cpp b/mozilla/caps/src/nsScriptSecurityManager.cpp index 38c01567617..ab24355a4c9 100644 --- a/mozilla/caps/src/nsScriptSecurityManager.cpp +++ b/mozilla/caps/src/nsScriptSecurityManager.cpp @@ -1683,7 +1683,7 @@ nsScriptSecurityManager::GetPrefName(nsIPrincipal *principal, } p++; } - nsStringKey key(nextToLastDot ? nextToLastDot+1 : s); + nsCStringKey key(nextToLastDot ? nextToLastDot+1 : s); nsDomainEntry *de = (nsDomainEntry *) mOriginToPolicyMap->Get(&key); while (de) { if (de->Matches(s)) { @@ -1849,7 +1849,7 @@ nsScriptSecurityManager::EnumeratePolicyCallback(const char *prefName, if (*r == ' ' || *r == '\0') { working = (*r != '\0'); *r = '\0'; - nsStringKey key(nextToLastDot ? nextToLastDot+1 : q); + nsCStringKey key(nextToLastDot ? nextToLastDot+1 : q); nsDomainEntry *value = new nsDomainEntry(q, policyName, policyLength); if (!value) diff --git a/mozilla/chrome/src/nsChromeRegistry.cpp b/mozilla/chrome/src/nsChromeRegistry.cpp index 55e5c42bf0c..e643c137849 100644 --- a/mozilla/chrome/src/nsChromeRegistry.cpp +++ b/mozilla/chrome/src/nsChromeRegistry.cpp @@ -848,7 +848,7 @@ NS_IMETHODIMP nsChromeRegistry::LoadDataSource(const nsCString &aFileName, if (mDataSourceTable) { - nsStringKey skey(key); + nsCStringKey skey(key); nsCOMPtr supports = getter_AddRefs(NS_STATIC_CAST(nsISupports*, mDataSourceTable->Get(&skey))); @@ -884,7 +884,7 @@ NS_IMETHODIMP nsChromeRegistry::LoadDataSource(const nsCString &aFileName, rv = remote->Refresh(PR_TRUE); nsCOMPtr supports = do_QueryInterface(remote); - nsStringKey skey(key); + nsCStringKey skey(key); mDataSourceTable->Put(&skey, supports.get()); return NS_OK; diff --git a/mozilla/content/base/src/nsHTMLValue.cpp b/mozilla/content/base/src/nsHTMLValue.cpp index 0e8d718f982..d52454acfe7 100644 --- a/mozilla/content/base/src/nsHTMLValue.cpp +++ b/mozilla/content/base/src/nsHTMLValue.cpp @@ -178,7 +178,7 @@ PRUint32 nsHTMLValue::HashValue(void) const return PRUint32(mUnit) ^ ((((eHTMLUnit_String == mUnit) || (eHTMLUnit_ColorName == mUnit)) && (nsnull != mValue.mString)) ? - nsCRT::HashValue(mValue.mString) : + nsCRT::HashCode(mValue.mString, nsCRT::strlen(mValue.mString)) : mValue.mInt); } diff --git a/mozilla/content/base/src/nsNameSpaceManager.cpp b/mozilla/content/base/src/nsNameSpaceManager.cpp index a3fad0a4429..34844cf646d 100644 --- a/mozilla/content/base/src/nsNameSpaceManager.cpp +++ b/mozilla/content/base/src/nsNameSpaceManager.cpp @@ -47,59 +47,6 @@ static nsVoidArray* gURIArray; MOZ_DECL_CTOR_COUNTER(NameSpaceURIKey); -class NameSpaceURIKey : public nsHashKey { -public: - NameSpaceURIKey(const nsString* aString) - : mString(aString) - { - MOZ_COUNT_CTOR(NameSpaceURIKey); - } - - virtual ~NameSpaceURIKey(void) - { - MOZ_COUNT_DTOR(NameSpaceURIKey); - } - - virtual PRUint32 HashValue(void) const - { -#if 1 // case insensitive XXX should this be case sensitive??? - PRUint32 hash = 0; - const PRUnichar* string = mString->GetUnicode(); - PRUnichar ch; - while ((ch = *string++) != 0) { - // FYI: hash = hash*37 + ch - ch = nsCRT::ToLower(ch); - hash = ((hash << 5) + (hash << 2) + hash) + ch; - } - return hash; -#else - if (nsnull != mString) { - return nsCRT::HashValue(mString->GetUnicode()); - } - return 0; -#endif - } - - virtual PRBool Equals(const nsHashKey *aKey) const - { - const nsString* other = ((const NameSpaceURIKey*)aKey)->mString; - if (nsnull != mString) { - if (nsnull != other) { - return mString->EqualsIgnoreCase(*other); // XXX case sensitive? - } - return PR_FALSE; - } - return PRBool(nsnull == other); - } - - virtual nsHashKey *Clone(void) const - { - return new NameSpaceURIKey(mString); - } - - const nsString* mString; -}; - static void AddRefTable() { if (0 == gNameSpaceTableRefs++) { @@ -119,11 +66,11 @@ static void AddRefTable() gURIArray->AppendElement(xhtml); gURIArray->AppendElement(xlink); gURIArray->AppendElement(html); - NameSpaceURIKey xmlnsKey(xmlns); - NameSpaceURIKey xmlKey(xml); - NameSpaceURIKey xhtmlKey(xhtml); - NameSpaceURIKey xlinkKey(xlink); - NameSpaceURIKey htmlKey(html); + nsStringKey xmlnsKey(*xmlns); + nsStringKey xmlKey(*xml); + nsStringKey xhtmlKey(*xhtml); + nsStringKey xlinkKey(*xlink); + nsStringKey htmlKey(*html); gURIToIDTable->Put(&xmlnsKey, (void*)kNameSpaceID_XMLNS); gURIToIDTable->Put(&xmlKey, (void*)kNameSpaceID_XML); gURIToIDTable->Put(&xhtmlKey, (void*)kNameSpaceID_HTML); @@ -152,7 +99,7 @@ static void ReleaseTable() static PRInt32 FindNameSpaceID(const nsString& aURI) { NS_ASSERTION(nsnull != gURIToIDTable, "no URI table"); - NameSpaceURIKey key(&aURI); + nsStringKey key(aURI); void* value = gURIToIDTable->Get(&key); if (nsnull != value) { return PRInt32(value); @@ -446,7 +393,7 @@ NameSpaceManagerImpl::RegisterNameSpace(const nsString& aURI, nsString* uri = new nsString(aURI); gURIArray->AppendElement(uri); id = gURIArray->Count(); // id is index + 1 - NameSpaceURIKey key(uri); + nsStringKey key(*uri); gURIToIDTable->Put(&key, (void*)id); } aNameSpaceID = id; diff --git a/mozilla/content/html/content/src/nsHTMLFormElement.cpp b/mozilla/content/html/content/src/nsHTMLFormElement.cpp index fb8d0f092a3..6a45030f4f8 100644 --- a/mozilla/content/html/content/src/nsHTMLFormElement.cpp +++ b/mozilla/content/html/content/src/nsHTMLFormElement.cpp @@ -851,7 +851,8 @@ nsFormControlList::GetNamedObject(JSContext* aContext, jsval aID, JSObject** aOb if (mLookupTable) { // Get the hash entry - nsStringKey key(str); + nsString ustr; ustr.AssignWithConversion(str); + nsStringKey key(ustr); nsCOMPtr tmp = dont_AddRef((nsISupports *)mLookupTable->Get(&key)); diff --git a/mozilla/content/html/style/src/nsCSSLoader.cpp b/mozilla/content/html/style/src/nsCSSLoader.cpp index f2e98c6b0f3..d9344c7cc8d 100644 --- a/mozilla/content/html/style/src/nsCSSLoader.cpp +++ b/mozilla/content/html/style/src/nsCSSLoader.cpp @@ -84,7 +84,7 @@ public: char* urlStr; mURL->GetSpec(&urlStr); if (urlStr) { - mHashValue = nsCRT::HashValue(urlStr); + mHashValue = nsCRT::HashCode(urlStr, nsCRT::strlen(urlStr)); nsCRT::free(urlStr); } } @@ -104,7 +104,7 @@ public: NS_RELEASE(mURL); } - virtual PRUint32 HashValue(void) const + virtual PRUint32 HashCode(void) const { return mHashValue; } @@ -126,48 +126,6 @@ public: PRUint32 mHashValue; }; -MOZ_DECL_CTOR_COUNTER(SupportsKey); - -class SupportsKey: public nsHashKey { -public: - SupportsKey(nsISupports* aSupports) - : nsHashKey(), - mSupports(aSupports) - { // note: does not hold reference on supports pointer - MOZ_COUNT_CTOR(SupportsKey); - } - - SupportsKey(const SupportsKey& aKey) - : nsHashKey(), - mSupports(aKey.mSupports) - { - MOZ_COUNT_CTOR(SupportsKey); - } - - virtual ~SupportsKey(void) - { - MOZ_COUNT_DTOR(SupportsKey); - } - - virtual PRUint32 HashValue(void) const - { - return (PRUint32)mSupports; - } - - virtual PRBool Equals(const nsHashKey* aKey) const - { - SupportsKey* key = (SupportsKey*)aKey; - return PRBool(mSupports == key->mSupports); - } - - virtual nsHashKey *Clone(void) const - { - return new SupportsKey(*this); - } - - nsISupports* mSupports; -}; - class SheetLoadData : public nsIStreamLoaderObserver { public: @@ -1113,7 +1071,7 @@ CSSLoaderImpl::InsertSheetInDoc(nsICSSStyleSheet* aSheet, PRInt32 aDocIndex, aSheet->GetTitle(title); aSheet->SetEnabled(! IsAlternate(title)); - SupportsKey key(mDocument); + nsISupportsKey key(mDocument); nsVoidArray* sheetMap = (nsVoidArray*)mSheetMapTable.Get(&key); if (! sheetMap) { sheetMap = new nsVoidArray(); @@ -1153,7 +1111,7 @@ CSSLoaderImpl::InsertChildSheet(nsICSSStyleSheet* aSheet, nsICSSStyleSheet* aPar return NS_ERROR_NULL_POINTER; } - SupportsKey key(aParentSheet); + nsISupportsKey key(aParentSheet); nsVoidArray* sheetMap = (nsVoidArray*)mSheetMapTable.Get(&key); if (! sheetMap) { sheetMap = new nsVoidArray(); diff --git a/mozilla/content/html/style/src/nsCSSStyleSheet.cpp b/mozilla/content/html/style/src/nsCSSStyleSheet.cpp index ca56d1b8166..f06ad1af824 100644 --- a/mozilla/content/html/style/src/nsCSSStyleSheet.cpp +++ b/mozilla/content/html/style/src/nsCSSStyleSheet.cpp @@ -86,7 +86,7 @@ public: AtomKey(nsIAtom* aAtom); AtomKey(const AtomKey& aKey); virtual ~AtomKey(void); - virtual PRUint32 HashValue(void) const; + virtual PRUint32 HashCode(void) const; virtual PRBool Equals(const nsHashKey *aKey) const; virtual nsHashKey *Clone(void) const; nsIAtom* mAtom; @@ -109,7 +109,7 @@ AtomKey::~AtomKey(void) NS_RELEASE(mAtom); } -PRUint32 AtomKey::HashValue(void) const +PRUint32 AtomKey::HashCode(void) const { return (PRUint32)mAtom; } diff --git a/mozilla/content/html/style/src/nsHTMLStyleSheet.cpp b/mozilla/content/html/style/src/nsHTMLStyleSheet.cpp index eb711bcfe9f..c877aa8dec0 100644 --- a/mozilla/content/html/style/src/nsHTMLStyleSheet.cpp +++ b/mozilla/content/html/style/src/nsHTMLStyleSheet.cpp @@ -497,7 +497,7 @@ public: virtual ~AttributeKey(void); PRBool Equals(const nsHashKey* aOther) const; - PRUint32 HashValue(void) const; + PRUint32 HashCode(void) const; nsHashKey* Clone(void) const; private: @@ -540,7 +540,7 @@ PRBool AttributeKey::Equals(const nsHashKey* aOther) const return equals; } -PRUint32 AttributeKey::HashValue(void) const +PRUint32 AttributeKey::HashCode(void) const { if (0 == mHash.mBits.mHashSet) { AttributeKey* self = (AttributeKey*)this; // break const diff --git a/mozilla/content/html/style/src/nsHTMLValue.cpp b/mozilla/content/html/style/src/nsHTMLValue.cpp index 0e8d718f982..d52454acfe7 100644 --- a/mozilla/content/html/style/src/nsHTMLValue.cpp +++ b/mozilla/content/html/style/src/nsHTMLValue.cpp @@ -178,7 +178,7 @@ PRUint32 nsHTMLValue::HashValue(void) const return PRUint32(mUnit) ^ ((((eHTMLUnit_String == mUnit) || (eHTMLUnit_ColorName == mUnit)) && (nsnull != mValue.mString)) ? - nsCRT::HashValue(mValue.mString) : + nsCRT::HashCode(mValue.mString, nsCRT::strlen(mValue.mString)) : mValue.mInt); } diff --git a/mozilla/content/shared/src/nsHTMLValue.cpp b/mozilla/content/shared/src/nsHTMLValue.cpp index 0e8d718f982..d52454acfe7 100644 --- a/mozilla/content/shared/src/nsHTMLValue.cpp +++ b/mozilla/content/shared/src/nsHTMLValue.cpp @@ -178,7 +178,7 @@ PRUint32 nsHTMLValue::HashValue(void) const return PRUint32(mUnit) ^ ((((eHTMLUnit_String == mUnit) || (eHTMLUnit_ColorName == mUnit)) && (nsnull != mValue.mString)) ? - nsCRT::HashValue(mValue.mString) : + nsCRT::HashCode(mValue.mString, nsCRT::strlen(mValue.mString)) : mValue.mInt); } diff --git a/mozilla/content/xbl/src/nsBindingManager.cpp b/mozilla/content/xbl/src/nsBindingManager.cpp index d5d7e20e9cb..39e4a91ef5c 100644 --- a/mozilla/content/xbl/src/nsBindingManager.cpp +++ b/mozilla/content/xbl/src/nsBindingManager.cpp @@ -303,7 +303,7 @@ nsBindingManager::PutXBLDocument(nsIDocument* aDocument) char* aString; uri->GetSpec(&aString); - nsStringKey key(aString); + nsCStringKey key(aString); mDocumentTable->Put(&key, aDocument); return NS_OK; @@ -316,7 +316,7 @@ nsBindingManager::GetXBLDocument(const nsCString& aURL, nsIDocument** aResult) if (!mDocumentTable) return NS_OK; - nsStringKey key(aURL); + nsCStringKey key(aURL); *aResult = NS_STATIC_CAST(nsIDocument*, mDocumentTable->Get(&key)); // Addref happens here. return NS_OK; } @@ -327,7 +327,7 @@ nsBindingManager::PutLoadingDocListener(const nsCString& aURL, nsIStreamListener if (!mLoadingDocTable) mLoadingDocTable = new nsSupportsHashtable(); - nsStringKey key(aURL); + nsCStringKey key(aURL); mLoadingDocTable->Put(&key, aListener); return NS_OK; @@ -340,7 +340,7 @@ nsBindingManager::GetLoadingDocListener(const nsCString& aURL, nsIStreamListener if (!mLoadingDocTable) return NS_OK; - nsStringKey key(aURL); + nsCStringKey key(aURL); *aResult = NS_STATIC_CAST(nsIStreamListener*, mLoadingDocTable->Get(&key)); // Addref happens here. return NS_OK; } @@ -351,7 +351,7 @@ nsBindingManager::RemoveLoadingDocListener(const nsCString& aURL) if (!mLoadingDocTable) return NS_OK; - nsStringKey key(aURL); + nsCStringKey key(aURL); mLoadingDocTable->Remove(&key); return NS_OK; diff --git a/mozilla/content/xbl/src/nsXBLBinding.cpp b/mozilla/content/xbl/src/nsXBLBinding.cpp index 25b1a9105a5..481f524e0f4 100644 --- a/mozilla/content/xbl/src/nsXBLBinding.cpp +++ b/mozilla/content/xbl/src/nsXBLBinding.cpp @@ -141,7 +141,7 @@ nsXBLJSClass::Destroy() "referenced nsXBLJSClass is on LRU list already!?"); if (nsXBLService::gClassTable) { - nsStringKey key(name); + nsCStringKey key(name); (nsXBLService::gClassTable)->Remove(&key); } @@ -1147,7 +1147,7 @@ nsXBLBinding::InitClass(const nsCString& aClassName, nsIScriptContext* aContext, nsXBLJSClass* c; void* classObject; - nsStringKey key(aClassName); + nsCStringKey key(aClassName); classObject = (nsXBLService::gClassTable)->Get(&key); if (classObject) { @@ -1173,7 +1173,7 @@ nsXBLBinding::InitClass(const nsCString& aClassName, nsIScriptContext* aContext, // Remove any mapping from the old name to the class struct. c = NS_STATIC_CAST(nsXBLJSClass*, lru); - nsStringKey oldKey(c->name); + nsCStringKey oldKey(c->name); (nsXBLService::gClassTable)->Remove(&oldKey); // Change the class name and we're done. diff --git a/mozilla/content/xbl/src/nsXBLService.cpp b/mozilla/content/xbl/src/nsXBLService.cpp index 6f8ada0087c..5407bcc6842 100644 --- a/mozilla/content/xbl/src/nsXBLService.cpp +++ b/mozilla/content/xbl/src/nsXBLService.cpp @@ -747,7 +747,7 @@ nsXBLService::GetBindingDocument(nsIContent* aBoundElement, const nsCString& aUR *aResult = nsnull; // We've got a file. Check our XBL document cache. - nsStringKey key(aURLStr); + nsCStringKey key(aURLStr); nsCOMPtr document; if (gXULUtils->UseXULCache()) { // The first line of defense is the chrome cache. diff --git a/mozilla/content/xul/document/src/nsXULPrototypeCache.cpp b/mozilla/content/xul/document/src/nsXULPrototypeCache.cpp index 128cddfe4ff..b32f9c9b0f2 100644 --- a/mozilla/content/xul/document/src/nsXULPrototypeCache.cpp +++ b/mozilla/content/xul/document/src/nsXULPrototypeCache.cpp @@ -84,7 +84,7 @@ protected: nsIURIKey(nsIURI* key) : mKey(key) {} ~nsIURIKey(void) {} - PRUint32 HashValue(void) const { + PRUint32 HashCode(void) const { nsXPIDLCString spec; mKey->GetSpec(getter_Copies(spec)); return (PRUint32) PL_HashString(spec); @@ -201,7 +201,7 @@ nsXULPrototypeCache::PutStyleSheet(nsICSSStyleSheet* aStyleSheet) NS_IMETHODIMP nsXULPrototypeCache::GetXBLDocument(const nsCString& aString, nsIDocument** _result) { - nsStringKey key(aString); + nsCStringKey key(aString); *_result = NS_STATIC_CAST(nsIDocument*, mXBLDocTable.Get(&key)); return NS_OK; } @@ -213,7 +213,7 @@ nsXULPrototypeCache::PutXBLDocument(nsIDocument *aDocument) nsXPIDLCString str; uri->GetSpec(getter_Copies(str)); - nsStringKey key((const char*)str); + nsCStringKey key((const char*)str); mXBLDocTable.Put(&key, aDocument); return NS_OK; @@ -222,7 +222,7 @@ nsXULPrototypeCache::PutXBLDocument(nsIDocument *aDocument) NS_IMETHODIMP nsXULPrototypeCache::GetXBLDocScriptAccess(const nsCString& aString, nsIDocument** _result) { - nsStringKey key(aString); + nsCStringKey key(aString); *_result = NS_STATIC_CAST(nsIDocument*, mScriptAccessTable.Get(&key)); return NS_OK; } @@ -234,7 +234,7 @@ nsXULPrototypeCache::PutXBLDocScriptAccess(nsIDocument *aDocument) nsXPIDLCString str; uri->GetSpec(getter_Copies(str)); - nsStringKey key((const char*)str); + nsCStringKey key((const char*)str); mScriptAccessTable.Put(&key, aDocument); return NS_OK; diff --git a/mozilla/gfx/src/mac/nsDeviceContextMac.cpp b/mozilla/gfx/src/mac/nsDeviceContextMac.cpp index cd98235b23b..82acafb591a 100644 --- a/mozilla/gfx/src/mac/nsDeviceContextMac.cpp +++ b/mozilla/gfx/src/mac/nsDeviceContextMac.cpp @@ -751,7 +751,7 @@ class FontNameKey : public nsHashKey public: FontNameKey(const nsString& aString); - virtual PRUint32 HashValue(void) const; + virtual PRUint32 HashCode(void) const; virtual PRBool Equals(const nsHashKey *aKey) const; virtual nsHashKey *Clone(void) const; @@ -763,11 +763,11 @@ FontNameKey::FontNameKey(const nsString& aString) mString.Assign(aString); } -PRUint32 FontNameKey::HashValue(void) const +PRUint32 FontNameKey::HashCode(void) const { nsString str; mString.ToLowerCase(str); - return nsCRT::HashValue(str.GetUnicode()); + return nsCRT::HashCode(str.GetUnicode(), str.Length()); } PRBool FontNameKey::Equals(const nsHashKey *aKey) const diff --git a/mozilla/gfx/src/mac/nsUnicodeFontMappingCache.h b/mozilla/gfx/src/mac/nsUnicodeFontMappingCache.h index 401e7620e82..c9af8bf8fc7 100644 --- a/mozilla/gfx/src/mac/nsUnicodeFontMappingCache.h +++ b/mozilla/gfx/src/mac/nsUnicodeFontMappingCache.h @@ -65,8 +65,8 @@ public: private: inline static PR_CALLBACK PLHashNumber HashKey(const void *aKey) { - PRUint32 uslen; - return nsCRT::HashValue(((nsString*)aKey)->GetUnicode(), &uslen); + nsString* key = (nsString*)aKey; + return nsCRT::HashCode(key->GetUnicode(), key->Length()); }; inline static PR_CALLBACK PRIntn CompareKeys(const void *v1, const void *v2) { diff --git a/mozilla/gfx/src/nsDeviceContext.cpp b/mozilla/gfx/src/nsDeviceContext.cpp index ac619757bbe..e240174c80f 100644 --- a/mozilla/gfx/src/nsDeviceContext.cpp +++ b/mozilla/gfx/src/nsDeviceContext.cpp @@ -507,14 +507,14 @@ public: FontAliasKey(const nsString& aString) {mString.Assign(aString);} - virtual PRUint32 HashValue(void) const; + virtual PRUint32 HashCode(void) const; virtual PRBool Equals(const nsHashKey *aKey) const; virtual nsHashKey *Clone(void) const; nsAutoString mString; }; -PRUint32 FontAliasKey::HashValue(void) const +PRUint32 FontAliasKey::HashCode(void) const { PRUint32 hash = 0; const PRUnichar* string = mString.GetUnicode(); diff --git a/mozilla/gfx/src/photon/nsFontMetricsPh.cpp b/mozilla/gfx/src/photon/nsFontMetricsPh.cpp index 6c7f0292407..4b67ccfcd6c 100644 --- a/mozilla/gfx/src/photon/nsFontMetricsPh.cpp +++ b/mozilla/gfx/src/photon/nsFontMetricsPh.cpp @@ -564,8 +564,9 @@ NS_IMPL_ISUPPORTS(nsFontEnumeratorPh, NS_GET_IID(nsIFontEnumerator)); static int gInitializedFontEnumerator = 0; static PLHashNumber HashKey(const void* aString) { + const nsString* key = (const nsString*) aString; return (PLHashNumber) - nsCRT::HashValue(((const nsString*) aString)->GetUnicode()); + nsCRT::HashCode(key->GetUnicode(), key->Length()); } static PRIntn diff --git a/mozilla/gfx/src/windows/nsFontMetricsWin.cpp b/mozilla/gfx/src/windows/nsFontMetricsWin.cpp index 0462b3c1578..b3b81413669 100644 --- a/mozilla/gfx/src/windows/nsFontMetricsWin.cpp +++ b/mozilla/gfx/src/windows/nsFontMetricsWin.cpp @@ -452,8 +452,9 @@ GetNAME(HDC aDC, nsString* aName) static PLHashNumber HashKey(const void* aString) { + const nsString* str = (const nsString*)aString; return (PLHashNumber) - nsCRT::HashValue(((const nsString*) aString)->GetUnicode()); + nsCRT::HashCode(str->GetUnicode(), str->Length()); } static PRIntn @@ -2112,7 +2113,7 @@ HashKeyFontWeight(const void* aFontWeightEntry) { const nsString* string = &((const nsFontWeightEntry*) aFontWeightEntry)->mFontName; return (PLHashNumber) - nsCRT::HashValue(string->GetUnicode()); + nsCRT::HashCode(string->GetUnicode(), string->Length()); } static PRIntn diff --git a/mozilla/gfx/src/xlib/nsFontMetricsXlib.cpp b/mozilla/gfx/src/xlib/nsFontMetricsXlib.cpp index 47ffaf6b0a9..2c80aebaf35 100644 --- a/mozilla/gfx/src/xlib/nsFontMetricsXlib.cpp +++ b/mozilla/gfx/src/xlib/nsFontMetricsXlib.cpp @@ -1297,8 +1297,9 @@ DumpTree(void) static PLHashNumber HashKey(const void* aString) { + const nsString* key = (const nsString*) aString; return (PLHashNumber) - nsCRT::HashValue(((const nsString*) aString)->GetUnicode()); + nsCRT::HashCode(key->GetUnicode(), key->Length()); } static PRIntn diff --git a/mozilla/gfx/src/xprint/nsFontMetricsXP.cpp b/mozilla/gfx/src/xprint/nsFontMetricsXP.cpp index 933d29e6986..5b3d03d96e6 100644 --- a/mozilla/gfx/src/xprint/nsFontMetricsXP.cpp +++ b/mozilla/gfx/src/xprint/nsFontMetricsXP.cpp @@ -1211,8 +1211,9 @@ DumpTree(void) static PLHashNumber HashKey(const void* aString) { + const nsString* key = (const nsString*) aString; return (PLHashNumber) - nsCRT::HashValue(((const nsString*) aString)->GetUnicode()); + nsCRT::HashCode(key->GetUnicode(), key->Length()); } static PRIntn diff --git a/mozilla/intl/strres/src/nsStringBundle.cpp b/mozilla/intl/strres/src/nsStringBundle.cpp index d489e1165e9..5ed3546cb16 100644 --- a/mozilla/intl/strres/src/nsStringBundle.cpp +++ b/mozilla/intl/strres/src/nsStringBundle.cpp @@ -642,7 +642,7 @@ nsresult nsExtensibleStringBundle::GetSimpleEnumeration(nsISimpleEnumerator ** a struct bundleCacheEntry_t { PRCList list; - nsStringKey *mHashKey; + nsCStringKey *mHashKey; // do not use a nsCOMPtr - this is a struct not a class! nsIStringBundle* mBundle; }; @@ -668,7 +668,7 @@ private: void flushBundleCache(); bundleCacheEntry_t *insertIntoCache(nsIStringBundle *aBundle, - nsStringKey *aHashKey); + nsCStringKey *aHashKey); static void recycleEntry(bundleCacheEntry_t*); @@ -757,7 +757,7 @@ nsStringBundleService::getStringBundle(const char *aURLSpec, nsXPIDLCString newSpec; - nsStringKey completeKey(aURLSpec); + nsCStringKey completeKey(aURLSpec); bundleCacheEntry_t* cacheEntry = (bundleCacheEntry_t*)mBundleMap.Get(&completeKey); @@ -794,7 +794,7 @@ nsStringBundleService::getStringBundle(const char *aURLSpec, bundleCacheEntry_t * nsStringBundleService::insertIntoCache(nsIStringBundle* aBundle, - nsStringKey* aHashKey) + nsCStringKey* aHashKey) { bundleCacheEntry_t *cacheEntry; @@ -825,7 +825,7 @@ nsStringBundleService::insertIntoCache(nsIStringBundle* aBundle, cacheEntry->mBundle = aBundle; NS_ADDREF(cacheEntry->mBundle); - cacheEntry->mHashKey = (nsStringKey*)aHashKey->Clone(); + cacheEntry->mHashKey = (nsCStringKey*)aHashKey->Clone(); // insert the entry into the cache and map, make it the MRU mBundleMap.Put(cacheEntry->mHashKey, cacheEntry); diff --git a/mozilla/layout/base/nsCSSFrameConstructor.cpp b/mozilla/layout/base/nsCSSFrameConstructor.cpp index 65411eac413..ab1ea8537fe 100644 --- a/mozilla/layout/base/nsCSSFrameConstructor.cpp +++ b/mozilla/layout/base/nsCSSFrameConstructor.cpp @@ -6196,7 +6196,7 @@ nsCSSFrameConstructor::ConstructXULFrame(nsIPresShell* aPresShell, } } - addToHashTable: +// addToHashTable: if (topFrame) { // the top frame is always what we map the content to. This is the frame that contains a pointer diff --git a/mozilla/layout/base/nsLayoutHistoryState.cpp b/mozilla/layout/base/nsLayoutHistoryState.cpp index 1a137ce384e..f64d0e91e09 100644 --- a/mozilla/layout/base/nsLayoutHistoryState.cpp +++ b/mozilla/layout/base/nsLayoutHistoryState.cpp @@ -27,34 +27,14 @@ MOZ_DECL_CTOR_COUNTER(HistoryKey); -class HistoryKey: public nsHashKey { - private: - PRUint32 itsHash; - +class HistoryKey: public nsVoidKey { public: - HistoryKey(PRUint32 aContentID, nsIStatefulFrame::StateType aStateType) { - MOZ_COUNT_CTOR(HistoryKey); - itsHash = aContentID * nsIStatefulFrame::eNumStateTypes + aStateType; + HistoryKey(PRUint32 aContentID, nsIStatefulFrame::StateType aStateType) + : nsVoidKey((void*)(aContentID * nsIStatefulFrame::eNumStateTypes + aStateType)) { } - HistoryKey(PRUint32 aKey) { - MOZ_COUNT_CTOR(HistoryKey); - itsHash = aKey; - } - ~HistoryKey() { - MOZ_COUNT_DTOR(HistoryKey); - } - - PRUint32 HashValue(void) const { - return itsHash; - } - - PRBool Equals(const nsHashKey *aKey) const { - return (itsHash == (((const HistoryKey *) aKey)->HashValue())) ? PR_TRUE : PR_FALSE; - } - - nsHashKey *Clone(void) const { - return new HistoryKey(itsHash); + HistoryKey(PRUint32 aKey) + : nsVoidKey((void*)aKey) { } }; diff --git a/mozilla/layout/base/src/nsLayoutHistoryState.cpp b/mozilla/layout/base/src/nsLayoutHistoryState.cpp index 1a137ce384e..f64d0e91e09 100644 --- a/mozilla/layout/base/src/nsLayoutHistoryState.cpp +++ b/mozilla/layout/base/src/nsLayoutHistoryState.cpp @@ -27,34 +27,14 @@ MOZ_DECL_CTOR_COUNTER(HistoryKey); -class HistoryKey: public nsHashKey { - private: - PRUint32 itsHash; - +class HistoryKey: public nsVoidKey { public: - HistoryKey(PRUint32 aContentID, nsIStatefulFrame::StateType aStateType) { - MOZ_COUNT_CTOR(HistoryKey); - itsHash = aContentID * nsIStatefulFrame::eNumStateTypes + aStateType; + HistoryKey(PRUint32 aContentID, nsIStatefulFrame::StateType aStateType) + : nsVoidKey((void*)(aContentID * nsIStatefulFrame::eNumStateTypes + aStateType)) { } - HistoryKey(PRUint32 aKey) { - MOZ_COUNT_CTOR(HistoryKey); - itsHash = aKey; - } - ~HistoryKey() { - MOZ_COUNT_DTOR(HistoryKey); - } - - PRUint32 HashValue(void) const { - return itsHash; - } - - PRBool Equals(const nsHashKey *aKey) const { - return (itsHash == (((const HistoryKey *) aKey)->HashValue())) ? PR_TRUE : PR_FALSE; - } - - nsHashKey *Clone(void) const { - return new HistoryKey(itsHash); + HistoryKey(PRUint32 aKey) + : nsVoidKey((void*)aKey) { } }; diff --git a/mozilla/layout/base/src/nsNameSpaceManager.cpp b/mozilla/layout/base/src/nsNameSpaceManager.cpp index a3fad0a4429..34844cf646d 100644 --- a/mozilla/layout/base/src/nsNameSpaceManager.cpp +++ b/mozilla/layout/base/src/nsNameSpaceManager.cpp @@ -47,59 +47,6 @@ static nsVoidArray* gURIArray; MOZ_DECL_CTOR_COUNTER(NameSpaceURIKey); -class NameSpaceURIKey : public nsHashKey { -public: - NameSpaceURIKey(const nsString* aString) - : mString(aString) - { - MOZ_COUNT_CTOR(NameSpaceURIKey); - } - - virtual ~NameSpaceURIKey(void) - { - MOZ_COUNT_DTOR(NameSpaceURIKey); - } - - virtual PRUint32 HashValue(void) const - { -#if 1 // case insensitive XXX should this be case sensitive??? - PRUint32 hash = 0; - const PRUnichar* string = mString->GetUnicode(); - PRUnichar ch; - while ((ch = *string++) != 0) { - // FYI: hash = hash*37 + ch - ch = nsCRT::ToLower(ch); - hash = ((hash << 5) + (hash << 2) + hash) + ch; - } - return hash; -#else - if (nsnull != mString) { - return nsCRT::HashValue(mString->GetUnicode()); - } - return 0; -#endif - } - - virtual PRBool Equals(const nsHashKey *aKey) const - { - const nsString* other = ((const NameSpaceURIKey*)aKey)->mString; - if (nsnull != mString) { - if (nsnull != other) { - return mString->EqualsIgnoreCase(*other); // XXX case sensitive? - } - return PR_FALSE; - } - return PRBool(nsnull == other); - } - - virtual nsHashKey *Clone(void) const - { - return new NameSpaceURIKey(mString); - } - - const nsString* mString; -}; - static void AddRefTable() { if (0 == gNameSpaceTableRefs++) { @@ -119,11 +66,11 @@ static void AddRefTable() gURIArray->AppendElement(xhtml); gURIArray->AppendElement(xlink); gURIArray->AppendElement(html); - NameSpaceURIKey xmlnsKey(xmlns); - NameSpaceURIKey xmlKey(xml); - NameSpaceURIKey xhtmlKey(xhtml); - NameSpaceURIKey xlinkKey(xlink); - NameSpaceURIKey htmlKey(html); + nsStringKey xmlnsKey(*xmlns); + nsStringKey xmlKey(*xml); + nsStringKey xhtmlKey(*xhtml); + nsStringKey xlinkKey(*xlink); + nsStringKey htmlKey(*html); gURIToIDTable->Put(&xmlnsKey, (void*)kNameSpaceID_XMLNS); gURIToIDTable->Put(&xmlKey, (void*)kNameSpaceID_XML); gURIToIDTable->Put(&xhtmlKey, (void*)kNameSpaceID_HTML); @@ -152,7 +99,7 @@ static void ReleaseTable() static PRInt32 FindNameSpaceID(const nsString& aURI) { NS_ASSERTION(nsnull != gURIToIDTable, "no URI table"); - NameSpaceURIKey key(&aURI); + nsStringKey key(aURI); void* value = gURIToIDTable->Get(&key); if (nsnull != value) { return PRInt32(value); @@ -446,7 +393,7 @@ NameSpaceManagerImpl::RegisterNameSpace(const nsString& aURI, nsString* uri = new nsString(aURI); gURIArray->AppendElement(uri); id = gURIArray->Count(); // id is index + 1 - NameSpaceURIKey key(uri); + nsStringKey key(*uri); gURIToIDTable->Put(&key, (void*)id); } aNameSpaceID = id; diff --git a/mozilla/layout/html/content/src/nsHTMLFormElement.cpp b/mozilla/layout/html/content/src/nsHTMLFormElement.cpp index fb8d0f092a3..6a45030f4f8 100644 --- a/mozilla/layout/html/content/src/nsHTMLFormElement.cpp +++ b/mozilla/layout/html/content/src/nsHTMLFormElement.cpp @@ -851,7 +851,8 @@ nsFormControlList::GetNamedObject(JSContext* aContext, jsval aID, JSObject** aOb if (mLookupTable) { // Get the hash entry - nsStringKey key(str); + nsString ustr; ustr.AssignWithConversion(str); + nsStringKey key(ustr); nsCOMPtr tmp = dont_AddRef((nsISupports *)mLookupTable->Get(&key)); diff --git a/mozilla/layout/html/style/src/nsCSSFrameConstructor.cpp b/mozilla/layout/html/style/src/nsCSSFrameConstructor.cpp index 65411eac413..ab1ea8537fe 100644 --- a/mozilla/layout/html/style/src/nsCSSFrameConstructor.cpp +++ b/mozilla/layout/html/style/src/nsCSSFrameConstructor.cpp @@ -6196,7 +6196,7 @@ nsCSSFrameConstructor::ConstructXULFrame(nsIPresShell* aPresShell, } } - addToHashTable: +// addToHashTable: if (topFrame) { // the top frame is always what we map the content to. This is the frame that contains a pointer diff --git a/mozilla/layout/html/style/src/nsCSSLoader.cpp b/mozilla/layout/html/style/src/nsCSSLoader.cpp index f2e98c6b0f3..d9344c7cc8d 100644 --- a/mozilla/layout/html/style/src/nsCSSLoader.cpp +++ b/mozilla/layout/html/style/src/nsCSSLoader.cpp @@ -84,7 +84,7 @@ public: char* urlStr; mURL->GetSpec(&urlStr); if (urlStr) { - mHashValue = nsCRT::HashValue(urlStr); + mHashValue = nsCRT::HashCode(urlStr, nsCRT::strlen(urlStr)); nsCRT::free(urlStr); } } @@ -104,7 +104,7 @@ public: NS_RELEASE(mURL); } - virtual PRUint32 HashValue(void) const + virtual PRUint32 HashCode(void) const { return mHashValue; } @@ -126,48 +126,6 @@ public: PRUint32 mHashValue; }; -MOZ_DECL_CTOR_COUNTER(SupportsKey); - -class SupportsKey: public nsHashKey { -public: - SupportsKey(nsISupports* aSupports) - : nsHashKey(), - mSupports(aSupports) - { // note: does not hold reference on supports pointer - MOZ_COUNT_CTOR(SupportsKey); - } - - SupportsKey(const SupportsKey& aKey) - : nsHashKey(), - mSupports(aKey.mSupports) - { - MOZ_COUNT_CTOR(SupportsKey); - } - - virtual ~SupportsKey(void) - { - MOZ_COUNT_DTOR(SupportsKey); - } - - virtual PRUint32 HashValue(void) const - { - return (PRUint32)mSupports; - } - - virtual PRBool Equals(const nsHashKey* aKey) const - { - SupportsKey* key = (SupportsKey*)aKey; - return PRBool(mSupports == key->mSupports); - } - - virtual nsHashKey *Clone(void) const - { - return new SupportsKey(*this); - } - - nsISupports* mSupports; -}; - class SheetLoadData : public nsIStreamLoaderObserver { public: @@ -1113,7 +1071,7 @@ CSSLoaderImpl::InsertSheetInDoc(nsICSSStyleSheet* aSheet, PRInt32 aDocIndex, aSheet->GetTitle(title); aSheet->SetEnabled(! IsAlternate(title)); - SupportsKey key(mDocument); + nsISupportsKey key(mDocument); nsVoidArray* sheetMap = (nsVoidArray*)mSheetMapTable.Get(&key); if (! sheetMap) { sheetMap = new nsVoidArray(); @@ -1153,7 +1111,7 @@ CSSLoaderImpl::InsertChildSheet(nsICSSStyleSheet* aSheet, nsICSSStyleSheet* aPar return NS_ERROR_NULL_POINTER; } - SupportsKey key(aParentSheet); + nsISupportsKey key(aParentSheet); nsVoidArray* sheetMap = (nsVoidArray*)mSheetMapTable.Get(&key); if (! sheetMap) { sheetMap = new nsVoidArray(); diff --git a/mozilla/layout/html/style/src/nsCSSStyleSheet.cpp b/mozilla/layout/html/style/src/nsCSSStyleSheet.cpp index ca56d1b8166..f06ad1af824 100644 --- a/mozilla/layout/html/style/src/nsCSSStyleSheet.cpp +++ b/mozilla/layout/html/style/src/nsCSSStyleSheet.cpp @@ -86,7 +86,7 @@ public: AtomKey(nsIAtom* aAtom); AtomKey(const AtomKey& aKey); virtual ~AtomKey(void); - virtual PRUint32 HashValue(void) const; + virtual PRUint32 HashCode(void) const; virtual PRBool Equals(const nsHashKey *aKey) const; virtual nsHashKey *Clone(void) const; nsIAtom* mAtom; @@ -109,7 +109,7 @@ AtomKey::~AtomKey(void) NS_RELEASE(mAtom); } -PRUint32 AtomKey::HashValue(void) const +PRUint32 AtomKey::HashCode(void) const { return (PRUint32)mAtom; } diff --git a/mozilla/layout/html/style/src/nsHTMLStyleSheet.cpp b/mozilla/layout/html/style/src/nsHTMLStyleSheet.cpp index eb711bcfe9f..c877aa8dec0 100644 --- a/mozilla/layout/html/style/src/nsHTMLStyleSheet.cpp +++ b/mozilla/layout/html/style/src/nsHTMLStyleSheet.cpp @@ -497,7 +497,7 @@ public: virtual ~AttributeKey(void); PRBool Equals(const nsHashKey* aOther) const; - PRUint32 HashValue(void) const; + PRUint32 HashCode(void) const; nsHashKey* Clone(void) const; private: @@ -540,7 +540,7 @@ PRBool AttributeKey::Equals(const nsHashKey* aOther) const return equals; } -PRUint32 AttributeKey::HashValue(void) const +PRUint32 AttributeKey::HashCode(void) const { if (0 == mHash.mBits.mHashSet) { AttributeKey* self = (AttributeKey*)this; // break const diff --git a/mozilla/layout/html/style/src/nsHTMLValue.cpp b/mozilla/layout/html/style/src/nsHTMLValue.cpp index 0e8d718f982..d52454acfe7 100644 --- a/mozilla/layout/html/style/src/nsHTMLValue.cpp +++ b/mozilla/layout/html/style/src/nsHTMLValue.cpp @@ -178,7 +178,7 @@ PRUint32 nsHTMLValue::HashValue(void) const return PRUint32(mUnit) ^ ((((eHTMLUnit_String == mUnit) || (eHTMLUnit_ColorName == mUnit)) && (nsnull != mValue.mString)) ? - nsCRT::HashValue(mValue.mString) : + nsCRT::HashCode(mValue.mString, nsCRT::strlen(mValue.mString)) : mValue.mInt); } diff --git a/mozilla/layout/style/nsCSSLoader.cpp b/mozilla/layout/style/nsCSSLoader.cpp index f2e98c6b0f3..d9344c7cc8d 100644 --- a/mozilla/layout/style/nsCSSLoader.cpp +++ b/mozilla/layout/style/nsCSSLoader.cpp @@ -84,7 +84,7 @@ public: char* urlStr; mURL->GetSpec(&urlStr); if (urlStr) { - mHashValue = nsCRT::HashValue(urlStr); + mHashValue = nsCRT::HashCode(urlStr, nsCRT::strlen(urlStr)); nsCRT::free(urlStr); } } @@ -104,7 +104,7 @@ public: NS_RELEASE(mURL); } - virtual PRUint32 HashValue(void) const + virtual PRUint32 HashCode(void) const { return mHashValue; } @@ -126,48 +126,6 @@ public: PRUint32 mHashValue; }; -MOZ_DECL_CTOR_COUNTER(SupportsKey); - -class SupportsKey: public nsHashKey { -public: - SupportsKey(nsISupports* aSupports) - : nsHashKey(), - mSupports(aSupports) - { // note: does not hold reference on supports pointer - MOZ_COUNT_CTOR(SupportsKey); - } - - SupportsKey(const SupportsKey& aKey) - : nsHashKey(), - mSupports(aKey.mSupports) - { - MOZ_COUNT_CTOR(SupportsKey); - } - - virtual ~SupportsKey(void) - { - MOZ_COUNT_DTOR(SupportsKey); - } - - virtual PRUint32 HashValue(void) const - { - return (PRUint32)mSupports; - } - - virtual PRBool Equals(const nsHashKey* aKey) const - { - SupportsKey* key = (SupportsKey*)aKey; - return PRBool(mSupports == key->mSupports); - } - - virtual nsHashKey *Clone(void) const - { - return new SupportsKey(*this); - } - - nsISupports* mSupports; -}; - class SheetLoadData : public nsIStreamLoaderObserver { public: @@ -1113,7 +1071,7 @@ CSSLoaderImpl::InsertSheetInDoc(nsICSSStyleSheet* aSheet, PRInt32 aDocIndex, aSheet->GetTitle(title); aSheet->SetEnabled(! IsAlternate(title)); - SupportsKey key(mDocument); + nsISupportsKey key(mDocument); nsVoidArray* sheetMap = (nsVoidArray*)mSheetMapTable.Get(&key); if (! sheetMap) { sheetMap = new nsVoidArray(); @@ -1153,7 +1111,7 @@ CSSLoaderImpl::InsertChildSheet(nsICSSStyleSheet* aSheet, nsICSSStyleSheet* aPar return NS_ERROR_NULL_POINTER; } - SupportsKey key(aParentSheet); + nsISupportsKey key(aParentSheet); nsVoidArray* sheetMap = (nsVoidArray*)mSheetMapTable.Get(&key); if (! sheetMap) { sheetMap = new nsVoidArray(); diff --git a/mozilla/layout/style/nsCSSStyleSheet.cpp b/mozilla/layout/style/nsCSSStyleSheet.cpp index ca56d1b8166..f06ad1af824 100644 --- a/mozilla/layout/style/nsCSSStyleSheet.cpp +++ b/mozilla/layout/style/nsCSSStyleSheet.cpp @@ -86,7 +86,7 @@ public: AtomKey(nsIAtom* aAtom); AtomKey(const AtomKey& aKey); virtual ~AtomKey(void); - virtual PRUint32 HashValue(void) const; + virtual PRUint32 HashCode(void) const; virtual PRBool Equals(const nsHashKey *aKey) const; virtual nsHashKey *Clone(void) const; nsIAtom* mAtom; @@ -109,7 +109,7 @@ AtomKey::~AtomKey(void) NS_RELEASE(mAtom); } -PRUint32 AtomKey::HashValue(void) const +PRUint32 AtomKey::HashCode(void) const { return (PRUint32)mAtom; } diff --git a/mozilla/layout/style/nsHTMLStyleSheet.cpp b/mozilla/layout/style/nsHTMLStyleSheet.cpp index eb711bcfe9f..c877aa8dec0 100644 --- a/mozilla/layout/style/nsHTMLStyleSheet.cpp +++ b/mozilla/layout/style/nsHTMLStyleSheet.cpp @@ -497,7 +497,7 @@ public: virtual ~AttributeKey(void); PRBool Equals(const nsHashKey* aOther) const; - PRUint32 HashValue(void) const; + PRUint32 HashCode(void) const; nsHashKey* Clone(void) const; private: @@ -540,7 +540,7 @@ PRBool AttributeKey::Equals(const nsHashKey* aOther) const return equals; } -PRUint32 AttributeKey::HashValue(void) const +PRUint32 AttributeKey::HashCode(void) const { if (0 == mHash.mBits.mHashSet) { AttributeKey* self = (AttributeKey*)this; // break const diff --git a/mozilla/layout/xbl/src/nsBindingManager.cpp b/mozilla/layout/xbl/src/nsBindingManager.cpp index d5d7e20e9cb..39e4a91ef5c 100644 --- a/mozilla/layout/xbl/src/nsBindingManager.cpp +++ b/mozilla/layout/xbl/src/nsBindingManager.cpp @@ -303,7 +303,7 @@ nsBindingManager::PutXBLDocument(nsIDocument* aDocument) char* aString; uri->GetSpec(&aString); - nsStringKey key(aString); + nsCStringKey key(aString); mDocumentTable->Put(&key, aDocument); return NS_OK; @@ -316,7 +316,7 @@ nsBindingManager::GetXBLDocument(const nsCString& aURL, nsIDocument** aResult) if (!mDocumentTable) return NS_OK; - nsStringKey key(aURL); + nsCStringKey key(aURL); *aResult = NS_STATIC_CAST(nsIDocument*, mDocumentTable->Get(&key)); // Addref happens here. return NS_OK; } @@ -327,7 +327,7 @@ nsBindingManager::PutLoadingDocListener(const nsCString& aURL, nsIStreamListener if (!mLoadingDocTable) mLoadingDocTable = new nsSupportsHashtable(); - nsStringKey key(aURL); + nsCStringKey key(aURL); mLoadingDocTable->Put(&key, aListener); return NS_OK; @@ -340,7 +340,7 @@ nsBindingManager::GetLoadingDocListener(const nsCString& aURL, nsIStreamListener if (!mLoadingDocTable) return NS_OK; - nsStringKey key(aURL); + nsCStringKey key(aURL); *aResult = NS_STATIC_CAST(nsIStreamListener*, mLoadingDocTable->Get(&key)); // Addref happens here. return NS_OK; } @@ -351,7 +351,7 @@ nsBindingManager::RemoveLoadingDocListener(const nsCString& aURL) if (!mLoadingDocTable) return NS_OK; - nsStringKey key(aURL); + nsCStringKey key(aURL); mLoadingDocTable->Remove(&key); return NS_OK; diff --git a/mozilla/layout/xbl/src/nsXBLBinding.cpp b/mozilla/layout/xbl/src/nsXBLBinding.cpp index 25b1a9105a5..481f524e0f4 100644 --- a/mozilla/layout/xbl/src/nsXBLBinding.cpp +++ b/mozilla/layout/xbl/src/nsXBLBinding.cpp @@ -141,7 +141,7 @@ nsXBLJSClass::Destroy() "referenced nsXBLJSClass is on LRU list already!?"); if (nsXBLService::gClassTable) { - nsStringKey key(name); + nsCStringKey key(name); (nsXBLService::gClassTable)->Remove(&key); } @@ -1147,7 +1147,7 @@ nsXBLBinding::InitClass(const nsCString& aClassName, nsIScriptContext* aContext, nsXBLJSClass* c; void* classObject; - nsStringKey key(aClassName); + nsCStringKey key(aClassName); classObject = (nsXBLService::gClassTable)->Get(&key); if (classObject) { @@ -1173,7 +1173,7 @@ nsXBLBinding::InitClass(const nsCString& aClassName, nsIScriptContext* aContext, // Remove any mapping from the old name to the class struct. c = NS_STATIC_CAST(nsXBLJSClass*, lru); - nsStringKey oldKey(c->name); + nsCStringKey oldKey(c->name); (nsXBLService::gClassTable)->Remove(&oldKey); // Change the class name and we're done. diff --git a/mozilla/layout/xbl/src/nsXBLService.cpp b/mozilla/layout/xbl/src/nsXBLService.cpp index 6f8ada0087c..5407bcc6842 100644 --- a/mozilla/layout/xbl/src/nsXBLService.cpp +++ b/mozilla/layout/xbl/src/nsXBLService.cpp @@ -747,7 +747,7 @@ nsXBLService::GetBindingDocument(nsIContent* aBoundElement, const nsCString& aUR *aResult = nsnull; // We've got a file. Check our XBL document cache. - nsStringKey key(aURLStr); + nsCStringKey key(aURLStr); nsCOMPtr document; if (gXULUtils->UseXULCache()) { // The first line of defense is the chrome cache. diff --git a/mozilla/mailnews/base/src/nsMsgAccountManager.cpp b/mozilla/mailnews/base/src/nsMsgAccountManager.cpp index 2cfd96227f1..0fdb23dfcc7 100644 --- a/mozilla/mailnews/base/src/nsMsgAccountManager.cpp +++ b/mozilla/mailnews/base/src/nsMsgAccountManager.cpp @@ -250,7 +250,7 @@ nsMsgAccountManager::getUniqueKey(const char* prefix, do { aResult=prefix; aResult.AppendInt(i++); - nsStringKey hashKey(aResult); + nsCStringKey hashKey(aResult); void* hashElement = hashTable->Get(&hashKey); if (!hashElement) unique=PR_TRUE; @@ -310,7 +310,7 @@ nsMsgAccountManager::GetIdentity(const char* key, nsresult rv; // check for the identity in the hash table - nsStringKey hashKey(key); + nsCStringKey hashKey(key); nsISupports *idsupports = (nsISupports*)m_identities.Get(&hashKey); nsCOMPtr identity = do_QueryInterface(idsupports, &rv); @@ -344,7 +344,7 @@ nsMsgAccountManager::createKeyedIdentity(const char* key, identity->SetKey(NS_CONST_CAST(char *,key)); - nsStringKey hashKey(key); + nsCStringKey hashKey(key); // addref for the hash table` nsISupports* idsupports = identity; @@ -381,7 +381,7 @@ nsMsgAccountManager::GetIncomingServer(const char* key, nsresult rv=NS_OK; - nsStringKey hashKey(key); + nsCStringKey hashKey(key); nsCOMPtr server = do_QueryInterface((nsISupports*)m_incomingServers.Get(&hashKey), &rv); @@ -466,7 +466,7 @@ nsMsgAccountManager::createKeyedServer(const char* key, server->SetUsername(username); server->SetHostName(hostname); - nsStringKey hashKey(key); + nsCStringKey hashKey(key); // addref for the hashtable nsISupports* serversupports = server; @@ -561,7 +561,7 @@ nsMsgAccountManager::RemoveAccount(nsIMsgAccount *aAccount) nsXPIDLCString serverKey; rv = server->GetKey(getter_Copies(serverKey)); - nsStringKey hashKey(serverKey); + nsCStringKey hashKey(serverKey); nsIMsgIncomingServer* removedServer = (nsIMsgIncomingServer*) m_incomingServers.Remove(&hashKey); diff --git a/mozilla/mailnews/base/src/nsMsgFolderCache.cpp b/mozilla/mailnews/base/src/nsMsgFolderCache.cpp index f3868b4c84d..6ee5a55836d 100644 --- a/mozilla/mailnews/base/src/nsMsgFolderCache.cpp +++ b/mozilla/mailnews/base/src/nsMsgFolderCache.cpp @@ -380,7 +380,7 @@ NS_IMETHODIMP nsMsgFolderCache::Init(nsIFileSpec *dbFileSpec) NS_IMETHODIMP nsMsgFolderCache::GetCacheElement(const char *pathKey, PRBool createIfMissing, nsIMsgFolderCacheElement **result) { - nsStringKey hashKey(pathKey); + nsCStringKey hashKey(pathKey); if (!result || !pathKey) return NS_ERROR_NULL_POINTER; @@ -472,7 +472,7 @@ nsresult nsMsgFolderCache::AddCacheElement(const char *key, nsIMdbRow *row, nsIM nsCOMPtr supports(do_QueryInterface(cacheElement)); if(supports) { - nsStringKey hashKey(hashStrKey); + nsCStringKey hashKey(hashStrKey); m_cacheElements->Put(&hashKey, supports); } if (result) diff --git a/mozilla/mailnews/db/msgdb/src/nsMsgDatabase.cpp b/mozilla/mailnews/db/msgdb/src/nsMsgDatabase.cpp index 2d6e0b29f57..71e5aec8ffd 100644 --- a/mozilla/mailnews/db/msgdb/src/nsMsgDatabase.cpp +++ b/mozilla/mailnews/db/msgdb/src/nsMsgDatabase.cpp @@ -86,7 +86,7 @@ nsresult nsMsgDatabase::GetHdrFromCache(nsMsgKey key, nsIMsgDBHdr* *result) // it would be nice if we had an nsISupports hash table that hashed 32 bit int's nsCAutoString strKey; strKey.AppendInt(key, 10); - nsStringKey hashKey(strKey.GetBuffer()); + nsCStringKey hashKey(strKey.GetBuffer()); // nsSupportsHashtable does an addref *result = (nsIMsgDBHdr *) m_cachedHeaders->Get(&hashKey); if (*result) @@ -109,7 +109,7 @@ nsresult nsMsgDatabase::AddHdrToCache(nsIMsgDBHdr *hdr, nsMsgKey key) // do we w // it would be nice if we had an nsISupports hash table that hashed 32 bit int's nsCAutoString strKey; strKey.AppendInt(key, 10); - nsStringKey hashKey(strKey.GetBuffer()); + nsCStringKey hashKey(strKey.GetBuffer()); m_cachedHeaders->Put(&hashKey, hdr); return NS_OK; } @@ -135,7 +135,7 @@ nsresult nsMsgDatabase::RemoveHdrFromCache(nsIMsgDBHdr *hdr, nsMsgKey key) nsCAutoString strKey; strKey.AppendInt(key, 10); - nsStringKey hashKey(strKey.GetBuffer()); + nsCStringKey hashKey(strKey.GetBuffer()); /* * this does release on the held object, unless you don't * want it to, by passing as third argument a non-null pointer @@ -162,7 +162,7 @@ nsresult nsMsgDatabase::GetHdrFromUseCache(nsMsgKey key, nsIMsgDBHdr* *result) // it would be nice if we had a hash table that hashed 32 bit int's nsCAutoString strKey; strKey.AppendInt(key, 10); - nsStringKey hashKey(strKey.GetBuffer()); + nsCStringKey hashKey(strKey.GetBuffer()); // nsHashtable doesn't do an addref *result = (nsIMsgDBHdr *) m_headersInUse->Get(&hashKey); if (*result) @@ -184,7 +184,7 @@ nsresult nsMsgDatabase::AddHdrToUseCache(nsIMsgDBHdr *hdr, nsMsgKey key) // it would be nice if we had an nsISupports hash table that hashed 32 bit int's nsCAutoString strKey; strKey.AppendInt(key, 10); - nsStringKey hashKey(strKey.GetBuffer()); + nsCStringKey hashKey(strKey.GetBuffer()); m_headersInUse->Put(&hashKey, hdr); NS_ADDREF(hdr); // the hash table won't add ref, we'll do it ourselves @@ -213,7 +213,7 @@ nsresult nsMsgDatabase::RemoveHdrFromUseCache(nsIMsgDBHdr *hdr, nsMsgKey key) nsCAutoString strKey; strKey.AppendInt(key, 10); - nsStringKey hashKey(strKey.GetBuffer()); + nsCStringKey hashKey(strKey.GetBuffer()); nsIMsgDBHdr *removedHdr = (nsIMsgDBHdr *) m_headersInUse->Remove(&hashKey); } return NS_OK; diff --git a/mozilla/mailnews/imap/src/nsIMAPBodyShell.cpp b/mozilla/mailnews/imap/src/nsIMAPBodyShell.cpp index 5c06e8c65de..e5c146ef7c4 100644 --- a/mozilla/mailnews/imap/src/nsIMAPBodyShell.cpp +++ b/mozilla/mailnews/imap/src/nsIMAPBodyShell.cpp @@ -1616,7 +1616,7 @@ PRBool nsIMAPBodyShellCache::EjectEntry() nsIMAPBodyShell *removedShell = (nsIMAPBodyShell *) (m_shellList->ElementAt(0)); m_shellList->RemoveElementAt(0); - nsStringKey hashKey (removedShell->GetUID()); + nsCStringKey hashKey (removedShell->GetUID()); m_shellHash->Remove(&hashKey); delete removedShell; @@ -1636,11 +1636,11 @@ PRBool nsIMAPBodyShellCache::AddShellToCache(nsIMAPBodyShell *shell) // First, for safety sake, remove any entry with the given UID, // just in case we have a collision between two messages in different // folders with the same UID. - nsStringKey hashKey1(shell->GetUID()); + nsCStringKey hashKey1(shell->GetUID()); nsIMAPBodyShell *foundShell = (nsIMAPBodyShell *) m_shellHash->Get(&hashKey1); if (foundShell) { - nsStringKey hashKey(foundShell->GetUID()); + nsCStringKey hashKey(foundShell->GetUID()); m_shellHash->Remove(&hashKey); m_shellList->RemoveElement(foundShell); } @@ -1648,7 +1648,7 @@ PRBool nsIMAPBodyShellCache::AddShellToCache(nsIMAPBodyShell *shell) // Add the new one to the cache m_shellList->AppendElement(shell); - nsStringKey hashKey2 (shell->GetUID()); + nsCStringKey hashKey2 (shell->GetUID()); m_shellHash->Put(&hashKey2, shell); shell->SetIsCached(PR_TRUE); @@ -1665,7 +1665,7 @@ PRBool nsIMAPBodyShellCache::AddShellToCache(nsIMAPBodyShell *shell) nsIMAPBodyShell *nsIMAPBodyShellCache::FindShellForUID(nsCString &UID, const char *mailboxName) { - nsStringKey hashKey(UID); + nsCStringKey hashKey(UID); nsIMAPBodyShell *foundShell = (nsIMAPBodyShell *) m_shellHash->Get(&hashKey); if (!foundShell) diff --git a/mozilla/modules/libjar/nsJAR.cpp b/mozilla/modules/libjar/nsJAR.cpp index da21b9921b9..b78574885e4 100644 --- a/mozilla/modules/libjar/nsJAR.cpp +++ b/mozilla/modules/libjar/nsJAR.cpp @@ -324,7 +324,7 @@ nsJAR::GetCertificatePrincipal(const char* aFilename, nsIPrincipal** aPrincipal) if (aFilename) { //-- Find the item - nsStringKey key(aFilename); + nsCStringKey key(aFilename); nsJARManifestItem* manItem = (nsJARManifestItem*)mManifestData.Get(&key); if (!manItem) return NS_OK; @@ -586,7 +586,7 @@ nsJAR::ParseOneFile(nsISignatureVerifier* verifier, curItemMF->mType = JAR_INVALID; } //-- Check for duplicates - nsStringKey key(curItemName); + nsCStringKey key(curItemName); if (mManifestData.Exists(&key)) curItemMF->mType = JAR_INVALID; } @@ -600,7 +600,7 @@ nsJAR::ParseOneFile(nsISignatureVerifier* verifier, CalculateDigest(verifier, sectionStart, sectionLength, &(curItemMF->calculatedSectionDigest)); //-- Save item in the hashtable - nsStringKey itemKey(curItemName); + nsCStringKey itemKey(curItemName); mManifestData.Put(&itemKey, (void*)curItemMF); } if (nextLineStart == nsnull) // end-of-file @@ -616,7 +616,7 @@ nsJAR::ParseOneFile(nsISignatureVerifier* verifier, if (foundName) { nsJARManifestItem* curItemSF; - nsStringKey key(curItemName); + nsCStringKey key(curItemName); curItemSF = (nsJARManifestItem*)mManifestData.Get(&key); if(curItemSF) { @@ -852,7 +852,7 @@ PrintManItem(nsHashKey* aKey, void* aData, void* closure) nsJARManifestItem* manItem = (nsJARManifestItem*)aData; if (manItem) { - nsStringKey* key2 = (nsStringKey*)aKey; + nsCStringKey* key2 = (nsCStringKey*)aKey; char* name = key2->GetString().ToNewCString(); if (!(PL_strcmp(name, "") == 0)) printf("%s s=%i\n",name, manItem->status); @@ -1146,7 +1146,7 @@ nsZipReaderCache::GetZip(nsIFile* zipFile, nsIZipReader* *result) rv = zipFile->GetPath(getter_Copies(path)); if (NS_FAILED(rv)) return rv; - nsStringKey key(path); + nsCStringKey key(path); nsZipCacheEntry* entry = (nsZipCacheEntry*)mZips.Get(&key); if (entry) { *result = entry->mZip; @@ -1204,7 +1204,7 @@ nsZipReaderCache::ReleaseZip(nsIZipReader* zip) rv = zipFile->GetPath(getter_Copies(path)); if (NS_FAILED(rv)) return rv; - nsStringKey key(path); + nsCStringKey key(path); nsZipCacheEntry* entry = (nsZipCacheEntry*)mZips.Get(&key); if (entry == nsnull) return NS_ERROR_FAILURE; diff --git a/mozilla/modules/oji/src/ProxyJNI.cpp b/mozilla/modules/oji/src/ProxyJNI.cpp index 13be066aafd..ac42f491dd8 100644 --- a/mozilla/modules/oji/src/ProxyJNI.cpp +++ b/mozilla/modules/oji/src/ProxyJNI.cpp @@ -97,18 +97,6 @@ static PRBool get_method_type(const char* sig, PRUint32& arg_count, jni_type*& a return PR_FALSE; } -class JNIHashKey : public nsHashKey { -public: - JNIHashKey(void* key) : mKey(key) {} - - virtual PRUint32 HashValue(void) const { return PRUint32(mKey); } - virtual PRBool Equals(const nsHashKey *aKey) const { return mKey == ((JNIHashKey*)aKey)->mKey; } - virtual nsHashKey *Clone(void) const { return new JNIHashKey(mKey); } - -private: - void* mKey; -}; - struct JNIMember { char* mName; char* mSignature; @@ -444,7 +432,7 @@ private: jmethodID outMethodID = NULL; nsresult result = secureEnv->GetMethodID(clazz, name, sig, &outMethodID); if (result == NS_OK && outMethodID != NULL) { - JNIHashKey key(outMethodID); + nsVoidKey key(outMethodID); JNIMethod* method = (JNIMethod*) theIDTable->Get(&key); if (method == NULL) { method = new JNIMethod(name, sig, outMethodID); @@ -662,7 +650,7 @@ private: jfieldID outFieldID = NULL; nsresult result = secureEnv->GetFieldID(clazz, name, sig, &outFieldID); if (result == NS_OK && outFieldID != NULL) { - JNIHashKey key(outFieldID); + nsVoidKey key(outFieldID); JNIField* field = (JNIField*) theIDTable->Get(&key); if (field == NULL) { field = new JNIField(name, sig, outFieldID); @@ -741,7 +729,7 @@ private: jmethodID outMethodID = NULL; nsresult result = secureEnv->GetStaticMethodID(clazz, name, sig, &outMethodID); if (result == NS_OK && outMethodID != NULL) { - JNIHashKey key(outMethodID); + nsVoidKey key(outMethodID); JNIMethod* method = (JNIMethod*) theIDTable->Get(&key); if (method == NULL) { method = new JNIMethod(name, sig, outMethodID); @@ -849,7 +837,7 @@ private: jfieldID outFieldID = NULL; nsresult result = secureEnv->GetStaticFieldID(clazz, name, sig, &outFieldID); if (result == NS_OK && outFieldID != NULL) { - JNIHashKey key(outFieldID); + nsVoidKey key(outFieldID); JNIField* field = (JNIField*) theIDTable->Get(&key); if (field == NULL) { field = new JNIField(name, sig, outFieldID); diff --git a/mozilla/modules/plugin/base/src/nsPluginHostImpl.cpp b/mozilla/modules/plugin/base/src/nsPluginHostImpl.cpp index f2cce40f204..5e4d387a196 100644 --- a/mozilla/modules/plugin/base/src/nsPluginHostImpl.cpp +++ b/mozilla/modules/plugin/base/src/nsPluginHostImpl.cpp @@ -172,7 +172,7 @@ void DisplayNoDefaultPluginDialog(const char *mimeType) mimeTypesSeen = new nsHashtable(NS_MIME_TYPES_HASH_NUM); } if (nsnull != mimeTypesSeen){ - nsStringKey key(mimeType); + nsCStringKey key(mimeType); // if we've seen this mimetype before if (mimeTypesSeen->Get(&key)) { // don't display the dialog diff --git a/mozilla/modules/plugin/nglsrc/nsPluginHostImpl.cpp b/mozilla/modules/plugin/nglsrc/nsPluginHostImpl.cpp index f2cce40f204..5e4d387a196 100644 --- a/mozilla/modules/plugin/nglsrc/nsPluginHostImpl.cpp +++ b/mozilla/modules/plugin/nglsrc/nsPluginHostImpl.cpp @@ -172,7 +172,7 @@ void DisplayNoDefaultPluginDialog(const char *mimeType) mimeTypesSeen = new nsHashtable(NS_MIME_TYPES_HASH_NUM); } if (nsnull != mimeTypesSeen){ - nsStringKey key(mimeType); + nsCStringKey key(mimeType); // if we've seen this mimetype before if (mimeTypesSeen->Get(&key)) { // don't display the dialog diff --git a/mozilla/netwerk/cache/filecache/nsDiskCacheRecord.cpp b/mozilla/netwerk/cache/filecache/nsDiskCacheRecord.cpp index 21d88e3a1cd..4b8db96aa11 100644 --- a/mozilla/netwerk/cache/filecache/nsDiskCacheRecord.cpp +++ b/mozilla/netwerk/cache/filecache/nsDiskCacheRecord.cpp @@ -141,11 +141,12 @@ nsDiskCacheRecord::GetKey(PRUint32 *length, char** _retval) return NS_ERROR_NULL_POINTER ; *length = mKeyLength ; - *_retval = NS_STATIC_CAST(char*, nsMemory::Alloc(mKeyLength*sizeof(char))) ; + *_retval = NS_STATIC_CAST(char*, nsMemory::Alloc(mKeyLength*sizeof(char) + 1)) ; if(!*_retval) return NS_ERROR_OUT_OF_MEMORY ; memcpy(*_retval, mKey, mKeyLength) ; + (*_retval)[mKeyLength] = '\0'; // null terminate because this gets used in a string key for a hashtable return NS_OK ; } diff --git a/mozilla/netwerk/cache/memcache/nsMemCache.cpp b/mozilla/netwerk/cache/memcache/nsMemCache.cpp index 0b6512392c6..6ea61598bee 100644 --- a/mozilla/netwerk/cache/memcache/nsMemCache.cpp +++ b/mozilla/netwerk/cache/memcache/nsMemCache.cpp @@ -83,7 +83,7 @@ nsMemCache::GetDescription(PRUnichar * *aDescription) NS_IMETHODIMP nsMemCache::Contains(const char *aKey, PRUint32 aKeyLength, PRBool *aFound) { - nsOpaqueKey *opaqueKey = new nsOpaqueKey(aKey, aKeyLength); + nsCStringKey *opaqueKey = new nsCStringKey(aKey, aKeyLength); if (!opaqueKey) return NS_ERROR_OUT_OF_MEMORY; *aFound = mHashTable->Exists(opaqueKey); @@ -97,11 +97,11 @@ nsMemCache::GetCachedNetData(const char *aKey, PRUint32 aKeyLength, { nsresult rv; nsMemCacheRecord* record = 0; - nsOpaqueKey *opaqueKey2 = 0; - nsOpaqueKey *opaqueKey3 = 0; - nsOpaqueKey *opaqueKey; + nsCStringKey *opaqueKey2 = 0; + nsCStringKey *opaqueKey3 = 0; + nsCStringKey *opaqueKey; - opaqueKey = new nsOpaqueKey(aKey, aKeyLength); + opaqueKey = new nsCStringKey(aKey, aKeyLength); if (!opaqueKey) goto out_of_memory; record = (nsMemCacheRecord*)mHashTable->Get(opaqueKey); @@ -119,14 +119,14 @@ nsMemCache::GetCachedNetData(const char *aKey, PRUint32 aKeyLength, if (NS_FAILED(rv)) goto out_of_memory; // Index the record by opaque key - opaqueKey2 = new nsOpaqueKey(record->mKey, record->mKeyLength); + opaqueKey2 = new nsCStringKey(record->mKey, record->mKeyLength); if (!opaqueKey2) goto out_of_memory; mHashTable->Put(opaqueKey2, record); // Index the record by it's record ID char *recordIDbytes = NS_REINTERPRET_CAST(char *, &record->mRecordID); - opaqueKey3 = new nsOpaqueKey(recordIDbytes, - sizeof record->mRecordID); + opaqueKey3 = new nsCStringKey(recordIDbytes, + sizeof record->mRecordID); if (!opaqueKey3) { // Clean up the first record from the hash table mHashTable->Remove(opaqueKey); @@ -157,7 +157,7 @@ NS_IMETHODIMP nsMemCache::GetCachedNetDataByID(PRInt32 RecordID, nsINetDataCacheRecord* *aRecord) { - nsOpaqueKey opaqueKey(NS_REINTERPRET_CAST(const char *, &RecordID), + nsCStringKey opaqueKey(NS_REINTERPRET_CAST(const char *, &RecordID), sizeof RecordID); *aRecord = (nsINetDataCacheRecord*)mHashTable->Get(&opaqueKey); if (*aRecord) { @@ -173,12 +173,12 @@ nsMemCache::Delete(nsMemCacheRecord* aRecord) nsMemCacheRecord *removedRecord; char *recordIDbytes = NS_REINTERPRET_CAST(char *, &aRecord->mRecordID); - nsOpaqueKey opaqueRecordIDKey(recordIDbytes, + nsCStringKey opaqueRecordIDKey(recordIDbytes, sizeof aRecord->mRecordID); removedRecord = (nsMemCacheRecord*)mHashTable->Remove(&opaqueRecordIDKey); NS_ASSERTION(removedRecord == aRecord, "memory cache database inconsistent"); - nsOpaqueKey opaqueKey(aRecord->mKey, aRecord->mKeyLength); + nsCStringKey opaqueKey(aRecord->mKey, aRecord->mKeyLength); removedRecord = (nsMemCacheRecord*)mHashTable->Remove(&opaqueKey); NS_ASSERTION(removedRecord == aRecord, "memory cache database inconsistent"); @@ -234,19 +234,19 @@ HashEntryConverter(nsHashKey *aKey, void *aValue, void *unused, nsISupports **retval) { nsMemCacheRecord *record; - nsOpaqueKey *opaqueKey; + nsCStringKey *opaqueKey; record = (nsMemCacheRecord*)aValue; - opaqueKey = (nsOpaqueKey*)aKey; + opaqueKey = (nsCStringKey*)aKey; // Hash table keys that index cache entries by their record ID // shouldn't be enumerated. - if ((opaqueKey->GetKeyLength() == sizeof(PRInt32))) { + if ((opaqueKey->GetStringLength() == sizeof(PRInt32))) { #ifdef DEBUG PRInt32 recordID; record->GetRecordID(&recordID); - NS_ASSERTION(*((PRInt32*)opaqueKey->GetKey()) == recordID, + NS_ASSERTION(*((PRInt32*)opaqueKey->GetString()) == recordID, "Key has incorrect key length"); #endif return NS_ERROR_FAILURE; diff --git a/mozilla/netwerk/cache/memcache/nsMemCacheRecord.cpp b/mozilla/netwerk/cache/memcache/nsMemCacheRecord.cpp index fdf334ef95f..72078cc1094 100644 --- a/mozilla/netwerk/cache/memcache/nsMemCacheRecord.cpp +++ b/mozilla/netwerk/cache/memcache/nsMemCacheRecord.cpp @@ -47,10 +47,11 @@ NS_IMETHODIMP nsMemCacheRecord::GetKey(PRUint32 *aLength, char **aResult) { NS_ENSURE_ARG(aResult); - *aResult = (char *)nsMemory::Alloc(mKeyLength); + *aResult = (char *)nsMemory::Alloc(mKeyLength + 1); if (!*aResult) return NS_ERROR_OUT_OF_MEMORY; memcpy(*aResult, mKey, mKeyLength); + (*aResult)[mKeyLength] = '\0'; // null terminate because this is going to be used in a string key *aLength = mKeyLength; return NS_OK; } @@ -67,10 +68,11 @@ nsMemCacheRecord::Init(const char *aKey, PRUint32 aKeyLength, getter_AddRefs(mStorageStream)); if (NS_FAILED(rv)) return rv; - mKey = new char[aKeyLength]; + mKey = new char[aKeyLength + 1]; if (!mKey) return NS_ERROR_OUT_OF_MEMORY; memcpy(mKey, aKey, aKeyLength); + mKey[aKeyLength] = '\0'; // null terminate because we're going to use this for a hash key mKeyLength = aKeyLength; mRecordID = aRecordID; mCache = aCache; diff --git a/mozilla/netwerk/cache/mgr/nsCacheManager.cpp b/mozilla/netwerk/cache/mgr/nsCacheManager.cpp index 88df4ad314b..afc2f601735 100644 --- a/mozilla/netwerk/cache/mgr/nsCacheManager.cpp +++ b/mozilla/netwerk/cache/mgr/nsCacheManager.cpp @@ -245,12 +245,13 @@ nsCacheManager::GetCachedNetData(const char *aUriSpec, const char *aSecondaryKey // Construct the cache key by appending the secondary key to the URI spec nsCAutoString cacheKey(aUriSpec); - // Insert NUL at end of URI spec - cacheKey += '\0'; - if (aSecondaryKey) + // Insert a newline between URI spec and secondary key + if (aSecondaryKey) { + cacheKey += '\n'; cacheKey.Append(aSecondaryKey, aSecondaryKeyLength); + } - nsStringKey key(cacheKey); + nsCStringKey key(cacheKey); cachedData = (nsCachedNetData*)mActiveCacheRecords->Get(&key); // There is no existing instance of nsCachedNetData for this URL. @@ -288,7 +289,7 @@ nsCacheManager::NoteDormant(nsCachedNetData* aEntry) rv = record->GetKey(&keyLength, &key); if (NS_FAILED(rv)) return rv; - nsStringKey hashTableKey(nsCString(key, keyLength)); + nsCStringKey hashTableKey(key, keyLength); deletedEntry = (nsCachedNetData*)gCacheManager->mActiveCacheRecords->Remove(&hashTableKey); // NS_ASSERTION(deletedEntry == aEntry, "Hash table inconsistency"); nsMemory::Free( key ); @@ -310,12 +311,14 @@ nsCacheManager::Contains(const char *aUriSpec, const char *aSecondaryKey, // Construct the cache key by appending the secondary key to the URI spec nsCAutoString cacheKey(aUriSpec); - // Insert NUL between URI spec and secondary key - cacheKey += '\0'; - cacheKey.Append(aSecondaryKey, aSecondaryKeyLength); + // Insert a newline between URI spec and secondary key + if (aSecondaryKey) { + cacheKey += '\n'; + cacheKey.Append(aSecondaryKey, aSecondaryKeyLength); + } // Locate the record using (URI + secondary key) - nsStringKey key(cacheKey); + nsCStringKey key(cacheKey); cachedData = (nsCachedNetData*)mActiveCacheRecords->Get(&key); if (cachedData && (cache == cachedData->mCache)) { diff --git a/mozilla/netwerk/dns/src/nsDnsService.cpp b/mozilla/netwerk/dns/src/nsDnsService.cpp index 3e178f2b895..d76e3dfebf0 100644 --- a/mozilla/netwerk/dns/src/nsDnsService.cpp +++ b/mozilla/netwerk/dns/src/nsDnsService.cpp @@ -542,7 +542,7 @@ nsDNSLookup::InitiateLookup(void) rv = CompleteLookup(NS_OK); // XXX remove from hashtable and release - for now - nsStringKey key(mHostName); + nsCStringKey key(mHostName); (void) nsDNSService::gService->mLookups.Remove(&key); } nsMemory::Free(netAddr); @@ -605,7 +605,7 @@ nsDNSLookup::InitiateLookup(void) rv = CompleteLookup(rv); // XXX remove from hashtable and release - for now - nsStringKey key(mHostName); + nsCStringKey key(mHostName); nsDNSService::gService->mLookups.Remove(&key); #endif /* XP_UNIX */ @@ -775,7 +775,7 @@ nsDNSService::ProcessLookup(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam) gService->FreeMsgID(lookup->mMsgID); // XXX remove from hashtable and release - for now - nsStringKey key(lookup->mHostName); + nsCStringKey key(lookup->mHostName); (void) nsDNSService::gService->mLookups.Remove(&key); NS_RELEASE(lookup); @@ -1069,7 +1069,7 @@ nsDNSService::Run(void) rv = lookup->CompleteLookup(lookup->mStatus); // sets lookup->mComplete = PR_TRUE; // XXX remove from hashtable and release - for now - nsStringKey key(lookup->mHostName); + nsCStringKey key(lookup->mHostName); (void) nsDNSService::gService->mLookups.Remove(&key); NS_RELEASE(lookup); @@ -1152,7 +1152,7 @@ nsDNSService::GetLookupEntry(const char* hostName, nsAutoMonitor mon(mMonitor); - nsStringKey key(hostName); + nsCStringKey key(hostName); nsDNSLookup * lookup = (nsDNSLookup*)mLookups.Get(&key); if (lookup) { nsAutoCMonitor lmon(lookup); diff --git a/mozilla/netwerk/mime/src/nsXMLMIMEDataSource.cpp b/mozilla/netwerk/mime/src/nsXMLMIMEDataSource.cpp index d8bc4560d05..12968e81b9b 100644 --- a/mozilla/netwerk/mime/src/nsXMLMIMEDataSource.cpp +++ b/mozilla/netwerk/mime/src/nsXMLMIMEDataSource.cpp @@ -129,7 +129,7 @@ nsXMLMIMEDataSource::AddMapping(const char* mimeType, if (NS_FAILED(rv)) return rv; // Next add the new root MIME mapping. - nsStringKey key(mimeType); + nsCStringKey key(mimeType); nsMIMEInfoImpl* oldInfo = (nsMIMEInfoImpl*)mInfoObjects->Put(&key, anInfo); NS_ASSERTION(!oldInfo, "we just removed the entry, we shouldn't have one"); NS_ADDREF(anInfo); @@ -164,7 +164,7 @@ nsXMLMIMEDataSource::Add( nsIMIMEInfo* aMapper ) if (NS_FAILED(rv)) return rv; // Next add the new root MIME mapping. - nsStringKey key(mimeType); + nsCStringKey key(mimeType); nsMIMEInfoImpl* oldInfo = (nsMIMEInfoImpl*)mInfoObjects->Put(&key, aMapper); NS_ASSERTION(!oldInfo, "we just removed the entry, we shouldn't have one"); NS_ADDREF(aMapper); @@ -197,7 +197,7 @@ static PRBool removeExts(nsCString& aElement, void *aData) { nsHashtable* infoObjects = (nsHashtable*)aData; NS_ASSERTION(infoObjects, "hash table botched up"); - nsStringKey key(aElement); + nsCStringKey key(aElement); nsMIMEInfoImpl* info = (nsMIMEInfoImpl*)infoObjects->Remove(&key); NS_RELEASE(info); return PR_TRUE; @@ -206,7 +206,7 @@ static PRBool removeExts(nsCString& aElement, void *aData) { NS_IMETHODIMP nsXMLMIMEDataSource::Remove(const char* aMIMEType) { nsresult rv = NS_OK; - nsStringKey key(aMIMEType); + nsCStringKey key(aMIMEType); // First remove the root MIME mapping. nsMIMEInfoImpl* info = (nsMIMEInfoImpl*)mInfoObjects->Remove(&key); @@ -228,7 +228,7 @@ nsXMLMIMEDataSource::Remove(const char* aMIMEType) { nsresult nsXMLMIMEDataSource::AppendExtension(const char* mimeType, const char* extension) { - nsStringKey key(mimeType); + nsCStringKey key(mimeType); nsMIMEInfoImpl* info = (nsMIMEInfoImpl*)mInfoObjects->Get(&key); if (!info) return NS_ERROR_FAILURE; @@ -247,7 +247,7 @@ nsXMLMIMEDataSource::AppendExtension(const char* mimeType, const char* extension nsresult nsXMLMIMEDataSource::RemoveExtension(const char* aExtension) { nsresult rv = NS_OK; - nsStringKey key(aExtension); + nsCStringKey key(aExtension); // First remove the extension mapping. nsMIMEInfoImpl* info = (nsMIMEInfoImpl*)mInfoObjects->Remove(&key); @@ -255,8 +255,7 @@ nsXMLMIMEDataSource::RemoveExtension(const char* aExtension) { // Next remove the root MIME mapping from the array and hash // IFF this was the only file extension mapping left. - nsCAutoString keyString; keyString.AssignWithConversion(key.GetString().GetUnicode()); - PRBool removed = info->mExtensions.RemoveCString(keyString); + PRBool removed = info->mExtensions.RemoveCString(aExtension); NS_ASSERTION(removed, "mapping problem"); if (info->GetExtCount() == 0) { @@ -517,7 +516,7 @@ nsXMLMIMEDataSource::GetFromExtension(const char *aFileExt, nsIMIMEInfo **_retva nsCAutoString fileExt(aFileExt); fileExt.ToLowerCase(); - nsStringKey key(fileExt.GetBuffer()); + nsCStringKey key(fileExt.GetBuffer()); nsMIMEInfoImpl *entry = (nsMIMEInfoImpl*)mInfoObjects->Get(&key); if (!entry) return NS_ERROR_FAILURE; @@ -533,7 +532,7 @@ nsXMLMIMEDataSource::GetFromMIMEType(const char *aMIMEType, nsIMIMEInfo **_retva nsCAutoString MIMEType(aMIMEType); MIMEType.ToLowerCase(); - nsStringKey key(MIMEType.GetBuffer()); + nsCStringKey key(MIMEType.GetBuffer()); nsMIMEInfoImpl *entry = (nsMIMEInfoImpl*)mInfoObjects->Get(&key); if (!entry) return NS_ERROR_FAILURE; @@ -549,9 +548,9 @@ nsXMLMIMEDataSource::GetFromTypeCreator(PRUint32 aType, PRUint32 aCreator, const PRUint32 buf[2]; buf[0] = aType; buf[1] = aCreator; - nsAutoString keyString; keyString.AssignWithConversion( (char*)buf,8 ); - keyString.AppendWithConversion(aExt); - nsStringKey key( keyString ); + nsCAutoString keyString((char*)buf,8); + keyString += aExt; + nsCStringKey key(keyString); // Check if in cache for real quick look up of common ( html,js, xul, ...) types nsIMIMEInfo *entry = (nsIMIMEInfo*)mMacCache.Get(&key); if (entry) diff --git a/mozilla/netwerk/protocol/ftp/src/nsFtpProtocolHandler.cpp b/mozilla/netwerk/protocol/ftp/src/nsFtpProtocolHandler.cpp index 859be63ff24..530432e2f3e 100644 --- a/mozilla/netwerk/protocol/ftp/src/nsFtpProtocolHandler.cpp +++ b/mozilla/netwerk/protocol/ftp/src/nsFtpProtocolHandler.cpp @@ -245,7 +245,7 @@ nsFtpProtocolHandler::NewChannel(nsIURI* url, nsIChannel* *result) NS_IMETHODIMP nsFtpProtocolHandler::RemoveConn(const char *aKey, nsConnectionCacheObj* *_retval) { NS_ASSERTION(_retval, "null pointer"); - nsStringKey key(aKey); + nsCStringKey key(aKey); nsAutoLock lock(mLock); *_retval = (nsConnectionCacheObj*)mRootConnectionList->Remove(&key); return NS_OK; @@ -254,7 +254,7 @@ nsFtpProtocolHandler::RemoveConn(const char *aKey, nsConnectionCacheObj* *_retva NS_IMETHODIMP nsFtpProtocolHandler::InsertConn(const char *aKey, nsConnectionCacheObj *aConn) { NS_ASSERTION(aConn, "null pointer"); - nsStringKey key(aKey); + nsCStringKey key(aKey); nsAutoLock lock(mLock); mRootConnectionList->Put(&key, aConn); return NS_OK; diff --git a/mozilla/netwerk/protocol/http/src/nsHTTPHandler.cpp b/mozilla/netwerk/protocol/http/src/nsHTTPHandler.cpp index d9c8833d8f7..4225e7bfa5b 100644 --- a/mozilla/netwerk/protocol/http/src/nsHTTPHandler.cpp +++ b/mozilla/netwerk/protocol/http/src/nsHTTPHandler.cpp @@ -1468,7 +1468,7 @@ nsHTTPHandler::SetServerCapabilities( hStr.Append( ':'); hStr.AppendInt(port); - nsStringKey key(hStr); + nsCStringKey key(hStr); mCapTable.Put(&key, (void *)aCapabilities); } return NS_OK; @@ -1494,7 +1494,7 @@ nsHTTPHandler::GetServerCapabilities ( hStr.Append ( ':'); hStr.AppendInt (port); - nsStringKey key (hStr); + nsCStringKey key (hStr); void * p = mCapTable.Get (&key); if (p != NULL) diff --git a/mozilla/netwerk/protocol/res/src/nsResChannel.cpp b/mozilla/netwerk/protocol/res/src/nsResChannel.cpp index 9331a47a54b..cad366510eb 100644 --- a/mozilla/netwerk/protocol/res/src/nsResChannel.cpp +++ b/mozilla/netwerk/protocol/res/src/nsResChannel.cpp @@ -123,7 +123,9 @@ nsResChannel::Substitutions::Init() char* root; rv = channel->mResourceURI->GetHost(&root); if (NS_SUCCEEDED(rv)) { - rv = channel->mHandler->GetSubstitutions(root, getter_AddRefs(mSubstitutions)); + char* strRoot = root; + if (strRoot == nsnull) strRoot = ""; // don't pass null to GetSubstitutions + rv = channel->mHandler->GetSubstitutions(strRoot, getter_AddRefs(mSubstitutions)); nsCRT::free(root); } return rv; diff --git a/mozilla/netwerk/protocol/res/src/nsResProtocolHandler.cpp b/mozilla/netwerk/protocol/res/src/nsResProtocolHandler.cpp index 3709ff4c40a..fdf9ce6ba38 100644 --- a/mozilla/netwerk/protocol/res/src/nsResProtocolHandler.cpp +++ b/mozilla/netwerk/protocol/res/src/nsResProtocolHandler.cpp @@ -245,7 +245,7 @@ nsResProtocolHandler::PrependSubstitution(const char *root, const char *urlStr) rv = ioServ->NewURI(urlStr, nsnull, getter_AddRefs(url)); if (NS_FAILED(rv)) return rv; - nsStringKey key(root); + nsCStringKey key(root); nsCOMPtr strings; nsCOMPtr newStrings; @@ -281,7 +281,7 @@ nsResProtocolHandler::AppendSubstitution(const char *root, const char *urlStr) rv = ioServ->NewURI(urlStr, nsnull, getter_AddRefs(url)); if (NS_FAILED(rv)) return rv; - nsStringKey key(root); + nsCStringKey key(root); nsCOMPtr strings; nsCOMPtr newStrings; @@ -337,7 +337,7 @@ nsResProtocolHandler::RemoveSubstitution(const char *root, const char *urlStr) rv = ioServ->NewURI(urlStr, nsnull, getter_AddRefs(url)); if (NS_FAILED(rv)) return rv; - nsStringKey key(root); + nsCStringKey key(root); nsCOMPtr strings; nsCOMPtr newStrings; @@ -368,7 +368,7 @@ nsResProtocolHandler::GetSubstitutions(const char *root, nsISupportsArray* *resu nsresult rv; nsAutoLock lock(mLock); - nsStringKey key(root); + nsCStringKey key(root); nsISupportsArray* strings = (nsISupportsArray*)mSubstitutions.Get(&key); if (strings == nsnull) { rv = NS_NewISupportsArray(&strings); @@ -382,7 +382,7 @@ nsResProtocolHandler::GetSubstitutions(const char *root, nsISupportsArray* *resu NS_IMETHODIMP nsResProtocolHandler::HasSubstitutions(const char *root, PRBool *result) { - nsStringKey key(root); + nsCStringKey key(root); *result = mSubstitutions.Exists(&key); return NS_OK; } diff --git a/mozilla/netwerk/streamconv/converters/nsHTTPChunkConv.h b/mozilla/netwerk/streamconv/converters/nsHTTPChunkConv.h index bcad2eee64c..7755f1eb575 100644 --- a/mozilla/netwerk/streamconv/converters/nsHTTPChunkConv.h +++ b/mozilla/netwerk/streamconv/converters/nsHTTPChunkConv.h @@ -165,7 +165,7 @@ public: void AddTrailerHeader (const char *header) { - nsStringKey key (header); + nsCStringKey key (header); mTrailer.Put (&key, (void *) 1); mHeadersCount++; diff --git a/mozilla/netwerk/streamconv/src/nsStreamConverterService.cpp b/mozilla/netwerk/streamconv/src/nsStreamConverterService.cpp index 569ff79b982..7454cd60569 100644 --- a/mozilla/netwerk/streamconv/src/nsStreamConverterService.cpp +++ b/mozilla/netwerk/streamconv/src/nsStreamConverterService.cpp @@ -185,9 +185,9 @@ nsStreamConverterService::AddAdjacency(const char *aProgID) { // each MIME-type is represented as a key in our hashtable. PRBool delFrom = PR_TRUE, delTo = PR_TRUE; - nsStringKey *fromKey = new nsStringKey(fromStr.GetBuffer()); + nsCStringKey *fromKey = new nsCStringKey(fromStr.GetBuffer()); if (!fromKey) return NS_ERROR_OUT_OF_MEMORY; - nsStringKey *toKey = new nsStringKey(toStr.GetBuffer()); + nsCStringKey *toKey = new nsCStringKey(toStr.GetBuffer()); if (!toKey) { delete fromKey; return NS_ERROR_OUT_OF_MEMORY; @@ -355,7 +355,7 @@ nsStreamConverterService::FindConverter(const char *aProgID, nsCStringArray **aE rv = ParseFromTo(aProgID, fromC, toC); if (NS_FAILED(rv)) return rv; - nsStringKey *source = new nsStringKey(fromC.GetBuffer()); + nsCStringKey *source = new nsCStringKey(fromC.GetBuffer()); if (!source) return NS_ERROR_OUT_OF_MEMORY; SCTableData *data = (SCTableData*)lBFSTable.Get(source); @@ -390,7 +390,7 @@ nsStreamConverterService::FindConverter(const char *aProgID, nsCStringArray **aE nsStr::Initialize(curVertexStr, eOneByte); curVertexAtom->ToString(curVertexStr); char * curVertexCString = curVertexStr.ToNewCString(); - nsStringKey *curVertex = new nsStringKey(curVertexCString); + nsCStringKey *curVertex = new nsCStringKey(curVertexCString); nsMemory::Free(curVertexCString); SCTableData *data3 = (SCTableData*)lBFSTable.Get(curVertex); @@ -408,7 +408,7 @@ nsStreamConverterService::FindConverter(const char *aProgID, nsCStringArray **aE } } headVertexState->color = black; - nsStringKey *cur = (nsStringKey*)grayQ->PopFront(); + nsCStringKey *cur = (nsCStringKey*)grayQ->PopFront(); delete cur; cur = nsnull; } @@ -426,7 +426,7 @@ nsStreamConverterService::FindConverter(const char *aProgID, nsCStringArray **aE nsCString ProgIDPrefix(NS_ISTREAMCONVERTER_KEY); nsCStringArray *shortestPath = new nsCStringArray(); //nsVoidArray *shortestPath = new nsVoidArray(); - nsStringKey *toMIMEType = new nsStringKey(toStr); + nsCStringKey *toMIMEType = new nsCStringKey(toStr); data = (SCTableData*)lBFSTable.Get(toMIMEType); delete toMIMEType; diff --git a/mozilla/rdf/chrome/src/nsChromeRegistry.cpp b/mozilla/rdf/chrome/src/nsChromeRegistry.cpp index 55e5c42bf0c..e643c137849 100644 --- a/mozilla/rdf/chrome/src/nsChromeRegistry.cpp +++ b/mozilla/rdf/chrome/src/nsChromeRegistry.cpp @@ -848,7 +848,7 @@ NS_IMETHODIMP nsChromeRegistry::LoadDataSource(const nsCString &aFileName, if (mDataSourceTable) { - nsStringKey skey(key); + nsCStringKey skey(key); nsCOMPtr supports = getter_AddRefs(NS_STATIC_CAST(nsISupports*, mDataSourceTable->Get(&skey))); @@ -884,7 +884,7 @@ NS_IMETHODIMP nsChromeRegistry::LoadDataSource(const nsCString &aFileName, rv = remote->Refresh(PR_TRUE); nsCOMPtr supports = do_QueryInterface(remote); - nsStringKey skey(key); + nsCStringKey skey(key); mDataSourceTable->Put(&skey, supports.get()); return NS_OK; diff --git a/mozilla/rdf/content/src/nsXULKeyListener.cpp b/mozilla/rdf/content/src/nsXULKeyListener.cpp index f34fe078c9f..62da8e1c3ac 100644 --- a/mozilla/rdf/content/src/nsXULKeyListener.cpp +++ b/mozilla/rdf/content/src/nsXULKeyListener.cpp @@ -274,7 +274,7 @@ protected: nsIURIKey(nsIURI* key) : mKey(key) {} ~nsIURIKey(void) {} - PRUint32 HashValue(void) const { + PRUint32 HashCode(void) const { nsXPIDLCString spec; mKey->GetSpec(getter_Copies(spec)); return (PRUint32) PL_HashString(spec); diff --git a/mozilla/rdf/content/src/nsXULPrototypeCache.cpp b/mozilla/rdf/content/src/nsXULPrototypeCache.cpp index 128cddfe4ff..b32f9c9b0f2 100644 --- a/mozilla/rdf/content/src/nsXULPrototypeCache.cpp +++ b/mozilla/rdf/content/src/nsXULPrototypeCache.cpp @@ -84,7 +84,7 @@ protected: nsIURIKey(nsIURI* key) : mKey(key) {} ~nsIURIKey(void) {} - PRUint32 HashValue(void) const { + PRUint32 HashCode(void) const { nsXPIDLCString spec; mKey->GetSpec(getter_Copies(spec)); return (PRUint32) PL_HashString(spec); @@ -201,7 +201,7 @@ nsXULPrototypeCache::PutStyleSheet(nsICSSStyleSheet* aStyleSheet) NS_IMETHODIMP nsXULPrototypeCache::GetXBLDocument(const nsCString& aString, nsIDocument** _result) { - nsStringKey key(aString); + nsCStringKey key(aString); *_result = NS_STATIC_CAST(nsIDocument*, mXBLDocTable.Get(&key)); return NS_OK; } @@ -213,7 +213,7 @@ nsXULPrototypeCache::PutXBLDocument(nsIDocument *aDocument) nsXPIDLCString str; uri->GetSpec(getter_Copies(str)); - nsStringKey key((const char*)str); + nsCStringKey key((const char*)str); mXBLDocTable.Put(&key, aDocument); return NS_OK; @@ -222,7 +222,7 @@ nsXULPrototypeCache::PutXBLDocument(nsIDocument *aDocument) NS_IMETHODIMP nsXULPrototypeCache::GetXBLDocScriptAccess(const nsCString& aString, nsIDocument** _result) { - nsStringKey key(aString); + nsCStringKey key(aString); *_result = NS_STATIC_CAST(nsIDocument*, mScriptAccessTable.Get(&key)); return NS_OK; } @@ -234,7 +234,7 @@ nsXULPrototypeCache::PutXBLDocScriptAccess(nsIDocument *aDocument) nsXPIDLCString str; uri->GetSpec(getter_Copies(str)); - nsStringKey key((const char*)str); + nsCStringKey key((const char*)str); mScriptAccessTable.Put(&key, aDocument); return NS_OK; diff --git a/mozilla/rdf/tests/domds/nsRDFDOMDataSource.cpp b/mozilla/rdf/tests/domds/nsRDFDOMDataSource.cpp index 7ce095fcb9e..9775168c3cc 100644 --- a/mozilla/rdf/tests/domds/nsRDFDOMDataSource.cpp +++ b/mozilla/rdf/tests/domds/nsRDFDOMDataSource.cpp @@ -286,7 +286,7 @@ nsRDFDOMDataSource::GetTargets(nsIRDFResource *aSource, nsIRDFResource *aPropert // what node is this? if (aSource == kNC_DOMRoot) { - nsStringKey frameMode("frame"); + nsCStringKey frameMode("frame"); if (mModeTable.Get(&frameMode)) rv = getTargetsForKnownObject(mRootFrame, aProperty, PR_TRUE, arcs); else @@ -750,7 +750,7 @@ nsRDFDOMDataSource::getTargetForKnownObject(nsISupports* object, nsresult rv; // should we display nsIFrames? - nsStringKey frameMode("frame"); + nsCStringKey frameMode("frame"); if (mModeTable.Get(&frameMode)) { nsIFrame *frame; rv = object->QueryInterface(kFrameIID, (void **)&frame); @@ -760,7 +760,7 @@ nsRDFDOMDataSource::getTargetForKnownObject(nsISupports* object, } // should we display nsIDOMNodes? - nsStringKey domMode("dom"); + nsCStringKey domMode("dom"); if (mModeTable.Get(&domMode)) { // nsIDOMNode @@ -879,7 +879,7 @@ nsRDFDOMDataSource::getTargetsForKnownObject(nsISupports *object, } // nsIFrame (testing right now) - nsStringKey frameKey("frame"); + nsCStringKey frameKey("frame"); if (mModeTable.Get(&frameKey)) { nsIFrame* frame; rv = object->QueryInterface(kFrameIID, (void **)&frame); @@ -890,7 +890,7 @@ nsRDFDOMDataSource::getTargetsForKnownObject(nsISupports *object, } // nsIDOMNode hierarchy - nsStringKey domKey("dom"); + nsCStringKey domKey("dom"); if (mModeTable.Get(&domKey)) { // try HTML first @@ -908,7 +908,7 @@ nsRDFDOMDataSource::getTargetsForKnownObject(nsISupports *object, } // nsIContent hierarchy - nsStringKey contentKey("content"); + nsCStringKey contentKey("content"); if (mModeTable.Get(&contentKey) && !useDOM) { // start at nsIStyleContent and work upwards nsCOMPtr styledContent = @@ -934,7 +934,7 @@ nsRDFDOMDataSource::appendLeafObject(nsString& name, nsISupportsArray* arcs) { nsresult rv; - nsStringKey leafKey("leaf"); + nsCStringKey leafKey("leaf"); if (!mModeTable.Get(&leafKey)) return NS_OK; nsIRDFDOMViewerObject* viewerObject; @@ -1268,7 +1268,7 @@ nsRDFDOMDataSource::SetMode(const char *mode, PRBool active) { printf("Turning %s the %s mode\n", active ? "ON" : "OFF", mode); - nsStringKey modeKey(mode); + nsCStringKey modeKey(mode); mModeTable.Put(&modeKey, (void *)active); return NS_OK; } @@ -1276,7 +1276,7 @@ nsRDFDOMDataSource::SetMode(const char *mode, PRBool active) nsresult nsRDFDOMDataSource::GetMode(const char *mode, PRBool *active) { - nsStringKey modeKey(mode); + nsCStringKey modeKey(mode); *active = (PRBool)mModeTable.Get(&modeKey); return NS_OK; } diff --git a/mozilla/string/obsolete/nsStr.cpp b/mozilla/string/obsolete/nsStr.cpp index 67e02a2dce9..0f300bf9281 100644 --- a/mozilla/string/obsolete/nsStr.cpp +++ b/mozilla/string/obsolete/nsStr.cpp @@ -780,25 +780,10 @@ CBufDescriptor::CBufDescriptor(const PRUnichar* aString,PRBool aStackBased,PRUin PRUint32 nsStr::HashCode(const nsStr& aDest) { - if (aDest.mCharSize == eTwoByte) { - PRUint32 h; - PRUint32 n = aDest.mLength; - PRUint32 m; - const PRUnichar* c; - h = 0; - - c = aDest.mUStr; - if (n < 16) { /* Hash every char in a short string. */ - for(; n; c++, n--) - h = (h >> 28) ^ (h << 4) ^ *c; - } - else { /* Sample a la java.lang.String.hash(). */ - for(m = n / 8; n >= m; c += m, n -= m) - h = (h >> 28) ^ (h << 4) ^ *c; - } - return h; - } - return (PRUint32)PL_HashString((const void*) aDest.mStr); + if (aDest.mCharSize == eTwoByte) + return nsCRT::HashCode(aDest.mUStr, aDest.mLength); + else + return nsCRT::HashCode(aDest.mStr, aDest.mLength); } #ifdef NS_STR_STATS diff --git a/mozilla/string/obsolete/nsStr.h b/mozilla/string/obsolete/nsStr.h index f8c392345da..d876eee8b70 100644 --- a/mozilla/string/obsolete/nsStr.h +++ b/mozilla/string/obsolete/nsStr.h @@ -431,7 +431,6 @@ struct NS_COM nsStr { */ static PRUint32 HashCode(const nsStr& aDest); - #ifndef NEW_STRING_APIS static void Append(nsStr& aDest,const nsStr& aSource,PRUint32 anOffset,PRInt32 aCount) { StrAppend(aDest, aSource, anOffset, aCount); diff --git a/mozilla/xpcom/components/nsCategoryManager.cpp b/mozilla/xpcom/components/nsCategoryManager.cpp index f156e77399d..8b737fd764b 100644 --- a/mozilla/xpcom/components/nsCategoryManager.cpp +++ b/mozilla/xpcom/components/nsCategoryManager.cpp @@ -48,27 +48,22 @@ static NS_IMETHODIMP ExtractKeyString( nsHashKey* key, void*, void*, nsISupports** _retval ) - /* - ...works with |nsHashtableEnumerator| to make the hash keys enumerable. - */ - { - nsresult status; - nsCOMPtr obj = do_CreateInstance(NS_SUPPORTS_STRING_PROGID, &status); - if ( obj ) - { - // BULLSHIT ALERT: use |nsCAutoString| to deflate to single-byte until I can add, e.g., - // |nsCStringKey| to hashtable - const nsString& s = NS_STATIC_CAST(nsStringKey*, key)->GetString(); - nsCAutoString tmpStr; - tmpStr.AssignWithConversion(s); - status = obj->SetDataWithLength(tmpStr.Length(), tmpStr); - } - - *_retval = obj; - NS_IF_ADDREF(*_retval); - return status; + /* + ...works with |nsHashtableEnumerator| to make the hash keys enumerable. + */ +{ + nsresult status; + nsCOMPtr obj = do_CreateInstance(NS_SUPPORTS_STRING_PROGID, &status); + if ( obj ) { + nsCStringKey* strkey = NS_STATIC_CAST(nsCStringKey*, key); + status = obj->SetDataWithLength(strkey->GetStringLength(), strkey->GetString()); } + *_retval = obj; + NS_IF_ADDREF(*_retval); + return status; +} + typedef nsCString LeafNode; @@ -104,7 +99,7 @@ class CategoryNode LeafNode* CategoryNode::find_leaf( const char* aLeafName ) { - nsStringKey leafNameKey(aLeafName); + nsCStringKey leafNameKey(aLeafName); return NS_STATIC_CAST(LeafNode*, Get(&leafNameKey)); } @@ -236,7 +231,7 @@ nsCategoryManager::~nsCategoryManager() CategoryNode* nsCategoryManager::find_category( const char* aCategoryName ) { - nsStringKey categoryNameKey(aCategoryName); + nsCStringKey categoryNameKey(aCategoryName); return NS_STATIC_CAST(CategoryNode*, Get(&categoryNameKey)); } @@ -297,7 +292,7 @@ nsCategoryManager::GetCategoryEntryRaw( const char *aCategoryName, CategoryNode* category = find_category(aCategoryName); if (category) { - nsStringKey entryKey(aEntryName); + nsCStringKey entryKey(aEntryName); LeafNode* entry = NS_STATIC_CAST(LeafNode*, category->Get(&entryKey)); if (entry) status = (*_retval = nsXPIDLCString::Copy(*entry)) ? NS_OK : NS_ERROR_OUT_OF_MEMORY; @@ -337,7 +332,7 @@ nsCategoryManager::AddCategoryEntry( const char *aCategoryName, { // That category doesn't exist yet; let's make it. category = new CategoryNode; - nsStringKey categoryNameKey(aCategoryName); + nsCStringKey categoryNameKey(aCategoryName); Put(&categoryNameKey, category); } @@ -365,7 +360,7 @@ nsCategoryManager::AddCategoryEntry( const char *aCategoryName, // If you didn't say 'replace', and there was already an entry there, // then we can't put your value in, or make it persistent (see below) entry = new LeafNode(aValue); - nsStringKey entryNameKey(aEntryName); + nsCStringKey entryNameKey(aEntryName); category->Put(&entryNameKey, entry); // If you said 'persist' but not 'replace', and an entry @@ -406,7 +401,7 @@ nsCategoryManager::DeleteCategoryEntry( const char *aCategoryName, CategoryNode* category = find_category(aCategoryName); if (category) { - nsStringKey entryKey(aEntryName); + nsCStringKey entryKey(aEntryName); category->RemoveAndDelete(&entryKey); } @@ -425,7 +420,7 @@ nsCategoryManager::DeleteCategory( const char *aCategoryName ) NS_ASSERTION(aCategoryName, "aCategoryName is NULL!"); // QUESTION: consider whether this should be an error - nsStringKey categoryKey(aCategoryName); + nsCStringKey categoryKey(aCategoryName); return RemoveAndDelete(&categoryKey) ? NS_OK : NS_ERROR_NOT_AVAILABLE; } diff --git a/mozilla/xpcom/components/nsComponentManager.cpp b/mozilla/xpcom/components/nsComponentManager.cpp index 2baf36dc13c..dbaea9ef112 100644 --- a/mozilla/xpcom/components/nsComponentManager.cpp +++ b/mozilla/xpcom/components/nsComponentManager.cpp @@ -312,7 +312,7 @@ nsresult nsComponentManagerImpl::Init(void) mLoaders = new nsSupportsHashtable(16, /* Thread safe */ PR_TRUE); if (mLoaders == nsnull) return NS_ERROR_OUT_OF_MEMORY; - nsStringKey loaderKey(nativeComponentType); + nsCStringKey loaderKey(nativeComponentType); mLoaders->Put(&loaderKey, mNativeComponentLoader); } @@ -937,7 +937,7 @@ nsresult nsComponentManagerImpl::PlatformPrePopulateRegistry() } // put the {progid, Cid} mapping into our map - nsStringKey key(progidString); + nsCStringKey key(progidString); mProgIDs->Put(&key, aClass); // printf("Populating [ %s, %s ]\n", cidString, progidString); } @@ -959,7 +959,7 @@ nsComponentManagerImpl::HashProgID(const char *aProgID, const nsCID &aClass) return NS_ERROR_NULL_POINTER; } - nsStringKey key(aProgID); + nsCStringKey key(aProgID); nsCID* cid = (nsCID*) mProgIDs->Get(&key); if (cid) { @@ -1120,7 +1120,7 @@ nsComponentManagerImpl::ProgIDToClassID(const char *aProgID, nsCID *aClass) nsresult res = NS_ERROR_FACTORY_NOT_REGISTERED; #ifdef USE_REGISTRY - nsStringKey key(aProgID); + nsCStringKey key(aProgID); nsCID* cid = (nsCID*) mProgIDs->Get(&key); if (cid) { if (cid == &kNoCID) { @@ -1674,7 +1674,7 @@ nsresult nsComponentManagerImpl::GetLoaderForType(const char *aType, nsIComponentLoader **aLoader) { - nsStringKey typeKey(aType); + nsCStringKey typeKey(aType); nsresult rv; nsCOMPtr loader; @@ -2229,14 +2229,8 @@ ConvertProgIDKeyToString(nsHashKey *key, void *data, void *convert_data, (void **)&strHolder); if(NS_SUCCEEDED(rv)) { - nsStringKey *strKey = (nsStringKey *) key; - const nsString& str = strKey->GetString(); - char* yetAnotherCopyOfTheString = str.ToNewCString(); - if(yetAnotherCopyOfTheString) - { - strHolder->SetData(yetAnotherCopyOfTheString); - delete [] yetAnotherCopyOfTheString; - } + nsCStringKey *strKey = (nsCStringKey *) key; + strHolder->SetData(strKey->GetString()); *retval = strHolder; } else diff --git a/mozilla/xpcom/components/nsNativeComponentLoader.cpp b/mozilla/xpcom/components/nsNativeComponentLoader.cpp index fb20da487e4..85d21d7b81d 100644 --- a/mozilla/xpcom/components/nsNativeComponentLoader.cpp +++ b/mozilla/xpcom/components/nsNativeComponentLoader.cpp @@ -785,7 +785,7 @@ nsNativeComponentLoader::AutoRegisterComponent(PRInt32 when, if (NS_FAILED(rv)) return rv; - nsStringKey key(persistentDescriptor); + nsCStringKey key(persistentDescriptor); // Get the registry representation of the dll, if any nsDll *dll; @@ -1108,7 +1108,7 @@ nsNativeComponentLoader::CreateDll(nsIFile *aSpec, const char *aLocation, nsCOMPtr spec; nsresult rv; - nsStringKey key(aLocation); + nsCStringKey key(aLocation); dll = (nsDll *)mDllStore->Get(&key); if (dll) { diff --git a/mozilla/xpcom/ds/nsAtomTable.cpp b/mozilla/xpcom/ds/nsAtomTable.cpp index 93a8c1197b3..1c1e71bd3c8 100644 --- a/mozilla/xpcom/ds/nsAtomTable.cpp +++ b/mozilla/xpcom/ds/nsAtomTable.cpp @@ -126,7 +126,7 @@ AtomImpl::SizeOf(nsISizeOfHandler* aHandler, PRUint32* _retval) /*FIX: const */ static PLHashNumber HashKey(const PRUnichar* k) { - return (PLHashNumber) nsCRT::HashValue(k); + return (PLHashNumber) nsCRT::HashCode(k, nsCRT::strlen(k)); } static PRIntn CompareKeys(const PRUnichar* k1, const PRUnichar* k2) @@ -155,8 +155,8 @@ NS_COM nsIAtom* NS_NewAtom(const PRUnichar* us) (PLHashComparator) nsnull, nsnull, nsnull); } - PRUint32 uslen; - PRUint32 hashCode = nsCRT::HashValue(us, &uslen); + PRUint32 uslen = nsCRT::strlen(us); + PRUint32 hashCode = nsCRT::HashCode(us, uslen); PLHashEntry** hep = PL_HashTableRawLookup(gAtomHashTable, hashCode, us); PLHashEntry* he = *hep; if (nsnull != he) { diff --git a/mozilla/xpcom/ds/nsCRT.cpp b/mozilla/xpcom/ds/nsCRT.cpp index 688b6c58634..811a51f3742 100644 --- a/mozilla/xpcom/ds/nsCRT.cpp +++ b/mozilla/xpcom/ds/nsCRT.cpp @@ -486,9 +486,13 @@ PRInt32 nsCRT::strncasecmp(const PRUnichar* s1, const char* s2, PRUint32 n) { PRUnichar* nsCRT::strdup(const PRUnichar* str) { - PRUint32 len = nsCRT::strlen(str) + 1; // add one for null - + PRUint32 len = nsCRT::strlen(str); + return strndup(str, len); +} +PRUnichar* nsCRT::strndup(const PRUnichar* str, PRUint32 len) +{ + len += 1; // add one for the null nsCppSharedAllocator shared_allocator; PRUnichar* rslt = shared_allocator.allocate(len); // PRUnichar* rslt = new PRUnichar[len]; @@ -498,6 +502,7 @@ PRUnichar* nsCRT::strdup(const PRUnichar* str) return rslt; } +#if 0 PRUint32 nsCRT::HashValue(const char* us) { PRUint32 rv = 0; @@ -551,6 +556,47 @@ PRUint32 nsCRT::HashValue(const PRUnichar* us, PRUint32* uslenp) *uslenp = len; return rv; } +#endif + +PRUint32 +nsCRT::HashCode(const char* c, PRUint32 n) +{ + PRUint32 h = 0; + NS_ASSERTION(n >= 0, "bad string length"); + + // Same hashing technique as for java.lang.String.hashCode() + if (n < 16) { + // A short key; Use a dense sampling to compute the hash code + for(; n; c++, n--) + h = (h >> 28) ^ (h << 4) ^ *c; + } + else { + // A long key; Use a sparse sampling to compute the hash code + for(PRUint32 m = n >> 3; n >= m; c += m, n -= m) + h = (h >> 28) ^ (h << 4) ^ *c; + } + return h; +} + +PRUint32 +nsCRT::HashCode(const PRUnichar* c, PRUint32 n) +{ + PRUint32 h = 0; + NS_ASSERTION(n >= 0, "bad string length"); + + // Same hashing technique as for java.lang.String.hashCode() + if (n < 16) { + // A short key; Use a dense sampling to compute the hash code + for(; n; c++, n--) + h = (h >> 28) ^ (h << 4) ^ *c; + } + else { + // A long key; Use a sparse sampling to compute the hash code + for(PRUint32 m = n >> 3; n >= m; c += m, n -= m) + h = (h >> 28) ^ (h << 4) ^ *c; + } + return h; +} PRInt32 nsCRT::atoi( const PRUnichar *string ) { diff --git a/mozilla/xpcom/ds/nsCRT.h b/mozilla/xpcom/ds/nsCRT.h index 60e8539c6e5..259cb9abf07 100644 --- a/mozilla/xpcom/ds/nsCRT.h +++ b/mozilla/xpcom/ds/nsCRT.h @@ -108,6 +108,11 @@ public: ::memcpy(aDest, aSrc, (size_t)aCount); } + static PRInt32 memcmp(void* aDest, const void* aSrc, PRUint32 aCount) { + NS_ASSERTION((aDest != NULL && aSrc != NULL) || (aCount == 0), "Invalid NULL argument"); + return ::memcmp(aDest, aSrc, (size_t)aCount); + } + static void memmove(void* aDest, const void* aSrc, PRUint32 aCount) { NS_ASSERTION((aDest != NULL && aSrc != NULL) || (aCount == 0), "Invalid NULL argument"); ::memmove(aDest, aSrc, (size_t)aCount); @@ -167,6 +172,10 @@ public: return PL_strdup(str); } + static char* strndup(const char* str, PRUint32 len) { + return PL_strndup(str, len); + } + static void free(char* str) { PL_strfree(str); } @@ -223,11 +232,13 @@ public: // free the memory static PRUnichar* strdup(const PRUnichar* str); + static PRUnichar* strndup(const PRUnichar* str, PRUint32 len); + static void free(PRUnichar* str) { nsCppSharedAllocator shared_allocator; shared_allocator.deallocate(str, 0 /*we never new or kept the size*/); } - +#if 0 /// Compute a hashcode for a C string static PRUint32 HashValue(const char* s1); @@ -239,6 +250,9 @@ public: /// Same as above except that we return the length in s1len static PRUint32 HashValue(const PRUnichar* s1, PRUint32* s1len); +#endif + static PRUint32 HashCode(const char* str, PRUint32 strLen); + static PRUint32 HashCode(const PRUnichar* str, PRUint32 strLen); /// String to integer. static PRInt32 atoi( const PRUnichar *string ); diff --git a/mozilla/xpcom/ds/nsHashtable.cpp b/mozilla/xpcom/ds/nsHashtable.cpp index 153cae58b9b..f6683746760 100644 --- a/mozilla/xpcom/ds/nsHashtable.cpp +++ b/mozilla/xpcom/ds/nsHashtable.cpp @@ -34,13 +34,107 @@ #include "prlog.h" #include "nsHashtable.h" +//////////////////////////////////////////////////////////////////////////////// +// These functions really should be part of nspr, and have internal knowledge +// of its workings. They allow the PLHashTable to be embedded in the structure +// of the nsHashtable, thereby avoiding a secondary allocation. I've added them +// here because we don't have the "right" to add anything to nspr at this point. + +#include "prbit.h" + +/* Compute the number of buckets in ht */ +#define NBUCKETS(ht) (1 << (PL_HASH_BITS - (ht)->shift)) + +/* The smallest table has 16 buckets */ +#define MINBUCKETSLOG2 4 +#define MINBUCKETS (1 << MINBUCKETSLOG2) + +/* Compute the maximum entries given n buckets that we will tolerate, ~90% */ +#define OVERLOADED(n) ((n) - ((n) >> 3)) + +/* Compute the number of entries below which we shrink the table by half */ +#define UNDERLOADED(n) (((n) > MINBUCKETS) ? ((n) >> 2) : 0) + +PR_IMPLEMENT(PRStatus) +PL_HashTableInit(PLHashTable *ht, PRUint32 n, PLHashFunction keyHash, + PLHashComparator keyCompare, PLHashComparator valueCompare, + const PLHashAllocOps *allocOps, void *allocPriv) +{ + PRSize nb; + + if (n <= MINBUCKETS) { + n = MINBUCKETSLOG2; + } else { + n = PR_CeilingLog2(n); + if ((PRInt32)n < 0) + return PR_FAILURE; + } + +#if 0 // if we were in nspr... + if (!allocOps) allocOps = &defaultHashAllocOps; +#else + PR_ASSERT(allocOps); +#endif + + memset(ht, 0, sizeof *ht); + ht->shift = PL_HASH_BITS - n; + n = 1 << n; +#if defined(WIN16) + if (n > 16000) { + (*allocOps->freeTable)(allocPriv, ht); + return PR_FAILURE; + } +#endif /* WIN16 */ + nb = n * sizeof(PLHashEntry *); + ht->buckets = (PLHashEntry**)((*allocOps->allocTable)(allocPriv, nb)); + if (!ht->buckets) { + (*allocOps->freeTable)(allocPriv, ht); + return PR_FAILURE; + } + memset(ht->buckets, 0, nb); + + ht->keyHash = keyHash; + ht->keyCompare = keyCompare; + ht->valueCompare = valueCompare; + ht->allocOps = allocOps; + ht->allocPriv = allocPriv; + return PR_SUCCESS; +} + +PR_IMPLEMENT(void) +PL_HashTableFinalize(PLHashTable *ht) +{ + PRUint32 i, n; + PLHashEntry *he, *next; + const PLHashAllocOps *allocOps = ht->allocOps; + void *allocPriv = ht->allocPriv; + + n = NBUCKETS(ht); + for (i = 0; i < n; i++) { + for (he = ht->buckets[i]; he; he = next) { + next = he->next; + (*allocOps->freeEntry)(allocPriv, he, HT_FREE_ENTRY); + } + } +#ifdef DEBUG + memset(ht->buckets, 0xDB, n * sizeof ht->buckets[0]); +#endif + (*allocOps->freeTable)(allocPriv, ht->buckets); +#ifdef DEBUG + memset(ht, 0xDB, sizeof *ht); +#endif +} + +// end of nspr stuff +//////////////////////////////////////////////////////////////////////////////// + // // Key operations // static PLHashNumber PR_CALLBACK _hashValue(const void *key) { - return ((const nsHashKey *) key)->HashValue(); + return ((const nsHashKey *) key)->HashCode(); } static PRIntn PR_CALLBACK _hashKeyCompare(const void *key1, const void *key2) { @@ -107,6 +201,9 @@ MOZ_DECL_CTOR_COUNTER(nsHashKey); nsHashKey::nsHashKey(void) { +#ifdef DEBUG + mKeyType = UnknownKey; +#endif MOZ_COUNT_CTOR(nsHashKey); } @@ -121,12 +218,14 @@ nsHashtable::nsHashtable(PRUint32 aInitSize, PRBool threadSafe) : mLock(NULL) { MOZ_COUNT_CTOR(nsHashtable); - hashtable = PL_NewHashTable(aInitSize, - _hashValue, - _hashKeyCompare, - _hashValueCompare, - &_hashAllocOps, - NULL); + PRStatus status = PL_HashTableInit(&mHashtable, + aInitSize, + _hashValue, + _hashKeyCompare, + _hashValueCompare, + &_hashAllocOps, + NULL); + PR_ASSERT(status == PR_SUCCESS); if (threadSafe == PR_TRUE) { mLock = PR_NewLock(); @@ -141,17 +240,17 @@ nsHashtable::nsHashtable(PRUint32 aInitSize, PRBool threadSafe) nsHashtable::~nsHashtable() { MOZ_COUNT_DTOR(nsHashtable); - PL_HashTableDestroy(hashtable); + PL_HashTableFinalize(&mHashtable); if (mLock) PR_DestroyLock(mLock); } PRBool nsHashtable::Exists(nsHashKey *aKey) { - PLHashNumber hash = aKey->HashValue(); + PLHashNumber hash = aKey->HashCode(); if (mLock) PR_Lock(mLock); - PLHashEntry **hep = PL_HashTableRawLookup(hashtable, hash, (void *) aKey); + PLHashEntry **hep = PL_HashTableRawLookup(&mHashtable, hash, (void *) aKey); if (mLock) PR_Unlock(mLock); @@ -160,19 +259,24 @@ PRBool nsHashtable::Exists(nsHashKey *aKey) void *nsHashtable::Put(nsHashKey *aKey, void *aData) { void *res = NULL; - PLHashNumber hash = aKey->HashValue(); + PLHashNumber hash = aKey->HashCode(); PLHashEntry *he; if (mLock) PR_Lock(mLock); - PLHashEntry **hep = PL_HashTableRawLookup(hashtable, hash, (void *) aKey); + PLHashEntry **hep = PL_HashTableRawLookup(&mHashtable, hash, (void *) aKey); if ((he = *hep) != NULL) { res = he->value; he->value = aData; } else { - PL_HashTableRawAdd(hashtable, hep, hash, - (void *) aKey->Clone(), aData); + nsHashKey* key = aKey->Clone(); + if (key) { + PL_HashTableRawAdd(&mHashtable, hep, hash, + (void *)key, aData); + } + else + res = NULL; } if (mLock) PR_Unlock(mLock); @@ -184,7 +288,7 @@ void *nsHashtable::Get(nsHashKey *aKey) { if (mLock) PR_Lock(mLock); - void *ret = PL_HashTableLookup(hashtable, (void *) aKey); + void *ret = PL_HashTableLookup(&mHashtable, (void *) aKey); if (mLock) PR_Unlock(mLock); @@ -192,17 +296,17 @@ void *nsHashtable::Get(nsHashKey *aKey) { } void *nsHashtable::Remove(nsHashKey *aKey) { - PLHashNumber hash = aKey->HashValue(); + PLHashNumber hash = aKey->HashCode(); PLHashEntry *he; if (mLock) PR_Lock(mLock); - PLHashEntry **hep = PL_HashTableRawLookup(hashtable, hash, (void *) aKey); + PLHashEntry **hep = PL_HashTableRawLookup(&mHashtable, hash, (void *) aKey); void *res = NULL; if ((he = *hep) != NULL) { res = he->value; - PL_HashTableRawRemove(hashtable, hep, he); + PL_HashTableRawRemove(&mHashtable, hep, he); } if (mLock) PR_Unlock(mLock); @@ -224,9 +328,9 @@ nsHashtable * nsHashtable::Clone() { PRBool threadSafe = PR_FALSE; if (mLock) threadSafe = PR_TRUE; - nsHashtable *newHashTable = new nsHashtable(hashtable->nentries, threadSafe); + nsHashtable *newHashTable = new nsHashtable(mHashtable.nentries, threadSafe); - PL_HashTableEnumerateEntries(hashtable, _hashEnumerateShare, newHashTable); + PL_HashTableEnumerateEntries(&mHashtable, _hashEnumerateShare, newHashTable); return newHashTable; } @@ -234,7 +338,7 @@ void nsHashtable::Enumerate(nsHashtableEnumFunc aEnumFunc, void* closure) { _HashEnumerateArgs thunk; thunk.fn = aEnumFunc; thunk.arg = closure; - PL_HashTableEnumerateEntries(hashtable, _hashEnumerate, &thunk); + PL_HashTableEnumerateEntries(&mHashtable, _hashEnumerate, &thunk); } static PRIntn PR_CALLBACK _hashEnumerateRemove(PLHashEntry *he, PRIntn i, void *arg) @@ -259,61 +363,130 @@ void nsHashtable::Reset(nsHashtableEnumFunc destroyFunc, void* closure) _HashEnumerateArgs thunk; thunk.fn = destroyFunc; thunk.arg = closure; - PL_HashTableEnumerateEntries(hashtable, _hashEnumerateRemove, &thunk); + PL_HashTableEnumerateEntries(&mHashtable, _hashEnumerateRemove, &thunk); } else - PL_HashTableEnumerateEntries(hashtable, _hashEnumerateRemove, NULL); + PL_HashTableEnumerateEntries(&mHashtable, _hashEnumerateRemove, NULL); } //////////////////////////////////////////////////////////////////////////////// -nsStringKey::nsStringKey(const char* str) +nsCStringKey::nsCStringKey(const nsCString& str) + : mStr((char*)str.GetBuffer()), mStrLen(str.Length()), mOwnsStr(PR_FALSE) { - MOZ_COUNT_CTOR(nsStringKey); - mStr.AssignWithConversion(str); + NS_ASSERTION(mStr, "null string key"); + NS_ASSERTION(mStrLen == nsCRT::strlen(mStr), "bad string length"); +#ifdef DEBUG + mKeyType = CStringKey; +#endif + MOZ_COUNT_CTOR(nsCStringKey); } -nsStringKey::nsStringKey(const PRUnichar* str) +nsCStringKey::nsCStringKey(const char* str, PRUint32 strLen, PRBool ownsStr) + : mStr((char*)str), mStrLen(strLen), mOwnsStr(ownsStr) { - MOZ_COUNT_CTOR(nsStringKey); - mStr.Assign(str); + NS_ASSERTION(mStr, "null string key"); + if (mStrLen == -1) + mStrLen = nsCRT::strlen(str); +#ifdef DEBUG + mKeyType = CStringKey; +#endif + MOZ_COUNT_CTOR(nsCStringKey); } -nsStringKey::nsStringKey(const nsString& str) { - MOZ_COUNT_CTOR(nsStringKey); - mStr.Assign(str); +nsCStringKey::~nsCStringKey(void) +{ + if (mOwnsStr) + nsMemory::Free(mStr); + MOZ_COUNT_DTOR(nsCStringKey); } -nsStringKey::nsStringKey(const nsCString& str) { - MOZ_COUNT_CTOR(nsStringKey); - mStr.AssignWithConversion(str); +PRUint32 +nsCStringKey::HashCode(void) const +{ + return nsCRT::HashCode(mStr, mStrLen); +} + +PRBool +nsCStringKey::Equals(const nsHashKey* aKey) const +{ + NS_ASSERTION(aKey->GetKeyType() == CStringKey, "mismatched key types"); + nsCStringKey* other = (nsCStringKey*)aKey; + if (mStrLen != other->mStrLen) + return PR_FALSE; + return nsCRT::memcmp(mStr, other->mStr, mStrLen) == 0; +} + +nsHashKey* +nsCStringKey::Clone() const +{ + PRUint32 len = mStrLen * sizeof(char); + char* str = (char*)nsMemory::Alloc(len); + if (str == NULL) + return NULL; + nsCRT::memcpy(str, mStr, len); + return new nsCStringKey(str, mStrLen, PR_TRUE); +} + +//////////////////////////////////////////////////////////////////////////////// + +nsStringKey::nsStringKey(const nsString& str) + : mStr((PRUnichar*)str.GetUnicode()), mStrLen(str.Length()), mOwnsStr(PR_FALSE) +{ + NS_ASSERTION(mStr, "null string key"); + NS_ASSERTION(mStrLen == nsCRT::strlen(mStr), "bad string length"); +#ifdef DEBUG + mKeyType = StringKey; +#endif + MOZ_COUNT_CTOR(nsStringKey); +} + +nsStringKey::nsStringKey(const PRUnichar* str, PRUint32 strLen, PRBool ownsStr) + : mStr((PRUnichar*)str), mStrLen(strLen), mOwnsStr(ownsStr) +{ + NS_ASSERTION(mStr, "null string key"); + if (mStrLen == -1) + mStrLen = nsCRT::strlen(str); +#ifdef DEBUG + mKeyType = StringKey; +#endif + MOZ_COUNT_CTOR(nsStringKey); } nsStringKey::~nsStringKey(void) { - MOZ_COUNT_DTOR(nsStringKey); + if (mOwnsStr) + nsMemory::Free(mStr); + MOZ_COUNT_DTOR(nsStringKey); } -PRUint32 nsStringKey::HashValue(void) const +PRUint32 +nsStringKey::HashCode(void) const { - return nsStr::HashCode(mStr); + return nsCRT::HashCode(mStr, mStrLen); } -PRBool nsStringKey::Equals(const nsHashKey* aKey) const +PRBool +nsStringKey::Equals(const nsHashKey* aKey) const { - return ((nsStringKey*)aKey)->mStr == mStr; + NS_ASSERTION(aKey->GetKeyType() == StringKey, "mismatched key types"); + nsStringKey* other = (nsStringKey*)aKey; + if (mStrLen != other->mStrLen) + return PR_FALSE; + return nsCRT::memcmp(mStr, other->mStr, mStrLen) == 0; } -nsHashKey* nsStringKey::Clone() const +nsHashKey* +nsStringKey::Clone() const { - return new nsStringKey(mStr); + PRUint32 len = mStrLen * sizeof(PRUnichar); + PRUnichar* str = (PRUnichar*)nsMemory::Alloc(len); + if (str == NULL) + return NULL; + nsCRT::memcpy(str, mStr, len); + return new nsStringKey(str, mStrLen, PR_TRUE); } -const nsString& nsStringKey::GetString() const -{ - return mStr; -} - //////////////////////////////////////////////////////////////////////////////// // nsObjectHashtable: an nsHashtable where the elements are C++ objects to be // deleted @@ -358,9 +531,9 @@ nsObjectHashtable::Clone() nsObjectHashtable* newHashTable = new nsObjectHashtable(mCloneElementFun, mCloneElementClosure, mDestroyElementFun, mDestroyElementClosure, - hashtable->nentries, threadSafe); + mHashtable.nentries, threadSafe); - PL_HashTableEnumerateEntries(hashtable, CopyElement, newHashTable); + PL_HashTableEnumerateEntries(&mHashtable, CopyElement, newHashTable); return newHashTable; } @@ -401,7 +574,7 @@ nsSupportsHashtable::~nsSupportsHashtable() // Return if we overwrote something PRBool -nsSupportsHashtable::Put (nsHashKey *aKey, nsISupports* aData, nsISupports **value) +nsSupportsHashtable::Put(nsHashKey *aKey, nsISupports* aData, nsISupports **value) { NS_IF_ADDREF(aData); void *prev = nsHashtable::Put(aKey, aData); @@ -455,9 +628,9 @@ nsSupportsHashtable::Clone() if (mLock) threadSafe = PR_TRUE; nsSupportsHashtable* newHashTable = - new nsSupportsHashtable(hashtable->nentries, threadSafe); + new nsSupportsHashtable(mHashtable.nentries, threadSafe); - PL_HashTableEnumerateEntries(hashtable, EnumerateCopy, newHashTable); + PL_HashTableEnumerateEntries(&mHashtable, EnumerateCopy, newHashTable); return newHashTable; } @@ -469,68 +642,4 @@ nsSupportsHashtable::Reset() } //////////////////////////////////////////////////////////////////////////////// -// nsOpaqueKey: Where keys are opaque byte array blobs -// - -// Note opaque keys are not copied by this constructor. If you want a private -// copy in each hash key, you must create one and pass it in to this function. -nsOpaqueKey::nsOpaqueKey(const char *aOpaqueKey, PRUint32 aKeyLength) -{ - mOpaqueKey = aOpaqueKey; - mKeyLength = aKeyLength; -} - -nsOpaqueKey::~nsOpaqueKey(void) -{ -} - -PRUint32 -nsOpaqueKey::HashValue(void) const -{ - PRUint32 h, i, k; - - h = 0; - - // Same hashing technique as for java.lang.String.hashCode() - if (mKeyLength <= 15) { - // A short key; Use a dense sampling to compute the hash code - for (i = 0; i < mKeyLength; i++) - h += 37 * mOpaqueKey[i]; - } else { - // A long key; Use a sparse sampling to compute the hash code - k = mKeyLength >> 3; - for (i = 0; i < mKeyLength; i += k) - h += 39 * mOpaqueKey[i]; - } - return h; -} - -PRBool -nsOpaqueKey::Equals(const nsHashKey* aKey) const -{ - nsOpaqueKey *otherKey = (nsOpaqueKey*)aKey; - if (mKeyLength != otherKey->mKeyLength) - return PR_FALSE; - return !(PRBool)memcmp(otherKey->mOpaqueKey, mOpaqueKey, mKeyLength); -} - -nsHashKey* -nsOpaqueKey::Clone() const -{ - return new nsOpaqueKey(mOpaqueKey, mKeyLength); -} - -PRUint32 -nsOpaqueKey::GetKeyLength() const -{ - return mKeyLength; -} - -const char* -nsOpaqueKey::GetKey() const -{ - return mOpaqueKey; -} - -//////////////////////////////////////////////////////////////////////////////// diff --git a/mozilla/xpcom/ds/nsHashtable.h b/mozilla/xpcom/ds/nsHashtable.h index b3a655f95b9..33f650253ef 100644 --- a/mozilla/xpcom/ds/nsHashtable.h +++ b/mozilla/xpcom/ds/nsHashtable.h @@ -35,17 +35,37 @@ #include "plhash.h" #include "prlock.h" -#include "nsCom.h" +#include "nscom.h" #include "nscore.h" +class nsHashtable; +class nsStringKey; + class NS_COM nsHashKey { protected: nsHashKey(void); + public: virtual ~nsHashKey(void); - virtual PRUint32 HashValue(void) const = 0; + virtual PRUint32 HashCode(void) const = 0; virtual PRBool Equals(const nsHashKey *aKey) const = 0; - virtual nsHashKey *Clone(void) const = 0; + virtual nsHashKey *Clone() const = 0; + +#ifdef DEBUG +public: + // used for verification that we're casting to the correct key type + enum nsHashKeyType { + UnknownKey, + SupportsKey, + VoidKey, + IDKey, + CStringKey, + StringKey, + }; + nsHashKeyType GetKeyType() const { return mKeyType; } +protected: + nsHashKeyType mKeyType; +#endif }; // Enumerator callback function. Use @@ -55,14 +75,14 @@ typedef PRBool (*PR_CALLBACK nsHashtableEnumFunc)(nsHashKey *aKey, void *aData, class NS_COM nsHashtable { protected: // members - PLHashTable *hashtable; - PRLock *mLock; + PLHashTable mHashtable; + PRLock* mLock; public: nsHashtable(PRUint32 aSize = 256, PRBool threadSafe = PR_FALSE); virtual ~nsHashtable(); - PRInt32 Count(void) { return hashtable->nentries; } + PRInt32 Count(void) { return mHashtable.nentries; } PRBool Exists(nsHashKey *aKey); void *Put(nsHashKey *aKey, void *aData); void *Get(nsHashKey *aKey); @@ -152,6 +172,9 @@ protected: public: nsISupportsKey(nsISupports* key) { +#ifdef DEBUG + mKeyType = SupportsKey; +#endif mKey = key; NS_IF_ADDREF(mKey); } @@ -160,15 +183,16 @@ public: NS_IF_RELEASE(mKey); } - PRUint32 HashValue(void) const { + PRUint32 HashCode(void) const { return (PRUint32)mKey; } PRBool Equals(const nsHashKey *aKey) const { + NS_ASSERTION(aKey->GetKeyType() == SupportsKey, "mismatched key types"); return (mKey == ((nsISupportsKey *) aKey)->mKey); } - nsHashKey *Clone(void) const { + nsHashKey *Clone() const { return new nsISupportsKey(mKey); } }; @@ -178,24 +202,30 @@ public: class nsVoidKey : public nsHashKey { protected: - const void* mKey; + void* mKey; public: - nsVoidKey(const void* key) { + nsVoidKey(void* key) { +#ifdef DEBUG + mKeyType = VoidKey; +#endif mKey = key; } - PRUint32 HashValue(void) const { + PRUint32 HashCode(void) const { return (PRUint32)mKey; } PRBool Equals(const nsHashKey *aKey) const { + NS_ASSERTION(aKey->GetKeyType() == VoidKey, "mismatched key types"); return (mKey == ((const nsVoidKey *) aKey)->mKey); } - nsHashKey *Clone(void) const { + nsHashKey *Clone() const { return new nsVoidKey(mKey); } + + void* GetValue() { return mKey; } }; //////////////////////////////////////////////////////////////////////////////// @@ -209,18 +239,22 @@ protected: public: nsIDKey(const nsID &aID) { +#ifdef DEBUG + mKeyType = IDKey; +#endif mID = aID; } - PRUint32 HashValue(void) const { + PRUint32 HashCode(void) const { return mID.m0; } PRBool Equals(const nsHashKey *aKey) const { + NS_ASSERTION(aKey->GetKeyType() == IDKey, "mismatched key types"); return (mID.Equals(((const nsIDKey *) aKey)->mID)); } - nsHashKey *Clone(void) const { + nsHashKey *Clone() const { return new nsIDKey(mID); } }; @@ -231,54 +265,54 @@ public: #include "nsString.h" -class NS_COM nsStringKey : public nsHashKey { -protected: - nsAutoString mStr; - +class NS_COM nsCStringKey : public nsHashKey { public: - nsStringKey(const char* str); - nsStringKey(const PRUnichar* str); - nsStringKey(const nsString& str); - nsStringKey(const nsCString& str); - - ~nsStringKey(void); - - PRUint32 HashValue(void) const; + // If strLen is not passed, and defaults to -1, the assumption here is that str + // does not contain embedded nulls, i.e. nsCRT::strlen will be used to determine the + // length. If ownsString is true, destroying the string key will destroy str: + nsCStringKey(const char* str, PRUint32 strLen = -1, PRBool ownsStr = PR_FALSE); + nsCStringKey(const nsCString& str); + ~nsCStringKey(void); + PRUint32 HashCode(void) const; PRBool Equals(const nsHashKey* aKey) const; - nsHashKey* Clone() const; // For when the owner of the hashtable wants to peek at the actual // string in the key. No copy is made, so be careful. - const nsString& GetString() const; + const char* GetString() const { return mStr; } + PRUint32 GetStringLength() const { return mStrLen; } + +protected: + char* mStr; + PRUint32 mStrLen; + PRBool mOwnsStr; }; -//////////////////////////////////////////////////////////////////////////////// -// nsOpaqueKey: Where keys are opaque byte-array blobs - -#include "nsString.h" - -class NS_COM nsOpaqueKey : public nsHashKey { -protected: - const char* mOpaqueKey; // Byte array of opaque data - PRUint32 mKeyLength; // Length, in bytes, of mOpaqueKey - +class NS_COM nsStringKey : public nsHashKey { public: - // Note opaque keys are not copied by this constructor. If you want a private - // copy in each hash key, you must create one and pass it in to this function. - nsOpaqueKey(const char* aOpaqueKey, PRUint32 aKeyLength); + // If strLen is not passed, and defaults to -1, the assumption here is that str + // does not contain embedded nulls, i.e. nsCRT::strlen will be used to determine the + // length. If ownsString is true, destroying the string key will destroy str: + nsStringKey(const PRUnichar* str, PRUint32 strLen = -1, PRBool ownsStr = PR_FALSE); + nsStringKey(const nsString& str); + ~nsStringKey(void); - ~nsOpaqueKey(void); - - PRUint32 HashValue(void) const; + PRUint32 HashCode(void) const; PRBool Equals(const nsHashKey* aKey) const; nsHashKey* Clone() const; // For when the owner of the hashtable wants to peek at the actual - // opaque array in the key. No copy is made, so be careful. - const char* GetKey() const; - PRUint32 GetKeyLength() const; + // string in the key. No copy is made, so be careful. + const PRUnichar* GetString() const { return mStr; } + PRUint32 GetStringLength() const { return mStrLen; } + +protected: + PRUnichar* mStr; + PRUint32 mStrLen; + PRBool mOwnsStr; }; +//////////////////////////////////////////////////////////////////////////////// + #endif diff --git a/mozilla/xpcom/ds/nsPersistentProperties.cpp b/mozilla/xpcom/ds/nsPersistentProperties.cpp index 5b52b01092f..4e8c6ebed32 100644 --- a/mozilla/xpcom/ds/nsPersistentProperties.cpp +++ b/mozilla/xpcom/ds/nsPersistentProperties.cpp @@ -36,7 +36,7 @@ static PLHashNumber HashKey(const PRUnichar *aString) { - return (PLHashNumber) nsCRT::HashValue(aString); + return (PLHashNumber) nsCRT::HashCode(aString, nsCRT::strlen(aString)); } static PRIntn @@ -224,8 +224,8 @@ nsPersistentProperties::SetStringProperty(const nsString& aKey, nsString& aNewVa } const PRUnichar *key = aKey.GetUnicode(); // returns internal pointer (not a copy) - PRUint32 len; - PRUint32 hashValue = nsCRT::HashValue(key, &len); + PRUint32 len = nsCRT::strlen(key); + PRUint32 hashValue = nsCRT::HashCode(key, len); PLHashEntry **hep = PL_HashTableRawLookup(mTable, hashValue, key); PLHashEntry *he = *hep; if (he) { @@ -271,8 +271,8 @@ nsPersistentProperties::GetStringProperty(const nsString& aKey, nsString& aValue return NS_ERROR_FAILURE; } - PRUint32 len; - PRUint32 hashValue = nsCRT::HashValue(key, &len); + PRUint32 len = nsCRT::strlen(key); + PRUint32 hashValue = nsCRT::HashCode(key, len); PLHashEntry **hep = PL_HashTableRawLookup(mTable, hashValue, key); PLHashEntry *he = *hep; if (he) { diff --git a/mozilla/xpcom/ds/nsProperties.cpp b/mozilla/xpcom/ds/nsProperties.cpp index b1551b1d715..228f6ce2e4a 100644 --- a/mozilla/xpcom/ds/nsProperties.cpp +++ b/mozilla/xpcom/ds/nsProperties.cpp @@ -86,7 +86,7 @@ nsProperties::AggregatedQueryInterface(const nsIID& aIID, void** aInstancePtr) NS_IMETHODIMP nsProperties::Define(const char* prop, nsISupports* initialValue) { - nsStringKey key(prop); + nsCStringKey key(prop); if (Exists(&key)) return NS_ERROR_FAILURE; @@ -99,7 +99,7 @@ nsProperties::Define(const char* prop, nsISupports* initialValue) NS_IMETHODIMP nsProperties::Undefine(const char* prop) { - nsStringKey key(prop); + nsCStringKey key(prop); if (!Exists(&key)) return NS_ERROR_FAILURE; @@ -112,7 +112,7 @@ NS_IMETHODIMP nsProperties::Get(const char* prop, const nsIID & uuid, void* *result) { nsresult rv; - nsStringKey key(prop); + nsCStringKey key(prop); nsISupports* value = (nsISupports*)nsHashtable::Get(&key); if (value) { rv = value->QueryInterface(uuid, result); @@ -126,7 +126,7 @@ nsProperties::Get(const char* prop, const nsIID & uuid, void* *result) NS_IMETHODIMP nsProperties::Set(const char* prop, nsISupports* value) { - nsStringKey key(prop); + nsCStringKey key(prop); if (!Exists(&key)) return NS_ERROR_FAILURE; @@ -139,7 +139,7 @@ nsProperties::Set(const char* prop, nsISupports* value) NS_IMETHODIMP nsProperties::Has(const char* prop, PRBool *result) { - nsStringKey key(prop); + nsCStringKey key(prop); nsISupports* value = (nsISupports*)nsHashtable::Get(&key); // XXX this is bogus because it doesn't distinguish between properties // defined with a value NULL, and undefined properties, but we'll fix diff --git a/mozilla/xpcom/ds/nsStr.cpp b/mozilla/xpcom/ds/nsStr.cpp index 67e02a2dce9..0f300bf9281 100644 --- a/mozilla/xpcom/ds/nsStr.cpp +++ b/mozilla/xpcom/ds/nsStr.cpp @@ -780,25 +780,10 @@ CBufDescriptor::CBufDescriptor(const PRUnichar* aString,PRBool aStackBased,PRUin PRUint32 nsStr::HashCode(const nsStr& aDest) { - if (aDest.mCharSize == eTwoByte) { - PRUint32 h; - PRUint32 n = aDest.mLength; - PRUint32 m; - const PRUnichar* c; - h = 0; - - c = aDest.mUStr; - if (n < 16) { /* Hash every char in a short string. */ - for(; n; c++, n--) - h = (h >> 28) ^ (h << 4) ^ *c; - } - else { /* Sample a la java.lang.String.hash(). */ - for(m = n / 8; n >= m; c += m, n -= m) - h = (h >> 28) ^ (h << 4) ^ *c; - } - return h; - } - return (PRUint32)PL_HashString((const void*) aDest.mStr); + if (aDest.mCharSize == eTwoByte) + return nsCRT::HashCode(aDest.mUStr, aDest.mLength); + else + return nsCRT::HashCode(aDest.mStr, aDest.mLength); } #ifdef NS_STR_STATS diff --git a/mozilla/xpcom/ds/nsStr.h b/mozilla/xpcom/ds/nsStr.h index f8c392345da..d876eee8b70 100644 --- a/mozilla/xpcom/ds/nsStr.h +++ b/mozilla/xpcom/ds/nsStr.h @@ -431,7 +431,6 @@ struct NS_COM nsStr { */ static PRUint32 HashCode(const nsStr& aDest); - #ifndef NEW_STRING_APIS static void Append(nsStr& aDest,const nsStr& aSource,PRUint32 anOffset,PRInt32 aCount) { StrAppend(aDest, aSource, anOffset, aCount); diff --git a/mozilla/xpcom/io/nsDirectoryService.cpp b/mozilla/xpcom/io/nsDirectoryService.cpp index fc4299eb6ff..dddd04b3ae5 100644 --- a/mozilla/xpcom/io/nsDirectoryService.cpp +++ b/mozilla/xpcom/io/nsDirectoryService.cpp @@ -510,7 +510,7 @@ nsDirectoryService::Define(const char* prop, nsISupports* initialValue) NS_IMETHODIMP nsDirectoryService::Undefine(const char* prop) { - nsStringKey key(prop); + nsCStringKey key(prop); if (!mHashtable->Exists(&key)) return NS_ERROR_FAILURE; @@ -544,7 +544,7 @@ static PRBool FindProviderFile(nsISupports* aElement, void *aData) NS_IMETHODIMP nsDirectoryService::Get(const char* prop, const nsIID & uuid, void* *result) { - nsStringKey key(prop); + nsCStringKey key(prop); nsCOMPtr value = dont_AddRef(mHashtable->Get(&key)); @@ -587,7 +587,7 @@ nsDirectoryService::Get(const char* prop, const nsIID & uuid, void* *result) NS_IMETHODIMP nsDirectoryService::Set(const char* prop, nsISupports* value) { - nsStringKey key(prop); + nsCStringKey key(prop); if (mHashtable->Exists(&key) || value == nsnull) return NS_ERROR_FAILURE; diff --git a/mozilla/xpcom/io/nsSpecialSystemDirectory.cpp b/mozilla/xpcom/io/nsSpecialSystemDirectory.cpp index 0ae3a1898e8..6979a9179f6 100644 --- a/mozilla/xpcom/io/nsSpecialSystemDirectory.cpp +++ b/mozilla/xpcom/io/nsSpecialSystemDirectory.cpp @@ -67,7 +67,7 @@ public: SystemDirectoriesKey(nsSpecialSystemDirectory::SystemDirectories newKey) : sdKey(newKey) {} - virtual PRUint32 HashValue(void) const + virtual PRUint32 HashCode(void) const { return PRUint32(sdKey); } diff --git a/mozilla/xpcom/proxy/public/nsProxyEvent.h b/mozilla/xpcom/proxy/public/nsProxyEvent.h index 2885051ce43..41f764e972e 100644 --- a/mozilla/xpcom/proxy/public/nsProxyEvent.h +++ b/mozilla/xpcom/proxy/public/nsProxyEvent.h @@ -93,10 +93,11 @@ public: nsIInterfaceInfo * interfaceInfo); nsresult PostAndWait(nsProxyObjectCallInfo *proxyInfo); - nsISupports* GetRealObject(); - nsIEventQueue* GetQueue(); + nsISupports* GetRealObject() const; + nsIEventQueue* GetQueue() const; PRInt32 GetProxyType() const { return mProxyType; } + friend class nsProxyEventObject; private: PRInt32 mProxyType; diff --git a/mozilla/xpcom/proxy/src/nsProxyEvent.cpp b/mozilla/xpcom/proxy/src/nsProxyEvent.cpp index e863bd42930..ac517fcf00d 100644 --- a/mozilla/xpcom/proxy/src/nsProxyEvent.cpp +++ b/mozilla/xpcom/proxy/src/nsProxyEvent.cpp @@ -91,7 +91,7 @@ nsProxyObjectCallInfo::~nsProxyObjectCallInfo() if (mOwner->GetProxyType() & PROXY_ASYNC) CopyStrings(PR_FALSE); - mOwner = 0; + mOwner = nsnull; PR_FREEIF(mEvent); @@ -262,13 +262,13 @@ nsProxyObject::~nsProxyObject() // This function must return the real pointer to the object to be proxied. // It must not be a comptr or be addreffed. nsISupports* -nsProxyObject::GetRealObject() +nsProxyObject::GetRealObject() const { return mRealObject.get(); } nsIEventQueue* -nsProxyObject::GetQueue() +nsProxyObject::GetQueue() const { return mDestQueue; } diff --git a/mozilla/xpcom/proxy/src/nsProxyEventObject.cpp b/mozilla/xpcom/proxy/src/nsProxyEventObject.cpp index c57dd44d8df..f2f45339122 100644 --- a/mozilla/xpcom/proxy/src/nsProxyEventObject.cpp +++ b/mozilla/xpcom/proxy/src/nsProxyEventObject.cpp @@ -37,6 +37,39 @@ static NS_DEFINE_IID(kProxyObject_Identity_Class_IID, NS_PROXYEVENT_IDENTITY_CLASS_IID); +//////////////////////////////////////////////////////////////////////////////// + +class nsProxyEventKey : public nsHashKey +{ +public: + nsProxyEventKey(void* rootObjectKey, void* destQueueKey, PRInt32 proxyType) + : mRootObjectKey(rootObjectKey), mDestQueueKey(destQueueKey), mProxyType(proxyType) { + } + + PRUint32 HashCode(void) const { + // XXX what about 64-bit machines? + return (PRUint32)mRootObjectKey ^ (PRUint32)mDestQueueKey ^ mProxyType; + } + + PRBool Equals(const nsHashKey *aKey) const { + const nsProxyEventKey* other = (const nsProxyEventKey*)aKey; + return mRootObjectKey == other->mRootObjectKey + && mDestQueueKey == other->mDestQueueKey + && mProxyType == other->mProxyType; + } + + nsHashKey *Clone() const { + return new nsProxyEventKey(mRootObjectKey, mDestQueueKey, mProxyType); + } + +protected: + void* mRootObjectKey; + void* mDestQueueKey; + PRInt32 mProxyType; +}; + +//////////////////////////////////////////////////////////////////////////////// + #ifdef DEBUG_xpcom_proxy static PRMonitor* mon = nsnull; static PRUint32 totalProxyObjects = 0; @@ -72,9 +105,11 @@ nsProxyEventObject::DebugDump(const char * message, PRUint32 hashKey) PRBool isRoot = mRoot == nsnull; printf("%s wrapper around @ %x\n", isRoot ? "ROOT":"non-root\n", GetRealObject()); - - if (mHashKey.HashValue()!=0) - printf("Hashkey: %d\n", mHashKey.HashValue()); + + nsCOMPtr rootObject = do_QueryInterface(mProxyObject->mRealObject); + nsCOMPtr rootQueue = do_QueryInterface(mProxyObject->mDestQueue); + nsProxyEventKey key(rootObject, rootQueue, mProxyObject->mProxyType); + printf("Hashkey: %d\n", key.HashCode()); char* name; GetClass()->GetInterfaceInfo()->GetName(&name); @@ -166,9 +201,7 @@ nsProxyEventObject::GetNewOrUsedProxy(nsIEventQueue *destQueue, if (NS_FAILED(rv)) return nsnull; - char* rootKeyString = PR_sprintf_append(nsnull, "%p.%p.%d", (PRUint32)rootObject.get(), (PRUint32)destQRoot.get(), proxyType); - nsStringKey rootkey(rootKeyString); - + nsProxyEventKey rootkey(rootObject.get(), destQRoot.get(), proxyType); // find in our hash table root = (nsProxyEventObject*) realToProxyMap->Get(&rootkey); @@ -178,7 +211,6 @@ nsProxyEventObject::GetNewOrUsedProxy(nsIEventQueue *destQueue, if(proxy) { - PR_FREEIF(rootKeyString); peo = proxy; NS_ADDREF(peo); return peo; @@ -194,14 +226,12 @@ nsProxyEventObject::GetNewOrUsedProxy(nsIEventQueue *destQueue, proxyType, requestedInterface, clazz, - nsnull, - rootKeyString); + nsnull); proxy = do_QueryInterface(peo); if(proxy) { - PR_FREEIF(rootKeyString); realToProxyMap->Put(&rootkey, peo); peo = proxy; NS_ADDREF(peo); @@ -216,7 +246,6 @@ nsProxyEventObject::GetNewOrUsedProxy(nsIEventQueue *destQueue, if (!rootClazz) { - PR_FREEIF(rootKeyString); return nsnull; } @@ -224,12 +253,10 @@ nsProxyEventObject::GetNewOrUsedProxy(nsIEventQueue *destQueue, proxyType, rootObject, rootClazz, - nsnull, - rootKeyString); + nsnull); if(!peo) { - PR_FREEIF(rootKeyString); return nsnull; } @@ -248,14 +275,12 @@ nsProxyEventObject::GetNewOrUsedProxy(nsIEventQueue *destQueue, proxyType, requestedInterface, clazz, - root, - ""); + root); proxy = do_QueryInterface(peo); if(!proxy) { - PR_FREEIF(rootKeyString); return nsnull; } } @@ -263,15 +288,14 @@ nsProxyEventObject::GetNewOrUsedProxy(nsIEventQueue *destQueue, proxy->mNext = root->mNext; root->mNext = proxy; - PR_FREEIF(rootKeyString); peo = proxy; NS_ADDREF(peo); return peo; } + nsProxyEventObject::nsProxyEventObject() -: mHashKey(""), - mNext(nsnull) +: mNext(nsnull) { NS_WARNING("This constructor should never be called"); } @@ -280,29 +304,25 @@ nsProxyEventObject::nsProxyEventObject(nsIEventQueue *destQueue, PRInt32 proxyType, nsISupports* aObj, nsProxyEventClass* aClass, - nsProxyEventObject* root, - const char * hashStr) - : mHashKey(hashStr), + nsProxyEventObject* root) + : mClass(aClass), + mRoot(root), mNext(nsnull) { NS_INIT_REFCNT(); - - mClass = aClass; - - mRoot = root; NS_IF_ADDREF(mRoot); mProxyObject = new nsProxyObject(destQueue, proxyType, aObj); - + #ifdef DEBUG_xpcom_proxy -DebugDump("Create", 0); + DebugDump("Create", 0); #endif } nsProxyEventObject::~nsProxyEventObject() { #ifdef DEBUG_xpcom_proxy -DebugDump("Delete", 0); + DebugDump("Delete", 0); #endif if (mRoot != nsnull) { @@ -325,9 +345,13 @@ DebugDump("Delete", 0); nsCOMPtr manager = nsProxyObjectManager::GetInstance(); nsHashtable *realToProxyMap = manager->GetRealObjectToProxyObjectMap(); - if (realToProxyMap != nsnull && mHashKey.HashValue() != 0) + if (realToProxyMap != nsnull) { - realToProxyMap->Remove(&mHashKey); + nsCOMPtr rootObject = do_QueryInterface(mProxyObject->mRealObject); + nsCOMPtr rootQueue = do_QueryInterface(mProxyObject->mDestQueue); + nsProxyEventKey key(rootObject, rootQueue, mProxyObject->mProxyType); + void* value = realToProxyMap->Remove(&key); + NS_ASSERTION(value, "failed to remove from realToProxyMap"); } } } @@ -398,28 +422,11 @@ nsProxyEventObject::GetInterfaceInfo(nsIInterfaceInfo** info) NS_IMETHODIMP nsProxyEventObject::CallMethod(PRUint16 methodIndex, - const nsXPTMethodInfo* info, - nsXPTCMiniVariant * params) + const nsXPTMethodInfo* info, + nsXPTCMiniVariant * params) { if (mProxyObject) return mProxyObject->Post(methodIndex, (nsXPTMethodInfo*)info, params, GetClass()->GetInterfaceInfo()); return NS_ERROR_NULL_POINTER; } - - - - - - - - - - - - - - - - - diff --git a/mozilla/xpcom/proxy/src/nsProxyEventPrivate.h b/mozilla/xpcom/proxy/src/nsProxyEventPrivate.h index eeb9d3fa974..04fc992168e 100644 --- a/mozilla/xpcom/proxy/src/nsProxyEventPrivate.h +++ b/mozilla/xpcom/proxy/src/nsProxyEventPrivate.h @@ -118,8 +118,7 @@ public: PRInt32 proxyType, nsISupports* aObj, nsProxyEventClass* aClass, - nsProxyEventObject* root, - const char * hashStr); + nsProxyEventObject* root); virtual ~nsProxyEventObject(); @@ -132,8 +131,6 @@ public: protected: PRLock *mLock; - nsStringKey mHashKey; - nsCOMPtr mClass; nsCOMPtr mProxyObject; /* diff --git a/mozilla/xpcom/proxy/tests/proxytests.cpp b/mozilla/xpcom/proxy/tests/proxytests.cpp index a941aefd757..9e1191d6bd6 100644 --- a/mozilla/xpcom/proxy/tests/proxytests.cpp +++ b/mozilla/xpcom/proxy/tests/proxytests.cpp @@ -133,7 +133,7 @@ nsTestXPCFoo2::~nsTestXPCFoo2() { } -NS_IMPL_ISUPPORTS(nsTestXPCFoo2,NS_GET_IID(nsITestProxy)) +NS_IMPL_THREADSAFE_ISUPPORTS1(nsTestXPCFoo2, nsITestProxy) NS_IMETHODIMP nsTestXPCFoo2::Test(PRInt32 p1, PRInt32 p2, PRInt32* retval) { diff --git a/mozilla/xpcom/string/obsolete/nsStr.cpp b/mozilla/xpcom/string/obsolete/nsStr.cpp index 67e02a2dce9..0f300bf9281 100644 --- a/mozilla/xpcom/string/obsolete/nsStr.cpp +++ b/mozilla/xpcom/string/obsolete/nsStr.cpp @@ -780,25 +780,10 @@ CBufDescriptor::CBufDescriptor(const PRUnichar* aString,PRBool aStackBased,PRUin PRUint32 nsStr::HashCode(const nsStr& aDest) { - if (aDest.mCharSize == eTwoByte) { - PRUint32 h; - PRUint32 n = aDest.mLength; - PRUint32 m; - const PRUnichar* c; - h = 0; - - c = aDest.mUStr; - if (n < 16) { /* Hash every char in a short string. */ - for(; n; c++, n--) - h = (h >> 28) ^ (h << 4) ^ *c; - } - else { /* Sample a la java.lang.String.hash(). */ - for(m = n / 8; n >= m; c += m, n -= m) - h = (h >> 28) ^ (h << 4) ^ *c; - } - return h; - } - return (PRUint32)PL_HashString((const void*) aDest.mStr); + if (aDest.mCharSize == eTwoByte) + return nsCRT::HashCode(aDest.mUStr, aDest.mLength); + else + return nsCRT::HashCode(aDest.mStr, aDest.mLength); } #ifdef NS_STR_STATS diff --git a/mozilla/xpcom/string/obsolete/nsStr.h b/mozilla/xpcom/string/obsolete/nsStr.h index f8c392345da..d876eee8b70 100644 --- a/mozilla/xpcom/string/obsolete/nsStr.h +++ b/mozilla/xpcom/string/obsolete/nsStr.h @@ -431,7 +431,6 @@ struct NS_COM nsStr { */ static PRUint32 HashCode(const nsStr& aDest); - #ifndef NEW_STRING_APIS static void Append(nsStr& aDest,const nsStr& aSource,PRUint32 anOffset,PRInt32 aCount) { StrAppend(aDest, aSource, anOffset, aCount); diff --git a/mozilla/xpcom/threads/nsEventQueueService.cpp b/mozilla/xpcom/threads/nsEventQueueService.cpp index 16bb215624e..bd7f8035899 100644 --- a/mozilla/xpcom/threads/nsEventQueueService.cpp +++ b/mozilla/xpcom/threads/nsEventQueueService.cpp @@ -36,38 +36,6 @@ extern PRUint32 gEventQueueLogCount; static NS_DEFINE_CID(kEventQueueCID, NS_EVENTQUEUE_CID); -//////////////////////////////////////////////////////////////////////////////// - -// XXX move to nsID.h or nsHashtable.h? (copied from nsComponentManager.cpp) -class ThreadKey: public nsHashKey { - -public: - ThreadKey(PRThread* aID) { - id = aID; - } - - ThreadKey(const ThreadKey &aKey) { - id = aKey.id; - } - - PRUint32 HashValue(void) const { - return (PRUint32)id; - } - - PRBool Equals(const nsHashKey *aKey) const { - return (id == ((const ThreadKey *) aKey)->id); - } - - nsHashKey *Clone(void) const { - return new ThreadKey(id); - } - - PRThread* id; - -}; - -//////////////////////////////////////////////////////////////////////////////// - nsEventQueueServiceImpl::nsEventQueueServiceImpl() { NS_INIT_REFCNT(); @@ -177,7 +145,7 @@ NS_IMETHODIMP nsEventQueueServiceImpl::CreateEventQueue(PRThread *aThread, PRBool aNative) { nsresult rv = NS_OK; - ThreadKey key(aThread); + nsVoidKey key(aThread); nsCOMPtr queue; /* Enter the lock which protects the EventQ hashtable... */ @@ -202,7 +170,7 @@ NS_IMETHODIMP nsEventQueueServiceImpl::DestroyThreadEventQueue(void) { nsresult rv = NS_OK; - ThreadKey key(PR_GetCurrentThread()); + nsVoidKey key(PR_GetCurrentThread()); /* Enter the lock which protects the EventQ hashtable... */ PR_EnterMonitor(mEventQMonitor); @@ -263,7 +231,7 @@ NS_IMETHODIMP nsEventQueueServiceImpl::PushThreadEventQueue(nsIEventQueue **aNewQueue) { nsresult rv = NS_OK; - ThreadKey key(PR_GetCurrentThread()); + nsVoidKey key(PR_GetCurrentThread()); PRBool native = PR_TRUE; // native by default as per old comment @@ -284,7 +252,7 @@ nsEventQueueServiceImpl::PushThreadEventQueue(nsIEventQueue **aNewQueue) } nsCOMPtr newQueue; - MakeNewQueue(key.id, native, getter_AddRefs(newQueue)); // create new queue + MakeNewQueue((PRThread*)key.GetValue(), native, getter_AddRefs(newQueue)); // create new queue if (!queue) { // shouldn't happen. as a fallback, we guess you wanted a native queue @@ -317,7 +285,7 @@ NS_IMETHODIMP nsEventQueueServiceImpl::PopThreadEventQueue(nsIEventQueue *aQueue) { nsresult rv = NS_OK; - ThreadKey key(PR_GetCurrentThread()); + nsVoidKey key(PR_GetCurrentThread()); /* Enter the lock which protects the EventQ hashtable... */ PR_EnterMonitor(mEventQMonitor); @@ -374,7 +342,7 @@ nsEventQueueServiceImpl::GetThreadEventQueue(PRThread* aThread, nsIEventQueue** if (NS_FAILED(rv)) return rv; } - ThreadKey key(keyThread); + nsVoidKey key(keyThread); /* Enter the lock which protects the EventQ hashtable... */ PR_EnterMonitor(mEventQMonitor);