diff --git a/mozilla/base/src/nsString.cpp b/mozilla/base/src/nsString.cpp index 9f5ada26569..e3dd9f715ba 100644 --- a/mozilla/base/src/nsString.cpp +++ b/mozilla/base/src/nsString.cpp @@ -87,6 +87,26 @@ nsString::nsString(const PRUnichar* aUnicodeStr){ SelfTest(); } +/*------------------------------------------------------- + * 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(""); + } + if(++mInstanceCount==1) + SelfTest(); +} + /*------------------------------------------------------- * standard destructor * @update gess 3/27/98 @@ -1829,7 +1849,9 @@ void nsString::SelfTest(void) { * @param * @return *------------------------------------------------------*/ -nsAutoString::nsAutoString() : nsString() { +nsAutoString::nsAutoString() + : nsString(PR_TRUE) +{ mStr = mBuf; mLength=0; mCapacity = (sizeof(mBuf) / sizeof(chartype))-sizeof(chartype); @@ -1841,7 +1863,8 @@ nsAutoString::nsAutoString() : nsString() { * @param * @return *------------------------------------------------------*/ -nsAutoString::nsAutoString(const char* isolatin1) : nsString() +nsAutoString::nsAutoString(const char* isolatin1) + : nsString(PR_TRUE) { mLength=0; mCapacity = (sizeof(mBuf) / sizeof(chartype))-sizeof(chartype); @@ -1855,7 +1878,9 @@ nsAutoString::nsAutoString(const char* isolatin1) : nsString() * @param * @return *------------------------------------------------------*/ -nsAutoString::nsAutoString(const nsString& other) { +nsAutoString::nsAutoString(const nsString& other) + : nsString(PR_TRUE) +{ mLength=0; mCapacity = (sizeof(mBuf) / sizeof(chartype))-sizeof(chartype); mStr=mBuf; @@ -1868,7 +1893,9 @@ nsAutoString::nsAutoString(const nsString& other) { * @param * @return *------------------------------------------------------*/ -nsAutoString::nsAutoString(PRUnichar aChar) { +nsAutoString::nsAutoString(PRUnichar aChar) + : nsString(PR_TRUE) +{ mLength=0; mCapacity = (sizeof(mBuf) / sizeof(chartype))-sizeof(chartype); mStr=mBuf; @@ -1881,7 +1908,9 @@ nsAutoString::nsAutoString(PRUnichar aChar) { * @param * @return *------------------------------------------------------*/ -nsAutoString::nsAutoString(const nsAutoString& other) { +nsAutoString::nsAutoString(const nsAutoString& other) + : nsString(PR_TRUE) +{ mLength=0; mCapacity = (sizeof(mBuf) / sizeof(chartype))-sizeof(chartype); mStr=mBuf; @@ -1906,6 +1935,9 @@ void nsAutoString::EnsureCapacityFor(PRInt32 aNewLength) { if (mLength > 0) { nsCRT::memcpy(temp, mStr, mLength * sizeof(chartype)); } + if ((mStr != mBuf) && (0 != mStr)) { + delete [] mStr; + } mStr = temp; } } @@ -1916,7 +1948,9 @@ void nsAutoString::EnsureCapacityFor(PRInt32 aNewLength) { * @param * @return *------------------------------------------------------*/ -nsAutoString::nsAutoString(const PRUnichar* unicode, PRInt32 uslen) { +nsAutoString::nsAutoString(const PRUnichar* unicode, PRInt32 uslen) + : nsString(PR_TRUE) +{ mStr = mBuf; mCapacity = sizeof(mBuf) / sizeof(chartype); if (0 == uslen) { diff --git a/mozilla/base/src/nsString.h b/mozilla/base/src/nsString.h index dc26545c53b..d02e353530a 100644 --- a/mozilla/base/src/nsString.h +++ b/mozilla/base/src/nsString.h @@ -43,6 +43,9 @@ class NS_BASE nsString { nsString(const char* anISOLatin1=""); nsString(const nsString&); nsString(const PRUnichar* aUnicode); + protected: + nsString(PRBool aSubclassBuffer); // special subclas constructor + public: virtual ~nsString(); PRInt32 Length() const { return mLength; } diff --git a/mozilla/string/obsolete/nsString.cpp b/mozilla/string/obsolete/nsString.cpp index 9f5ada26569..e3dd9f715ba 100644 --- a/mozilla/string/obsolete/nsString.cpp +++ b/mozilla/string/obsolete/nsString.cpp @@ -87,6 +87,26 @@ nsString::nsString(const PRUnichar* aUnicodeStr){ SelfTest(); } +/*------------------------------------------------------- + * 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(""); + } + if(++mInstanceCount==1) + SelfTest(); +} + /*------------------------------------------------------- * standard destructor * @update gess 3/27/98 @@ -1829,7 +1849,9 @@ void nsString::SelfTest(void) { * @param * @return *------------------------------------------------------*/ -nsAutoString::nsAutoString() : nsString() { +nsAutoString::nsAutoString() + : nsString(PR_TRUE) +{ mStr = mBuf; mLength=0; mCapacity = (sizeof(mBuf) / sizeof(chartype))-sizeof(chartype); @@ -1841,7 +1863,8 @@ nsAutoString::nsAutoString() : nsString() { * @param * @return *------------------------------------------------------*/ -nsAutoString::nsAutoString(const char* isolatin1) : nsString() +nsAutoString::nsAutoString(const char* isolatin1) + : nsString(PR_TRUE) { mLength=0; mCapacity = (sizeof(mBuf) / sizeof(chartype))-sizeof(chartype); @@ -1855,7 +1878,9 @@ nsAutoString::nsAutoString(const char* isolatin1) : nsString() * @param * @return *------------------------------------------------------*/ -nsAutoString::nsAutoString(const nsString& other) { +nsAutoString::nsAutoString(const nsString& other) + : nsString(PR_TRUE) +{ mLength=0; mCapacity = (sizeof(mBuf) / sizeof(chartype))-sizeof(chartype); mStr=mBuf; @@ -1868,7 +1893,9 @@ nsAutoString::nsAutoString(const nsString& other) { * @param * @return *------------------------------------------------------*/ -nsAutoString::nsAutoString(PRUnichar aChar) { +nsAutoString::nsAutoString(PRUnichar aChar) + : nsString(PR_TRUE) +{ mLength=0; mCapacity = (sizeof(mBuf) / sizeof(chartype))-sizeof(chartype); mStr=mBuf; @@ -1881,7 +1908,9 @@ nsAutoString::nsAutoString(PRUnichar aChar) { * @param * @return *------------------------------------------------------*/ -nsAutoString::nsAutoString(const nsAutoString& other) { +nsAutoString::nsAutoString(const nsAutoString& other) + : nsString(PR_TRUE) +{ mLength=0; mCapacity = (sizeof(mBuf) / sizeof(chartype))-sizeof(chartype); mStr=mBuf; @@ -1906,6 +1935,9 @@ void nsAutoString::EnsureCapacityFor(PRInt32 aNewLength) { if (mLength > 0) { nsCRT::memcpy(temp, mStr, mLength * sizeof(chartype)); } + if ((mStr != mBuf) && (0 != mStr)) { + delete [] mStr; + } mStr = temp; } } @@ -1916,7 +1948,9 @@ void nsAutoString::EnsureCapacityFor(PRInt32 aNewLength) { * @param * @return *------------------------------------------------------*/ -nsAutoString::nsAutoString(const PRUnichar* unicode, PRInt32 uslen) { +nsAutoString::nsAutoString(const PRUnichar* unicode, PRInt32 uslen) + : nsString(PR_TRUE) +{ mStr = mBuf; mCapacity = sizeof(mBuf) / sizeof(chartype); if (0 == uslen) { diff --git a/mozilla/string/obsolete/nsString.h b/mozilla/string/obsolete/nsString.h index dc26545c53b..d02e353530a 100644 --- a/mozilla/string/obsolete/nsString.h +++ b/mozilla/string/obsolete/nsString.h @@ -43,6 +43,9 @@ class NS_BASE nsString { nsString(const char* anISOLatin1=""); nsString(const nsString&); nsString(const PRUnichar* aUnicode); + protected: + nsString(PRBool aSubclassBuffer); // special subclas constructor + public: virtual ~nsString(); PRInt32 Length() const { return mLength; } diff --git a/mozilla/xpcom/ds/nsString.cpp b/mozilla/xpcom/ds/nsString.cpp index 9f5ada26569..e3dd9f715ba 100644 --- a/mozilla/xpcom/ds/nsString.cpp +++ b/mozilla/xpcom/ds/nsString.cpp @@ -87,6 +87,26 @@ nsString::nsString(const PRUnichar* aUnicodeStr){ SelfTest(); } +/*------------------------------------------------------- + * 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(""); + } + if(++mInstanceCount==1) + SelfTest(); +} + /*------------------------------------------------------- * standard destructor * @update gess 3/27/98 @@ -1829,7 +1849,9 @@ void nsString::SelfTest(void) { * @param * @return *------------------------------------------------------*/ -nsAutoString::nsAutoString() : nsString() { +nsAutoString::nsAutoString() + : nsString(PR_TRUE) +{ mStr = mBuf; mLength=0; mCapacity = (sizeof(mBuf) / sizeof(chartype))-sizeof(chartype); @@ -1841,7 +1863,8 @@ nsAutoString::nsAutoString() : nsString() { * @param * @return *------------------------------------------------------*/ -nsAutoString::nsAutoString(const char* isolatin1) : nsString() +nsAutoString::nsAutoString(const char* isolatin1) + : nsString(PR_TRUE) { mLength=0; mCapacity = (sizeof(mBuf) / sizeof(chartype))-sizeof(chartype); @@ -1855,7 +1878,9 @@ nsAutoString::nsAutoString(const char* isolatin1) : nsString() * @param * @return *------------------------------------------------------*/ -nsAutoString::nsAutoString(const nsString& other) { +nsAutoString::nsAutoString(const nsString& other) + : nsString(PR_TRUE) +{ mLength=0; mCapacity = (sizeof(mBuf) / sizeof(chartype))-sizeof(chartype); mStr=mBuf; @@ -1868,7 +1893,9 @@ nsAutoString::nsAutoString(const nsString& other) { * @param * @return *------------------------------------------------------*/ -nsAutoString::nsAutoString(PRUnichar aChar) { +nsAutoString::nsAutoString(PRUnichar aChar) + : nsString(PR_TRUE) +{ mLength=0; mCapacity = (sizeof(mBuf) / sizeof(chartype))-sizeof(chartype); mStr=mBuf; @@ -1881,7 +1908,9 @@ nsAutoString::nsAutoString(PRUnichar aChar) { * @param * @return *------------------------------------------------------*/ -nsAutoString::nsAutoString(const nsAutoString& other) { +nsAutoString::nsAutoString(const nsAutoString& other) + : nsString(PR_TRUE) +{ mLength=0; mCapacity = (sizeof(mBuf) / sizeof(chartype))-sizeof(chartype); mStr=mBuf; @@ -1906,6 +1935,9 @@ void nsAutoString::EnsureCapacityFor(PRInt32 aNewLength) { if (mLength > 0) { nsCRT::memcpy(temp, mStr, mLength * sizeof(chartype)); } + if ((mStr != mBuf) && (0 != mStr)) { + delete [] mStr; + } mStr = temp; } } @@ -1916,7 +1948,9 @@ void nsAutoString::EnsureCapacityFor(PRInt32 aNewLength) { * @param * @return *------------------------------------------------------*/ -nsAutoString::nsAutoString(const PRUnichar* unicode, PRInt32 uslen) { +nsAutoString::nsAutoString(const PRUnichar* unicode, PRInt32 uslen) + : nsString(PR_TRUE) +{ mStr = mBuf; mCapacity = sizeof(mBuf) / sizeof(chartype); if (0 == uslen) { diff --git a/mozilla/xpcom/ds/nsString.h b/mozilla/xpcom/ds/nsString.h index dc26545c53b..d02e353530a 100644 --- a/mozilla/xpcom/ds/nsString.h +++ b/mozilla/xpcom/ds/nsString.h @@ -43,6 +43,9 @@ class NS_BASE nsString { nsString(const char* anISOLatin1=""); nsString(const nsString&); nsString(const PRUnichar* aUnicode); + protected: + nsString(PRBool aSubclassBuffer); // special subclas constructor + public: virtual ~nsString(); PRInt32 Length() const { return mLength; } diff --git a/mozilla/xpcom/string/obsolete/nsString.cpp b/mozilla/xpcom/string/obsolete/nsString.cpp index 9f5ada26569..e3dd9f715ba 100644 --- a/mozilla/xpcom/string/obsolete/nsString.cpp +++ b/mozilla/xpcom/string/obsolete/nsString.cpp @@ -87,6 +87,26 @@ nsString::nsString(const PRUnichar* aUnicodeStr){ SelfTest(); } +/*------------------------------------------------------- + * 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(""); + } + if(++mInstanceCount==1) + SelfTest(); +} + /*------------------------------------------------------- * standard destructor * @update gess 3/27/98 @@ -1829,7 +1849,9 @@ void nsString::SelfTest(void) { * @param * @return *------------------------------------------------------*/ -nsAutoString::nsAutoString() : nsString() { +nsAutoString::nsAutoString() + : nsString(PR_TRUE) +{ mStr = mBuf; mLength=0; mCapacity = (sizeof(mBuf) / sizeof(chartype))-sizeof(chartype); @@ -1841,7 +1863,8 @@ nsAutoString::nsAutoString() : nsString() { * @param * @return *------------------------------------------------------*/ -nsAutoString::nsAutoString(const char* isolatin1) : nsString() +nsAutoString::nsAutoString(const char* isolatin1) + : nsString(PR_TRUE) { mLength=0; mCapacity = (sizeof(mBuf) / sizeof(chartype))-sizeof(chartype); @@ -1855,7 +1878,9 @@ nsAutoString::nsAutoString(const char* isolatin1) : nsString() * @param * @return *------------------------------------------------------*/ -nsAutoString::nsAutoString(const nsString& other) { +nsAutoString::nsAutoString(const nsString& other) + : nsString(PR_TRUE) +{ mLength=0; mCapacity = (sizeof(mBuf) / sizeof(chartype))-sizeof(chartype); mStr=mBuf; @@ -1868,7 +1893,9 @@ nsAutoString::nsAutoString(const nsString& other) { * @param * @return *------------------------------------------------------*/ -nsAutoString::nsAutoString(PRUnichar aChar) { +nsAutoString::nsAutoString(PRUnichar aChar) + : nsString(PR_TRUE) +{ mLength=0; mCapacity = (sizeof(mBuf) / sizeof(chartype))-sizeof(chartype); mStr=mBuf; @@ -1881,7 +1908,9 @@ nsAutoString::nsAutoString(PRUnichar aChar) { * @param * @return *------------------------------------------------------*/ -nsAutoString::nsAutoString(const nsAutoString& other) { +nsAutoString::nsAutoString(const nsAutoString& other) + : nsString(PR_TRUE) +{ mLength=0; mCapacity = (sizeof(mBuf) / sizeof(chartype))-sizeof(chartype); mStr=mBuf; @@ -1906,6 +1935,9 @@ void nsAutoString::EnsureCapacityFor(PRInt32 aNewLength) { if (mLength > 0) { nsCRT::memcpy(temp, mStr, mLength * sizeof(chartype)); } + if ((mStr != mBuf) && (0 != mStr)) { + delete [] mStr; + } mStr = temp; } } @@ -1916,7 +1948,9 @@ void nsAutoString::EnsureCapacityFor(PRInt32 aNewLength) { * @param * @return *------------------------------------------------------*/ -nsAutoString::nsAutoString(const PRUnichar* unicode, PRInt32 uslen) { +nsAutoString::nsAutoString(const PRUnichar* unicode, PRInt32 uslen) + : nsString(PR_TRUE) +{ mStr = mBuf; mCapacity = sizeof(mBuf) / sizeof(chartype); if (0 == uslen) { diff --git a/mozilla/xpcom/string/obsolete/nsString.h b/mozilla/xpcom/string/obsolete/nsString.h index dc26545c53b..d02e353530a 100644 --- a/mozilla/xpcom/string/obsolete/nsString.h +++ b/mozilla/xpcom/string/obsolete/nsString.h @@ -43,6 +43,9 @@ class NS_BASE nsString { nsString(const char* anISOLatin1=""); nsString(const nsString&); nsString(const PRUnichar* aUnicode); + protected: + nsString(PRBool aSubclassBuffer); // special subclas constructor + public: virtual ~nsString(); PRInt32 Length() const { return mLength; }