From 682459c176579a8d7fe5a54f2054940f958c4dd0 Mon Sep 17 00:00:00 2001 From: "dp%netscape.com" Date: Fri, 22 Mar 2002 06:28:16 +0000 Subject: [PATCH] bug 131249 Using arena for RuleHash r=dbaron@fas.harvard.edu, sr=sfraser, a=asa git-svn-id: svn://10.0.0.236/trunk@117158 18797224-902f-48f8-a5cc-f745e15eee43 --- .../html/style/src/nsCSSStyleSheet.cpp | 49 ++++++++++++------- mozilla/layout/style/nsCSSStyleSheet.cpp | 49 ++++++++++++------- 2 files changed, 64 insertions(+), 34 deletions(-) diff --git a/mozilla/content/html/style/src/nsCSSStyleSheet.cpp b/mozilla/content/html/style/src/nsCSSStyleSheet.cpp index 9fa40ffeb22..2c865bd530d 100644 --- a/mozilla/content/html/style/src/nsCSSStyleSheet.cpp +++ b/mozilla/content/html/style/src/nsCSSStyleSheet.cpp @@ -39,6 +39,11 @@ * ***** END LICENSE BLOCK ***** */ #include "nscore.h" + +#define PL_ARENA_CONST_ALIGN_MASK 7 +#define NS_RULEHASH_ARENA_BLOCK_SIZE (256) +#include "plarena.h" + #include "nsICSSStyleSheet.h" #include "nsIArena.h" #include "nsCRT.h" @@ -294,11 +299,21 @@ struct RuleValue { mIndex = aIndex; mNext = nsnull; } + + // CAUTION: ~RuleValue will never get called as RuleValues are arena + // allocated and arena cleanup will take care of deleting memory. + // Add code to RuleHash::~RuleHash to get it to call the destructor + // if any more cleanup needs to happen. ~RuleValue(void) { - if ((nsnull != mNext) && (nsnull != mNext->mNext)) { - delete mNext; // don't delete that last in the chain, it's shared - } + // Rule values are arena allocated. No need for any deletion. + } + + // Placement new to arena allocate the RuleValues + void *operator new(size_t aSize, PLArenaPool &aArena) { + void *mem; + PL_ARENA_ALLOCATE(mem, &aArena, aSize); + return mem; } nsICSSStyleRule* mRule; @@ -337,6 +352,7 @@ protected: void AppendRuleToTable(nsHashtable& aTable, nsIAtom* aAtom, nsICSSStyleRule* aRule, PRBool aCaseSensitive = PR_TRUE); void AppendRuleToTable(nsHashtable& aTable, PRInt32 aNameSpace, nsICSSStyleRule* aRule); + // All rule values in these hashtables are arena allocated PRInt32 mRuleCount; nsHashtable mIdTable; nsHashtable mClassTable; @@ -348,6 +364,8 @@ protected: RuleValue mEndValue; PRBool mCaseSensitive; + PLArenaPool mArena; + #ifdef RULE_HASH_STATS PRUint32 mUniversalSelectors; PRUint32 mNameSpaceSelectors; @@ -391,12 +409,8 @@ RuleHash::RuleHash(void) mPseudoTagCalls(0) #endif { -} - -static PRBool PR_CALLBACK DeleteValue(nsHashKey* aKey, void* aValue, void* closure) -{ - delete ((RuleValue*)aValue); - return PR_TRUE; + // Initialize our arena + PL_INIT_ARENA_POOL(&mArena, "RuleHashArena", NS_RULEHASH_ARENA_BLOCK_SIZE); } RuleHash::~RuleHash(void) @@ -434,13 +448,14 @@ RuleHash::~RuleHash(void) } #endif // PRINT_UNIVERSAL_RULES #endif // RULE_HASH_STATS - mIdTable.Enumerate(DeleteValue); - mClassTable.Enumerate(DeleteValue); - mTagTable.Enumerate(DeleteValue); - mNameSpaceTable.Enumerate(DeleteValue); + // Rule Values are arena allocated no need to delete them. Their destructor + // isn't doing any cleanup. So we dont even bother to enumerate through + // the hash tables and call their destructors. if (nsnull != mEnumList) { delete [] mEnumList; } + // delete arena for strings and small objects + PL_FinishArenaPool(&mArena); } void RuleHash::AppendRuleToTable(nsHashtable& aTable, nsIAtom* aAtom, nsICSSStyleRule* aRule, PRBool aCaseSensitive) @@ -452,7 +467,7 @@ void RuleHash::AppendRuleToTable(nsHashtable& aTable, nsIAtom* aAtom, nsICSSStyl RuleValue* value = (RuleValue*)aTable.Get(&key); if (nsnull == value) { - value = new RuleValue(aRule, mRuleCount++); + value = new (mArena) RuleValue(aRule, mRuleCount++); aTable.Put(&key, value); value->mNext = &mEndValue; } @@ -460,7 +475,7 @@ void RuleHash::AppendRuleToTable(nsHashtable& aTable, nsIAtom* aAtom, nsICSSStyl while (&mEndValue != value->mNext) { value = value->mNext; } - value->mNext = new RuleValue(aRule, mRuleCount++); + value->mNext = new (mArena) RuleValue(aRule, mRuleCount++); value->mNext->mNext = &mEndValue; } mEndValue.mIndex = mRuleCount; @@ -472,7 +487,7 @@ void RuleHash::AppendRuleToTable(nsHashtable& aTable, PRInt32 aNameSpace, nsICSS RuleValue* value = (RuleValue*)aTable.Get(&key); if (nsnull == value) { - value = new RuleValue(aRule, mRuleCount++); + value = new (mArena) RuleValue(aRule, mRuleCount++); aTable.Put(&key, value); value->mNext = &mEndValue; } @@ -480,7 +495,7 @@ void RuleHash::AppendRuleToTable(nsHashtable& aTable, PRInt32 aNameSpace, nsICSS while (&mEndValue != value->mNext) { value = value->mNext; } - value->mNext = new RuleValue(aRule, mRuleCount++); + value->mNext = new (mArena) RuleValue(aRule, mRuleCount++); value->mNext->mNext = &mEndValue; } mEndValue.mIndex = mRuleCount; diff --git a/mozilla/layout/style/nsCSSStyleSheet.cpp b/mozilla/layout/style/nsCSSStyleSheet.cpp index 9fa40ffeb22..2c865bd530d 100644 --- a/mozilla/layout/style/nsCSSStyleSheet.cpp +++ b/mozilla/layout/style/nsCSSStyleSheet.cpp @@ -39,6 +39,11 @@ * ***** END LICENSE BLOCK ***** */ #include "nscore.h" + +#define PL_ARENA_CONST_ALIGN_MASK 7 +#define NS_RULEHASH_ARENA_BLOCK_SIZE (256) +#include "plarena.h" + #include "nsICSSStyleSheet.h" #include "nsIArena.h" #include "nsCRT.h" @@ -294,11 +299,21 @@ struct RuleValue { mIndex = aIndex; mNext = nsnull; } + + // CAUTION: ~RuleValue will never get called as RuleValues are arena + // allocated and arena cleanup will take care of deleting memory. + // Add code to RuleHash::~RuleHash to get it to call the destructor + // if any more cleanup needs to happen. ~RuleValue(void) { - if ((nsnull != mNext) && (nsnull != mNext->mNext)) { - delete mNext; // don't delete that last in the chain, it's shared - } + // Rule values are arena allocated. No need for any deletion. + } + + // Placement new to arena allocate the RuleValues + void *operator new(size_t aSize, PLArenaPool &aArena) { + void *mem; + PL_ARENA_ALLOCATE(mem, &aArena, aSize); + return mem; } nsICSSStyleRule* mRule; @@ -337,6 +352,7 @@ protected: void AppendRuleToTable(nsHashtable& aTable, nsIAtom* aAtom, nsICSSStyleRule* aRule, PRBool aCaseSensitive = PR_TRUE); void AppendRuleToTable(nsHashtable& aTable, PRInt32 aNameSpace, nsICSSStyleRule* aRule); + // All rule values in these hashtables are arena allocated PRInt32 mRuleCount; nsHashtable mIdTable; nsHashtable mClassTable; @@ -348,6 +364,8 @@ protected: RuleValue mEndValue; PRBool mCaseSensitive; + PLArenaPool mArena; + #ifdef RULE_HASH_STATS PRUint32 mUniversalSelectors; PRUint32 mNameSpaceSelectors; @@ -391,12 +409,8 @@ RuleHash::RuleHash(void) mPseudoTagCalls(0) #endif { -} - -static PRBool PR_CALLBACK DeleteValue(nsHashKey* aKey, void* aValue, void* closure) -{ - delete ((RuleValue*)aValue); - return PR_TRUE; + // Initialize our arena + PL_INIT_ARENA_POOL(&mArena, "RuleHashArena", NS_RULEHASH_ARENA_BLOCK_SIZE); } RuleHash::~RuleHash(void) @@ -434,13 +448,14 @@ RuleHash::~RuleHash(void) } #endif // PRINT_UNIVERSAL_RULES #endif // RULE_HASH_STATS - mIdTable.Enumerate(DeleteValue); - mClassTable.Enumerate(DeleteValue); - mTagTable.Enumerate(DeleteValue); - mNameSpaceTable.Enumerate(DeleteValue); + // Rule Values are arena allocated no need to delete them. Their destructor + // isn't doing any cleanup. So we dont even bother to enumerate through + // the hash tables and call their destructors. if (nsnull != mEnumList) { delete [] mEnumList; } + // delete arena for strings and small objects + PL_FinishArenaPool(&mArena); } void RuleHash::AppendRuleToTable(nsHashtable& aTable, nsIAtom* aAtom, nsICSSStyleRule* aRule, PRBool aCaseSensitive) @@ -452,7 +467,7 @@ void RuleHash::AppendRuleToTable(nsHashtable& aTable, nsIAtom* aAtom, nsICSSStyl RuleValue* value = (RuleValue*)aTable.Get(&key); if (nsnull == value) { - value = new RuleValue(aRule, mRuleCount++); + value = new (mArena) RuleValue(aRule, mRuleCount++); aTable.Put(&key, value); value->mNext = &mEndValue; } @@ -460,7 +475,7 @@ void RuleHash::AppendRuleToTable(nsHashtable& aTable, nsIAtom* aAtom, nsICSSStyl while (&mEndValue != value->mNext) { value = value->mNext; } - value->mNext = new RuleValue(aRule, mRuleCount++); + value->mNext = new (mArena) RuleValue(aRule, mRuleCount++); value->mNext->mNext = &mEndValue; } mEndValue.mIndex = mRuleCount; @@ -472,7 +487,7 @@ void RuleHash::AppendRuleToTable(nsHashtable& aTable, PRInt32 aNameSpace, nsICSS RuleValue* value = (RuleValue*)aTable.Get(&key); if (nsnull == value) { - value = new RuleValue(aRule, mRuleCount++); + value = new (mArena) RuleValue(aRule, mRuleCount++); aTable.Put(&key, value); value->mNext = &mEndValue; } @@ -480,7 +495,7 @@ void RuleHash::AppendRuleToTable(nsHashtable& aTable, PRInt32 aNameSpace, nsICSS while (&mEndValue != value->mNext) { value = value->mNext; } - value->mNext = new RuleValue(aRule, mRuleCount++); + value->mNext = new (mArena) RuleValue(aRule, mRuleCount++); value->mNext->mNext = &mEndValue; } mEndValue.mIndex = mRuleCount;