diff --git a/mozilla/base/src/nsString.cpp b/mozilla/base/src/nsString.cpp index ace4aa346c1..59fce5d475f 100644 --- a/mozilla/base/src/nsString.cpp +++ b/mozilla/base/src/nsString.cpp @@ -33,21 +33,17 @@ const char* kOutOfBoundsError = "Error: out of bounds"; const char* kNullPointerError = "Error: unexpected null ptr"; //********************************************** -//NOTE: Our buffer always hold capacity+1 bytes. +//NOTE: Our buffer always holds capacity+1 bytes. //********************************************** /** - * Default constructor. We assume that this string will have - * a bunch of Append's or SetString's done to it, therefore - * we start with a mid sized buffer. + * Default constructor. Assumes the string will be empty, and + * so it starts with a capacity of 0 */ nsString::nsString() { mLength = mCapacity = 0; mStr = 0; - // Size to 4*kGrowthDelta (EnsureCapacityFor adds in kGrowthDelta so - // subtract it before calling) - EnsureCapacityFor(4*kGrowthDelta - kGrowthDelta); } nsString::nsString(const char* anISOLatin1) { @@ -85,24 +81,6 @@ nsString::nsString(const PRUnichar* aUnicodeStr){ this->SetString(aUnicodeStr,len); } -/*------------------------------------------------------- - * special subclas constructor - * this will optionally not allocate a buffer - * but the subclass must - * @update psl 4/16/98 - * @param - * @return - *------------------------------------------------------*/ -nsString::nsString(PRBool aSubclassBuffer) -{ - mLength=mCapacity=0; - mStr=0; - if (PR_FALSE == aSubclassBuffer) { - EnsureCapacityFor(1); - this->SetString(""); - } -} - /*------------------------------------------------------- * standard destructor * @update gess 3/27/98 @@ -647,8 +625,11 @@ nsString& nsString::SetString(const PRUnichar* aStr,PRInt32 aLength) { mStr[mLength]=0; } else { - mLength=0; //This little bit of code handles the case - mStr[0]=0; //where some blockhead hands us a null string + mLength=0; //This little bit of code handles the case + //where some blockhead hands us a null string + if (nsnull != mStr) { + mStr[0]=0; + } } return *this; } @@ -1907,7 +1888,7 @@ void nsString::SelfTest(void) { * @return *------------------------------------------------------*/ nsAutoString::nsAutoString() - : nsString(PR_TRUE) + : nsString() { mStr = mBuf; mLength=0; @@ -1922,7 +1903,7 @@ nsAutoString::nsAutoString() * @return *------------------------------------------------------*/ nsAutoString::nsAutoString(const char* isolatin1) - : nsString(PR_TRUE) + : nsString() { mLength=0; mCapacity = (sizeof(mBuf) / sizeof(chartype))-sizeof(chartype); @@ -1937,7 +1918,7 @@ nsAutoString::nsAutoString(const char* isolatin1) * @return *------------------------------------------------------*/ nsAutoString::nsAutoString(const nsString& other) - : nsString(PR_TRUE) + : nsString() { mLength=0; mCapacity = (sizeof(mBuf) / sizeof(chartype))-sizeof(chartype); @@ -1952,7 +1933,7 @@ nsAutoString::nsAutoString(const nsString& other) * @return *------------------------------------------------------*/ nsAutoString::nsAutoString(PRUnichar aChar) - : nsString(PR_TRUE) + : nsString() { mLength=0; mCapacity = (sizeof(mBuf) / sizeof(chartype))-sizeof(chartype); @@ -1967,7 +1948,7 @@ nsAutoString::nsAutoString(PRUnichar aChar) * @return *------------------------------------------------------*/ nsAutoString::nsAutoString(const nsAutoString& other) - : nsString(PR_TRUE) + : nsString() { mLength=0; mCapacity = (sizeof(mBuf) / sizeof(chartype))-sizeof(chartype); @@ -2007,7 +1988,7 @@ void nsAutoString::EnsureCapacityFor(PRInt32 aNewLength) { * @return *------------------------------------------------------*/ nsAutoString::nsAutoString(const PRUnichar* unicode, PRInt32 uslen) - : nsString(PR_TRUE) + : nsString() { mStr = mBuf; mCapacity = sizeof(mBuf) / sizeof(chartype); diff --git a/mozilla/base/src/nsString.h b/mozilla/base/src/nsString.h index ade0d88b314..3120b55c299 100644 --- a/mozilla/base/src/nsString.h +++ b/mozilla/base/src/nsString.h @@ -44,9 +44,7 @@ class NS_BASE nsString { nsString(const char* anISOLatin1); nsString(const nsString&); nsString(const PRUnichar* aUnicode); - protected: - // special subclass constructor - nsString(PRBool aSubclassBuffer); + public: virtual ~nsString(); diff --git a/mozilla/string/obsolete/nsString.cpp b/mozilla/string/obsolete/nsString.cpp index ace4aa346c1..59fce5d475f 100644 --- a/mozilla/string/obsolete/nsString.cpp +++ b/mozilla/string/obsolete/nsString.cpp @@ -33,21 +33,17 @@ const char* kOutOfBoundsError = "Error: out of bounds"; const char* kNullPointerError = "Error: unexpected null ptr"; //********************************************** -//NOTE: Our buffer always hold capacity+1 bytes. +//NOTE: Our buffer always holds capacity+1 bytes. //********************************************** /** - * Default constructor. We assume that this string will have - * a bunch of Append's or SetString's done to it, therefore - * we start with a mid sized buffer. + * Default constructor. Assumes the string will be empty, and + * so it starts with a capacity of 0 */ nsString::nsString() { mLength = mCapacity = 0; mStr = 0; - // Size to 4*kGrowthDelta (EnsureCapacityFor adds in kGrowthDelta so - // subtract it before calling) - EnsureCapacityFor(4*kGrowthDelta - kGrowthDelta); } nsString::nsString(const char* anISOLatin1) { @@ -85,24 +81,6 @@ nsString::nsString(const PRUnichar* aUnicodeStr){ this->SetString(aUnicodeStr,len); } -/*------------------------------------------------------- - * special subclas constructor - * this will optionally not allocate a buffer - * but the subclass must - * @update psl 4/16/98 - * @param - * @return - *------------------------------------------------------*/ -nsString::nsString(PRBool aSubclassBuffer) -{ - mLength=mCapacity=0; - mStr=0; - if (PR_FALSE == aSubclassBuffer) { - EnsureCapacityFor(1); - this->SetString(""); - } -} - /*------------------------------------------------------- * standard destructor * @update gess 3/27/98 @@ -647,8 +625,11 @@ nsString& nsString::SetString(const PRUnichar* aStr,PRInt32 aLength) { mStr[mLength]=0; } else { - mLength=0; //This little bit of code handles the case - mStr[0]=0; //where some blockhead hands us a null string + mLength=0; //This little bit of code handles the case + //where some blockhead hands us a null string + if (nsnull != mStr) { + mStr[0]=0; + } } return *this; } @@ -1907,7 +1888,7 @@ void nsString::SelfTest(void) { * @return *------------------------------------------------------*/ nsAutoString::nsAutoString() - : nsString(PR_TRUE) + : nsString() { mStr = mBuf; mLength=0; @@ -1922,7 +1903,7 @@ nsAutoString::nsAutoString() * @return *------------------------------------------------------*/ nsAutoString::nsAutoString(const char* isolatin1) - : nsString(PR_TRUE) + : nsString() { mLength=0; mCapacity = (sizeof(mBuf) / sizeof(chartype))-sizeof(chartype); @@ -1937,7 +1918,7 @@ nsAutoString::nsAutoString(const char* isolatin1) * @return *------------------------------------------------------*/ nsAutoString::nsAutoString(const nsString& other) - : nsString(PR_TRUE) + : nsString() { mLength=0; mCapacity = (sizeof(mBuf) / sizeof(chartype))-sizeof(chartype); @@ -1952,7 +1933,7 @@ nsAutoString::nsAutoString(const nsString& other) * @return *------------------------------------------------------*/ nsAutoString::nsAutoString(PRUnichar aChar) - : nsString(PR_TRUE) + : nsString() { mLength=0; mCapacity = (sizeof(mBuf) / sizeof(chartype))-sizeof(chartype); @@ -1967,7 +1948,7 @@ nsAutoString::nsAutoString(PRUnichar aChar) * @return *------------------------------------------------------*/ nsAutoString::nsAutoString(const nsAutoString& other) - : nsString(PR_TRUE) + : nsString() { mLength=0; mCapacity = (sizeof(mBuf) / sizeof(chartype))-sizeof(chartype); @@ -2007,7 +1988,7 @@ void nsAutoString::EnsureCapacityFor(PRInt32 aNewLength) { * @return *------------------------------------------------------*/ nsAutoString::nsAutoString(const PRUnichar* unicode, PRInt32 uslen) - : nsString(PR_TRUE) + : nsString() { mStr = mBuf; mCapacity = sizeof(mBuf) / sizeof(chartype); diff --git a/mozilla/string/obsolete/nsString.h b/mozilla/string/obsolete/nsString.h index ade0d88b314..3120b55c299 100644 --- a/mozilla/string/obsolete/nsString.h +++ b/mozilla/string/obsolete/nsString.h @@ -44,9 +44,7 @@ class NS_BASE nsString { nsString(const char* anISOLatin1); nsString(const nsString&); nsString(const PRUnichar* aUnicode); - protected: - // special subclass constructor - nsString(PRBool aSubclassBuffer); + public: virtual ~nsString(); diff --git a/mozilla/xpcom/ds/nsString.cpp b/mozilla/xpcom/ds/nsString.cpp index ace4aa346c1..59fce5d475f 100644 --- a/mozilla/xpcom/ds/nsString.cpp +++ b/mozilla/xpcom/ds/nsString.cpp @@ -33,21 +33,17 @@ const char* kOutOfBoundsError = "Error: out of bounds"; const char* kNullPointerError = "Error: unexpected null ptr"; //********************************************** -//NOTE: Our buffer always hold capacity+1 bytes. +//NOTE: Our buffer always holds capacity+1 bytes. //********************************************** /** - * Default constructor. We assume that this string will have - * a bunch of Append's or SetString's done to it, therefore - * we start with a mid sized buffer. + * Default constructor. Assumes the string will be empty, and + * so it starts with a capacity of 0 */ nsString::nsString() { mLength = mCapacity = 0; mStr = 0; - // Size to 4*kGrowthDelta (EnsureCapacityFor adds in kGrowthDelta so - // subtract it before calling) - EnsureCapacityFor(4*kGrowthDelta - kGrowthDelta); } nsString::nsString(const char* anISOLatin1) { @@ -85,24 +81,6 @@ nsString::nsString(const PRUnichar* aUnicodeStr){ this->SetString(aUnicodeStr,len); } -/*------------------------------------------------------- - * special subclas constructor - * this will optionally not allocate a buffer - * but the subclass must - * @update psl 4/16/98 - * @param - * @return - *------------------------------------------------------*/ -nsString::nsString(PRBool aSubclassBuffer) -{ - mLength=mCapacity=0; - mStr=0; - if (PR_FALSE == aSubclassBuffer) { - EnsureCapacityFor(1); - this->SetString(""); - } -} - /*------------------------------------------------------- * standard destructor * @update gess 3/27/98 @@ -647,8 +625,11 @@ nsString& nsString::SetString(const PRUnichar* aStr,PRInt32 aLength) { mStr[mLength]=0; } else { - mLength=0; //This little bit of code handles the case - mStr[0]=0; //where some blockhead hands us a null string + mLength=0; //This little bit of code handles the case + //where some blockhead hands us a null string + if (nsnull != mStr) { + mStr[0]=0; + } } return *this; } @@ -1907,7 +1888,7 @@ void nsString::SelfTest(void) { * @return *------------------------------------------------------*/ nsAutoString::nsAutoString() - : nsString(PR_TRUE) + : nsString() { mStr = mBuf; mLength=0; @@ -1922,7 +1903,7 @@ nsAutoString::nsAutoString() * @return *------------------------------------------------------*/ nsAutoString::nsAutoString(const char* isolatin1) - : nsString(PR_TRUE) + : nsString() { mLength=0; mCapacity = (sizeof(mBuf) / sizeof(chartype))-sizeof(chartype); @@ -1937,7 +1918,7 @@ nsAutoString::nsAutoString(const char* isolatin1) * @return *------------------------------------------------------*/ nsAutoString::nsAutoString(const nsString& other) - : nsString(PR_TRUE) + : nsString() { mLength=0; mCapacity = (sizeof(mBuf) / sizeof(chartype))-sizeof(chartype); @@ -1952,7 +1933,7 @@ nsAutoString::nsAutoString(const nsString& other) * @return *------------------------------------------------------*/ nsAutoString::nsAutoString(PRUnichar aChar) - : nsString(PR_TRUE) + : nsString() { mLength=0; mCapacity = (sizeof(mBuf) / sizeof(chartype))-sizeof(chartype); @@ -1967,7 +1948,7 @@ nsAutoString::nsAutoString(PRUnichar aChar) * @return *------------------------------------------------------*/ nsAutoString::nsAutoString(const nsAutoString& other) - : nsString(PR_TRUE) + : nsString() { mLength=0; mCapacity = (sizeof(mBuf) / sizeof(chartype))-sizeof(chartype); @@ -2007,7 +1988,7 @@ void nsAutoString::EnsureCapacityFor(PRInt32 aNewLength) { * @return *------------------------------------------------------*/ nsAutoString::nsAutoString(const PRUnichar* unicode, PRInt32 uslen) - : nsString(PR_TRUE) + : nsString() { mStr = mBuf; mCapacity = sizeof(mBuf) / sizeof(chartype); diff --git a/mozilla/xpcom/ds/nsString.h b/mozilla/xpcom/ds/nsString.h index ade0d88b314..3120b55c299 100644 --- a/mozilla/xpcom/ds/nsString.h +++ b/mozilla/xpcom/ds/nsString.h @@ -44,9 +44,7 @@ class NS_BASE nsString { nsString(const char* anISOLatin1); nsString(const nsString&); nsString(const PRUnichar* aUnicode); - protected: - // special subclass constructor - nsString(PRBool aSubclassBuffer); + public: virtual ~nsString(); diff --git a/mozilla/xpcom/string/obsolete/nsString.cpp b/mozilla/xpcom/string/obsolete/nsString.cpp index ace4aa346c1..59fce5d475f 100644 --- a/mozilla/xpcom/string/obsolete/nsString.cpp +++ b/mozilla/xpcom/string/obsolete/nsString.cpp @@ -33,21 +33,17 @@ const char* kOutOfBoundsError = "Error: out of bounds"; const char* kNullPointerError = "Error: unexpected null ptr"; //********************************************** -//NOTE: Our buffer always hold capacity+1 bytes. +//NOTE: Our buffer always holds capacity+1 bytes. //********************************************** /** - * Default constructor. We assume that this string will have - * a bunch of Append's or SetString's done to it, therefore - * we start with a mid sized buffer. + * Default constructor. Assumes the string will be empty, and + * so it starts with a capacity of 0 */ nsString::nsString() { mLength = mCapacity = 0; mStr = 0; - // Size to 4*kGrowthDelta (EnsureCapacityFor adds in kGrowthDelta so - // subtract it before calling) - EnsureCapacityFor(4*kGrowthDelta - kGrowthDelta); } nsString::nsString(const char* anISOLatin1) { @@ -85,24 +81,6 @@ nsString::nsString(const PRUnichar* aUnicodeStr){ this->SetString(aUnicodeStr,len); } -/*------------------------------------------------------- - * special subclas constructor - * this will optionally not allocate a buffer - * but the subclass must - * @update psl 4/16/98 - * @param - * @return - *------------------------------------------------------*/ -nsString::nsString(PRBool aSubclassBuffer) -{ - mLength=mCapacity=0; - mStr=0; - if (PR_FALSE == aSubclassBuffer) { - EnsureCapacityFor(1); - this->SetString(""); - } -} - /*------------------------------------------------------- * standard destructor * @update gess 3/27/98 @@ -647,8 +625,11 @@ nsString& nsString::SetString(const PRUnichar* aStr,PRInt32 aLength) { mStr[mLength]=0; } else { - mLength=0; //This little bit of code handles the case - mStr[0]=0; //where some blockhead hands us a null string + mLength=0; //This little bit of code handles the case + //where some blockhead hands us a null string + if (nsnull != mStr) { + mStr[0]=0; + } } return *this; } @@ -1907,7 +1888,7 @@ void nsString::SelfTest(void) { * @return *------------------------------------------------------*/ nsAutoString::nsAutoString() - : nsString(PR_TRUE) + : nsString() { mStr = mBuf; mLength=0; @@ -1922,7 +1903,7 @@ nsAutoString::nsAutoString() * @return *------------------------------------------------------*/ nsAutoString::nsAutoString(const char* isolatin1) - : nsString(PR_TRUE) + : nsString() { mLength=0; mCapacity = (sizeof(mBuf) / sizeof(chartype))-sizeof(chartype); @@ -1937,7 +1918,7 @@ nsAutoString::nsAutoString(const char* isolatin1) * @return *------------------------------------------------------*/ nsAutoString::nsAutoString(const nsString& other) - : nsString(PR_TRUE) + : nsString() { mLength=0; mCapacity = (sizeof(mBuf) / sizeof(chartype))-sizeof(chartype); @@ -1952,7 +1933,7 @@ nsAutoString::nsAutoString(const nsString& other) * @return *------------------------------------------------------*/ nsAutoString::nsAutoString(PRUnichar aChar) - : nsString(PR_TRUE) + : nsString() { mLength=0; mCapacity = (sizeof(mBuf) / sizeof(chartype))-sizeof(chartype); @@ -1967,7 +1948,7 @@ nsAutoString::nsAutoString(PRUnichar aChar) * @return *------------------------------------------------------*/ nsAutoString::nsAutoString(const nsAutoString& other) - : nsString(PR_TRUE) + : nsString() { mLength=0; mCapacity = (sizeof(mBuf) / sizeof(chartype))-sizeof(chartype); @@ -2007,7 +1988,7 @@ void nsAutoString::EnsureCapacityFor(PRInt32 aNewLength) { * @return *------------------------------------------------------*/ nsAutoString::nsAutoString(const PRUnichar* unicode, PRInt32 uslen) - : nsString(PR_TRUE) + : nsString() { mStr = mBuf; mCapacity = sizeof(mBuf) / sizeof(chartype); diff --git a/mozilla/xpcom/string/obsolete/nsString.h b/mozilla/xpcom/string/obsolete/nsString.h index ade0d88b314..3120b55c299 100644 --- a/mozilla/xpcom/string/obsolete/nsString.h +++ b/mozilla/xpcom/string/obsolete/nsString.h @@ -44,9 +44,7 @@ class NS_BASE nsString { nsString(const char* anISOLatin1); nsString(const nsString&); nsString(const PRUnichar* aUnicode); - protected: - // special subclass constructor - nsString(PRBool aSubclassBuffer); + public: virtual ~nsString();