From becfeef73af8f2a32993ebbe2abbc557198c7e95 Mon Sep 17 00:00:00 2001 From: "sspitzer%netscape.com" Date: Mon, 18 Dec 2000 19:58:20 +0000 Subject: [PATCH] fix for #58238. sr=bienvenu. fix crash when growing the hash table that contained the list of atoms. see bug report for all the details. thanks to bienvenu, scc, brendan, and hyatt for the help. git-svn-id: svn://10.0.0.236/trunk@83789 18797224-902f-48f8-a5cc-f745e15eee43 --- mozilla/xpcom/ds/nsAtomTable.cpp | 63 ++++++++------------------------ 1 file changed, 16 insertions(+), 47 deletions(-) diff --git a/mozilla/xpcom/ds/nsAtomTable.cpp b/mozilla/xpcom/ds/nsAtomTable.cpp index f6eaba2900a..b37ae4091ca 100644 --- a/mozilla/xpcom/ds/nsAtomTable.cpp +++ b/mozilla/xpcom/ds/nsAtomTable.cpp @@ -80,12 +80,8 @@ AtomImpl::~AtomImpl() { NS_PRECONDITION(nsnull != gAtomHashTable, "null atom hashtable"); if (nsnull != gAtomHashTable) { - // The hash table uses nsAReadableString& as the key so we must - // instanciate a nsAReadableString (nsLiteralString) and use that - // as the key - nsLiteralString key(mString); - PL_HashTableRemove(gAtomHashTable, &key); + PL_HashTableRemove(gAtomHashTable, mString); nsrefcnt cnt = --gAtoms; if (0 == cnt) { // When the last atom is destroyed, the atom arena is destroyed @@ -98,33 +94,6 @@ AtomImpl::~AtomImpl() NS_IMPL_THREADSAFE_ISUPPORTS1(AtomImpl, nsIAtom) -class CalculateHash - { - public: - typedef PRUnichar value_type; - - CalculateHash() : mHash(0), mLengthHashed(0) { } - - - PRUint32 - write( const PRUnichar* s, PRUint32 N ) - { - for ( PRUint32 n=0; n hashBegin, hashEnd; - copy_string(k->BeginReading(hashBegin), k->EndReading(hashEnd), hasher); + PRUint32 hashResult = 0; + PRUint32 N = nsCRT::strlen(k); - return NS_STATIC_CAST(PLHashNumber, hasher.GetHash()); + for ( PRUint32 n=0; n hashBegin, hashEnd; - copy_string(aString.BeginReading(hashBegin), aString.EndReading(hashEnd), hasher); + const PRUnichar *str = nsPromiseFlatString(aString).get(); - PRUint32 hashCode = hasher.GetHash(); + PRUint32 hashCode = HashKey(str); + + PLHashEntry** hep = PL_HashTableRawLookup(gAtomHashTable, hashCode, str); - PLHashEntry** hep = PL_HashTableRawLookup(gAtomHashTable, hashCode, - &aString); PLHashEntry* he = *hep; AtomImpl* id; @@ -225,9 +194,9 @@ NS_COM nsIAtom* NS_NewAtom( const nsAReadableString& aString ) return id; } -NS_COM nsIAtom* NS_NewAtom( const PRUnichar* us ) +NS_COM nsIAtom* NS_NewAtom( const PRUnichar* str ) { - return NS_NewAtom(nsLiteralString(us)); + return NS_NewAtom(nsLiteralString(str)); } NS_COM nsrefcnt NS_GetNumberOfAtoms(void)