From 944a022ec9f96e8b3bccd191285131225feb80aa Mon Sep 17 00:00:00 2001 From: "rickg%netscape.com" Date: Fri, 17 Sep 1999 23:46:55 +0000 Subject: [PATCH] performance improvements and larger default buffer size git-svn-id: svn://10.0.0.236/trunk@48092 18797224-902f-48f8-a5cc-f745e15eee43 --- mozilla/string/obsolete/nsStr.cpp | 39 +++++++++++-- mozilla/string/obsolete/nsStr.h | 2 +- mozilla/xpcom/ds/bufferRoutines.h | 73 +++++++------------------ mozilla/xpcom/ds/nsStr.cpp | 39 +++++++++++-- mozilla/xpcom/ds/nsStr.h | 2 +- mozilla/xpcom/string/obsolete/nsStr.cpp | 39 +++++++++++-- mozilla/xpcom/string/obsolete/nsStr.h | 2 +- 7 files changed, 121 insertions(+), 75 deletions(-) diff --git a/mozilla/string/obsolete/nsStr.cpp b/mozilla/string/obsolete/nsStr.cpp index 46c668ede57..087c73f389d 100644 --- a/mozilla/string/obsolete/nsStr.cpp +++ b/mozilla/string/obsolete/nsStr.cpp @@ -207,15 +207,42 @@ void nsStr::Insert( nsStr& aDest,PRUint32 aDestOffset,const nsStr& aSource,PRUin if(aSrcOffset aDest.mCapacity) { + nsStr theTempStr; + nsStr::Initialize(theTempStr,aDest.mCharSize); + + nsIMemoryAgent* theAgent=(anAgent) ? anAgent : GetDefaultAgent(); + EnsureCapacity(theTempStr,aDest.mLength+theLength,theAgent); //grow the temp buffer to the right size + + if(aDestOffset) { + Append(theTempStr,aDest,0,aDestOffset,theAgent); //first copy leftmost data... + } + + Append(theTempStr,aSource,0,aSource.mLength,theAgent); //next copy inserted (new) data + + PRUint32 theRemains=aDest.mLength-aDestOffset; + if(theRemains) { + Append(theTempStr,aDest,aDestOffset,theRemains,theAgent); //next copy rightmost data + } + + theAgent->Free(aDest); + aDest.mStr = theTempStr.mStr; + theTempStr.mStr=0; //make sure to null this out so that you don't lose the buffer you just stole... + aDest.mCapacity=theTempStr.mCapacity; + aDest.mOwnsBuffer=theTempStr.mOwnsBuffer; + + } + + else { + //shift the chars right by theDelta... + (*gShiftChars[aDest.mCharSize][KSHIFTRIGHT])(aDest.mStr,aDest.mLength,aDestOffset,theLength); - //now insert new chars, starting at offset - (*gCopyChars[aSource.mCharSize][aDest.mCharSize])(aDest.mStr,aDestOffset,aSource.mStr,aSrcOffset,theLength); + //now insert new chars, starting at offset + (*gCopyChars[aSource.mCharSize][aDest.mCharSize])(aDest.mStr,aDestOffset,aSource.mStr,aSrcOffset,theLength); + } - //finally, make sure to update the string length... + //finally, make sure to update the string length... aDest.mLength+=theLength; AddNullTerminator(aDest); diff --git a/mozilla/string/obsolete/nsStr.h b/mozilla/string/obsolete/nsStr.h index 9d2ebac21d1..daf814e797e 100644 --- a/mozilla/string/obsolete/nsStr.h +++ b/mozilla/string/obsolete/nsStr.h @@ -173,7 +173,7 @@ enum eCharSize {eOneByte=0,eTwoByte=1}; #define kRadix16 (16) #define kAutoDetect (100) #define kRadixUnknown (kAutoDetect+1) -const PRInt32 kDefaultStringSize = 32; +const PRInt32 kDefaultStringSize = 64; const PRInt32 kNotFound = -1; diff --git a/mozilla/xpcom/ds/bufferRoutines.h b/mozilla/xpcom/ds/bufferRoutines.h index 5b5fdfa9152..285316532e9 100644 --- a/mozilla/xpcom/ds/bufferRoutines.h +++ b/mozilla/xpcom/ds/bufferRoutines.h @@ -64,19 +64,10 @@ inline PRUnichar GetCharAt(const char* aString,PRUint32 anIndex) { * @param aCount is the number of chars to be "cut" */ void ShiftCharsLeft(char* aDest,PRUint32 aLength,PRUint32 anOffset,PRUint32 aCount) { - //PRUint32 theMax=aLength-anOffset; - //PRUint32 theLength=(theMax aDest.mCapacity) { + nsStr theTempStr; + nsStr::Initialize(theTempStr,aDest.mCharSize); + + nsIMemoryAgent* theAgent=(anAgent) ? anAgent : GetDefaultAgent(); + EnsureCapacity(theTempStr,aDest.mLength+theLength,theAgent); //grow the temp buffer to the right size + + if(aDestOffset) { + Append(theTempStr,aDest,0,aDestOffset,theAgent); //first copy leftmost data... + } + + Append(theTempStr,aSource,0,aSource.mLength,theAgent); //next copy inserted (new) data + + PRUint32 theRemains=aDest.mLength-aDestOffset; + if(theRemains) { + Append(theTempStr,aDest,aDestOffset,theRemains,theAgent); //next copy rightmost data + } + + theAgent->Free(aDest); + aDest.mStr = theTempStr.mStr; + theTempStr.mStr=0; //make sure to null this out so that you don't lose the buffer you just stole... + aDest.mCapacity=theTempStr.mCapacity; + aDest.mOwnsBuffer=theTempStr.mOwnsBuffer; + + } + + else { + //shift the chars right by theDelta... + (*gShiftChars[aDest.mCharSize][KSHIFTRIGHT])(aDest.mStr,aDest.mLength,aDestOffset,theLength); - //now insert new chars, starting at offset - (*gCopyChars[aSource.mCharSize][aDest.mCharSize])(aDest.mStr,aDestOffset,aSource.mStr,aSrcOffset,theLength); + //now insert new chars, starting at offset + (*gCopyChars[aSource.mCharSize][aDest.mCharSize])(aDest.mStr,aDestOffset,aSource.mStr,aSrcOffset,theLength); + } - //finally, make sure to update the string length... + //finally, make sure to update the string length... aDest.mLength+=theLength; AddNullTerminator(aDest); diff --git a/mozilla/xpcom/ds/nsStr.h b/mozilla/xpcom/ds/nsStr.h index 9d2ebac21d1..daf814e797e 100644 --- a/mozilla/xpcom/ds/nsStr.h +++ b/mozilla/xpcom/ds/nsStr.h @@ -173,7 +173,7 @@ enum eCharSize {eOneByte=0,eTwoByte=1}; #define kRadix16 (16) #define kAutoDetect (100) #define kRadixUnknown (kAutoDetect+1) -const PRInt32 kDefaultStringSize = 32; +const PRInt32 kDefaultStringSize = 64; const PRInt32 kNotFound = -1; diff --git a/mozilla/xpcom/string/obsolete/nsStr.cpp b/mozilla/xpcom/string/obsolete/nsStr.cpp index 46c668ede57..087c73f389d 100644 --- a/mozilla/xpcom/string/obsolete/nsStr.cpp +++ b/mozilla/xpcom/string/obsolete/nsStr.cpp @@ -207,15 +207,42 @@ void nsStr::Insert( nsStr& aDest,PRUint32 aDestOffset,const nsStr& aSource,PRUin if(aSrcOffset aDest.mCapacity) { + nsStr theTempStr; + nsStr::Initialize(theTempStr,aDest.mCharSize); + + nsIMemoryAgent* theAgent=(anAgent) ? anAgent : GetDefaultAgent(); + EnsureCapacity(theTempStr,aDest.mLength+theLength,theAgent); //grow the temp buffer to the right size + + if(aDestOffset) { + Append(theTempStr,aDest,0,aDestOffset,theAgent); //first copy leftmost data... + } + + Append(theTempStr,aSource,0,aSource.mLength,theAgent); //next copy inserted (new) data + + PRUint32 theRemains=aDest.mLength-aDestOffset; + if(theRemains) { + Append(theTempStr,aDest,aDestOffset,theRemains,theAgent); //next copy rightmost data + } + + theAgent->Free(aDest); + aDest.mStr = theTempStr.mStr; + theTempStr.mStr=0; //make sure to null this out so that you don't lose the buffer you just stole... + aDest.mCapacity=theTempStr.mCapacity; + aDest.mOwnsBuffer=theTempStr.mOwnsBuffer; + + } + + else { + //shift the chars right by theDelta... + (*gShiftChars[aDest.mCharSize][KSHIFTRIGHT])(aDest.mStr,aDest.mLength,aDestOffset,theLength); - //now insert new chars, starting at offset - (*gCopyChars[aSource.mCharSize][aDest.mCharSize])(aDest.mStr,aDestOffset,aSource.mStr,aSrcOffset,theLength); + //now insert new chars, starting at offset + (*gCopyChars[aSource.mCharSize][aDest.mCharSize])(aDest.mStr,aDestOffset,aSource.mStr,aSrcOffset,theLength); + } - //finally, make sure to update the string length... + //finally, make sure to update the string length... aDest.mLength+=theLength; AddNullTerminator(aDest); diff --git a/mozilla/xpcom/string/obsolete/nsStr.h b/mozilla/xpcom/string/obsolete/nsStr.h index 9d2ebac21d1..daf814e797e 100644 --- a/mozilla/xpcom/string/obsolete/nsStr.h +++ b/mozilla/xpcom/string/obsolete/nsStr.h @@ -173,7 +173,7 @@ enum eCharSize {eOneByte=0,eTwoByte=1}; #define kRadix16 (16) #define kAutoDetect (100) #define kRadixUnknown (kAutoDetect+1) -const PRInt32 kDefaultStringSize = 32; +const PRInt32 kDefaultStringSize = 64; const PRInt32 kNotFound = -1;