From c06e84b6256d3ecb4bd73418eb4cffb6fdb6c699 Mon Sep 17 00:00:00 2001 From: "scc%mozilla.org" Date: Thu, 5 Oct 2000 01:22:00 +0000 Subject: [PATCH] bug #54601: r=waterson, a=brendan. Fix string allocation policy -- allocate exact size, double on fault ... thanks to everybody who helped me test this patch. git-svn-id: svn://10.0.0.236/trunk@80401 18797224-902f-48f8-a5cc-f745e15eee43 --- mozilla/string/obsolete/nsStr.cpp | 13 ++++++++++++- mozilla/xpcom/ds/nsStr.cpp | 13 ++++++++++++- mozilla/xpcom/string/obsolete/nsStr.cpp | 13 ++++++++++++- 3 files changed, 36 insertions(+), 3 deletions(-) diff --git a/mozilla/string/obsolete/nsStr.cpp b/mozilla/string/obsolete/nsStr.cpp index a64f12632aa..c794094bda3 100644 --- a/mozilla/string/obsolete/nsStr.cpp +++ b/mozilla/string/obsolete/nsStr.cpp @@ -121,6 +121,16 @@ PRBool nsStr::GrowCapacity(nsStr& aDest,PRUint32 aNewLength) { nsStr theTempStr; nsStr::Initialize(theTempStr,aDest.mCharSize); +#ifndef NS_USE_OLD_STRING_ALLOCATION_STRATEGY + // the new strategy is, allocate exact size, double on grows + if ( aDest.mCapacity ) { + PRUint32 newCapacity = aDest.mCapacity; + while ( newCapacity < aNewLength ) + newCapacity <<= 1; + aNewLength = newCapacity; + } +#endif + result=EnsureCapacity(theTempStr,aNewLength); if(result) { if(aDest.mLength) { @@ -656,7 +666,7 @@ PRBool nsStr::Alloc(nsStr& aDest,PRUint32 aCount) { static int mAllocCount=0; mAllocCount++; -#ifndef NS_DONT_USE_CHUNKY_STRING_ALLOCATION +#ifdef NS_USE_OLD_STRING_ALLOCATION_STRATEGY //we're given the acount value in charunits; now scale up to next multiple. PRUint32 theNewCapacity=kDefaultStringSize; while(theNewCapacity