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
This commit is contained in:
scc%mozilla.org
2000-10-05 01:22:00 +00:00
parent f8b1f2158d
commit c06e84b625
3 changed files with 36 additions and 3 deletions

View File

@@ -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<aCount){
@@ -667,6 +677,7 @@ PRBool nsStr::Alloc(nsStr& aDest,PRUint32 aCount) {
PRUint32 theSize=(theNewCapacity<<aDest.mCharSize);
aDest.mStr = (char*)nsMemory::Alloc(theSize);
#else
// the new strategy is, allocate exact size, double on grows
aDest.mCapacity = aCount;
aDest.mStr = (char*)nsMemory::Alloc((aCount+1)<<aDest.mCharSize);
#endif