fix for bug 108597 - move mOwnsBuffer and mCharSize into smaller variables to reduce nsStr's overall size

r=jag, sr=waterson
This commit is contained in:
alecf%netscape.com 2001-11-06 22:50:13 +00:00
Родитель 0234615ad0
Коммит 61f5ed73c5
6 изменённых файлов: 14 добавлений и 12 удалений

Просмотреть файл

@ -132,7 +132,7 @@ PRBool nsStr::GrowCapacity(nsStr& aDest,PRUint32 aNewLength) {
PRBool result=PR_TRUE; PRBool result=PR_TRUE;
if(aNewLength>aDest.mCapacity) { if(aNewLength>aDest.mCapacity) {
nsStr theTempStr; nsStr theTempStr;
nsStr::Initialize(theTempStr,aDest.mCharSize); nsStr::Initialize(theTempStr,eCharSize(aDest.mCharSize));
#ifndef NS_USE_OLD_STRING_ALLOCATION_STRATEGY #ifndef NS_USE_OLD_STRING_ALLOCATION_STRATEGY
// the new strategy is, allocate exact size, double on grows // the new strategy is, allocate exact size, double on grows
@ -232,7 +232,7 @@ void nsStr::StrInsert( nsStr& aDest,PRUint32 aDestOffset,const nsStr& aSource,PR
if(aDest.mLength+theLength > aDest.mCapacity) { if(aDest.mLength+theLength > aDest.mCapacity) {
nsStr theTempStr; nsStr theTempStr;
nsStr::Initialize(theTempStr,aDest.mCharSize); nsStr::Initialize(theTempStr,eCharSize(aDest.mCharSize));
PRBool isBigEnough=EnsureCapacity(theTempStr,aDest.mLength+theLength); //grow the temp buffer to the right size PRBool isBigEnough=EnsureCapacity(theTempStr,aDest.mLength+theLength); //grow the temp buffer to the right size

Просмотреть файл

@ -455,14 +455,15 @@ struct NS_COM nsStr {
PRUint32 mLength; PRUint32 mLength;
PRUint32 mCapacity; PRUint32 mCapacity;
eCharSize mCharSize;
PRBool mOwnsBuffer;
union { union {
char* mStr; char* mStr;
PRUnichar* mUStr; PRUnichar* mUStr;
}; };
PRInt8 mCharSize;
PRPackedBool mOwnsBuffer;
private: private:
static PRBool Alloc(nsStr& aString,PRUint32 aCount); static PRBool Alloc(nsStr& aString,PRUint32 aCount);
static PRBool Realloc(nsStr& aString,PRUint32 aCount); static PRBool Realloc(nsStr& aString,PRUint32 aCount);

Просмотреть файл

@ -114,7 +114,7 @@ nsCString::nsCString(const nsStr &aString) {
* @param reference to another nsCString * @param reference to another nsCString
*/ */
nsCString::nsCString(const nsCString& aString) { nsCString::nsCString(const nsCString& aString) {
Initialize(*this,aString.mCharSize); Initialize(*this,eCharSize(aString.mCharSize));
StrAssign(*this,aString,0,aString.mLength); StrAssign(*this,aString,0,aString.mLength);
} }

Просмотреть файл

@ -132,7 +132,7 @@ PRBool nsStr::GrowCapacity(nsStr& aDest,PRUint32 aNewLength) {
PRBool result=PR_TRUE; PRBool result=PR_TRUE;
if(aNewLength>aDest.mCapacity) { if(aNewLength>aDest.mCapacity) {
nsStr theTempStr; nsStr theTempStr;
nsStr::Initialize(theTempStr,aDest.mCharSize); nsStr::Initialize(theTempStr,eCharSize(aDest.mCharSize));
#ifndef NS_USE_OLD_STRING_ALLOCATION_STRATEGY #ifndef NS_USE_OLD_STRING_ALLOCATION_STRATEGY
// the new strategy is, allocate exact size, double on grows // the new strategy is, allocate exact size, double on grows
@ -232,7 +232,7 @@ void nsStr::StrInsert( nsStr& aDest,PRUint32 aDestOffset,const nsStr& aSource,PR
if(aDest.mLength+theLength > aDest.mCapacity) { if(aDest.mLength+theLength > aDest.mCapacity) {
nsStr theTempStr; nsStr theTempStr;
nsStr::Initialize(theTempStr,aDest.mCharSize); nsStr::Initialize(theTempStr,eCharSize(aDest.mCharSize));
PRBool isBigEnough=EnsureCapacity(theTempStr,aDest.mLength+theLength); //grow the temp buffer to the right size PRBool isBigEnough=EnsureCapacity(theTempStr,aDest.mLength+theLength); //grow the temp buffer to the right size

Просмотреть файл

@ -455,14 +455,15 @@ struct NS_COM nsStr {
PRUint32 mLength; PRUint32 mLength;
PRUint32 mCapacity; PRUint32 mCapacity;
eCharSize mCharSize;
PRBool mOwnsBuffer;
union { union {
char* mStr; char* mStr;
PRUnichar* mUStr; PRUnichar* mUStr;
}; };
PRInt8 mCharSize;
PRPackedBool mOwnsBuffer;
private: private:
static PRBool Alloc(nsStr& aString,PRUint32 aCount); static PRBool Alloc(nsStr& aString,PRUint32 aCount);
static PRBool Realloc(nsStr& aString,PRUint32 aCount); static PRBool Realloc(nsStr& aString,PRUint32 aCount);

Просмотреть файл

@ -114,7 +114,7 @@ nsCString::nsCString(const nsStr &aString) {
* @param reference to another nsCString * @param reference to another nsCString
*/ */
nsCString::nsCString(const nsCString& aString) { nsCString::nsCString(const nsCString& aString) {
Initialize(*this,aString.mCharSize); Initialize(*this,eCharSize(aString.mCharSize));
StrAssign(*this,aString,0,aString.mLength); StrAssign(*this,aString,0,aString.mLength);
} }