diff --git a/mozilla/base/src/nsString.cpp b/mozilla/base/src/nsString.cpp index e7027e6c183..848a91a58c7 100644 --- a/mozilla/base/src/nsString.cpp +++ b/mozilla/base/src/nsString.cpp @@ -37,23 +37,25 @@ const char* kNullPointerError = "Error: unexpected null ptr"; //********************************************** -PRInt32 nsString::mInstanceCount=0; +/** + * 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. + */ +nsString::nsString() { + mLength = mCapacity = 0; + mStr = 0; + // Size to 4*kGrowthDelta (EnsureCapacityFor adds in kGrowthDelta so + // subtract it before calling) + EnsureCapacityFor(4*kGrowthDelta - kGrowthDelta); +} -/**------------------------------------------------------- - * Default constructor - * - * @update gess 3/31/98 - * @param - * @return - *------------------------------------------------------*/ -nsString::nsString(const char* anISOLatin1/*=""*/) { +nsString::nsString(const char* anISOLatin1) { mLength=mCapacity=0; mStr=0; PRInt32 len=strlen(anISOLatin1); EnsureCapacityFor(len); this->SetString(anISOLatin1,len); - if(++mInstanceCount==1) - SelfTest(); } /*------------------------------------------------------- @@ -67,8 +69,6 @@ nsString::nsString(const nsString &aString) { mStr=0; EnsureCapacityFor(aString.mLength); this->SetString(aString.mStr,aString.mLength); - if(++mInstanceCount==1) - SelfTest(); } /*------------------------------------------------------- @@ -83,8 +83,6 @@ nsString::nsString(const PRUnichar* aUnicodeStr){ PRInt32 len=(aUnicodeStr) ? nsCRT::strlen(aUnicodeStr) : 0; EnsureCapacityFor(len); this->SetString(aUnicodeStr,len); - if(++mInstanceCount==1) - SelfTest(); } /*------------------------------------------------------- @@ -103,8 +101,6 @@ nsString::nsString(PRBool aSubclassBuffer) EnsureCapacityFor(1); this->SetString(""); } - if(++mInstanceCount==1) - SelfTest(); } /*------------------------------------------------------- @@ -409,7 +405,8 @@ void nsString::ToUpperCase() *------------------------------------------------------*/ void nsString::ToLowerCase(nsString& aOut) const { - aOut.SetLength(mLength); + aOut.EnsureCapacityFor(mLength); + aOut.mLength = mLength; chartype* to = aOut.mStr; chartype* from = mStr; chartype* end = from + mLength; @@ -431,7 +428,8 @@ void nsString::ToLowerCase(nsString& aOut) const *------------------------------------------------------*/ void nsString::ToUpperCase(nsString& aOut) const { - aOut.SetLength(mLength); + aOut.EnsureCapacityFor(mLength); + aOut.mLength = mLength; chartype* to = aOut.mStr; chartype* from = mStr; chartype* end = from + mLength; @@ -494,7 +492,7 @@ PRUnichar* nsString::ToNewUnicode() const *------------------------------------------------------*/ void nsString::ToString(nsString& aString) const { - aString.SetLength(0); + aString.mLength = 0; aString.Append(mStr, mLength); } diff --git a/mozilla/base/src/nsString.h b/mozilla/base/src/nsString.h index 7b924473907..075b014e1a8 100644 --- a/mozilla/base/src/nsString.h +++ b/mozilla/base/src/nsString.h @@ -40,11 +40,13 @@ class NS_BASE nsString { public: - nsString(const char* anISOLatin1=""); + nsString(); + nsString(const char* anISOLatin1); nsString(const nsString&); nsString(const PRUnichar* aUnicode); protected: - nsString(PRBool aSubclassBuffer); // special subclas constructor + // special subclass constructor + nsString(PRBool aSubclassBuffer); public: virtual ~nsString(); @@ -59,12 +61,6 @@ class NS_BASE nsString { PRUnichar* GetUnicode(void) const; operator PRUnichar*() const; -#if 0 - // This is NOT allowed because it has to do a malloc to - // create the iso-latin-1 version of the unicode string - operator char*() const; -#endif - PRUnichar* operator()() const; PRUnichar operator()(PRInt32 i) const; PRUnichar& operator[](PRInt32 i) const; @@ -199,7 +195,6 @@ typedef PRUnichar chartype; chartype* mStr; PRInt32 mLength; PRInt32 mCapacity; - static PRInt32 mInstanceCount; }; extern NS_BASE int fputs(const nsString& aString, FILE* out); diff --git a/mozilla/string/obsolete/nsString.cpp b/mozilla/string/obsolete/nsString.cpp index e7027e6c183..848a91a58c7 100644 --- a/mozilla/string/obsolete/nsString.cpp +++ b/mozilla/string/obsolete/nsString.cpp @@ -37,23 +37,25 @@ const char* kNullPointerError = "Error: unexpected null ptr"; //********************************************** -PRInt32 nsString::mInstanceCount=0; +/** + * 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. + */ +nsString::nsString() { + mLength = mCapacity = 0; + mStr = 0; + // Size to 4*kGrowthDelta (EnsureCapacityFor adds in kGrowthDelta so + // subtract it before calling) + EnsureCapacityFor(4*kGrowthDelta - kGrowthDelta); +} -/**------------------------------------------------------- - * Default constructor - * - * @update gess 3/31/98 - * @param - * @return - *------------------------------------------------------*/ -nsString::nsString(const char* anISOLatin1/*=""*/) { +nsString::nsString(const char* anISOLatin1) { mLength=mCapacity=0; mStr=0; PRInt32 len=strlen(anISOLatin1); EnsureCapacityFor(len); this->SetString(anISOLatin1,len); - if(++mInstanceCount==1) - SelfTest(); } /*------------------------------------------------------- @@ -67,8 +69,6 @@ nsString::nsString(const nsString &aString) { mStr=0; EnsureCapacityFor(aString.mLength); this->SetString(aString.mStr,aString.mLength); - if(++mInstanceCount==1) - SelfTest(); } /*------------------------------------------------------- @@ -83,8 +83,6 @@ nsString::nsString(const PRUnichar* aUnicodeStr){ PRInt32 len=(aUnicodeStr) ? nsCRT::strlen(aUnicodeStr) : 0; EnsureCapacityFor(len); this->SetString(aUnicodeStr,len); - if(++mInstanceCount==1) - SelfTest(); } /*------------------------------------------------------- @@ -103,8 +101,6 @@ nsString::nsString(PRBool aSubclassBuffer) EnsureCapacityFor(1); this->SetString(""); } - if(++mInstanceCount==1) - SelfTest(); } /*------------------------------------------------------- @@ -409,7 +405,8 @@ void nsString::ToUpperCase() *------------------------------------------------------*/ void nsString::ToLowerCase(nsString& aOut) const { - aOut.SetLength(mLength); + aOut.EnsureCapacityFor(mLength); + aOut.mLength = mLength; chartype* to = aOut.mStr; chartype* from = mStr; chartype* end = from + mLength; @@ -431,7 +428,8 @@ void nsString::ToLowerCase(nsString& aOut) const *------------------------------------------------------*/ void nsString::ToUpperCase(nsString& aOut) const { - aOut.SetLength(mLength); + aOut.EnsureCapacityFor(mLength); + aOut.mLength = mLength; chartype* to = aOut.mStr; chartype* from = mStr; chartype* end = from + mLength; @@ -494,7 +492,7 @@ PRUnichar* nsString::ToNewUnicode() const *------------------------------------------------------*/ void nsString::ToString(nsString& aString) const { - aString.SetLength(0); + aString.mLength = 0; aString.Append(mStr, mLength); } diff --git a/mozilla/string/obsolete/nsString.h b/mozilla/string/obsolete/nsString.h index 7b924473907..075b014e1a8 100644 --- a/mozilla/string/obsolete/nsString.h +++ b/mozilla/string/obsolete/nsString.h @@ -40,11 +40,13 @@ class NS_BASE nsString { public: - nsString(const char* anISOLatin1=""); + nsString(); + nsString(const char* anISOLatin1); nsString(const nsString&); nsString(const PRUnichar* aUnicode); protected: - nsString(PRBool aSubclassBuffer); // special subclas constructor + // special subclass constructor + nsString(PRBool aSubclassBuffer); public: virtual ~nsString(); @@ -59,12 +61,6 @@ class NS_BASE nsString { PRUnichar* GetUnicode(void) const; operator PRUnichar*() const; -#if 0 - // This is NOT allowed because it has to do a malloc to - // create the iso-latin-1 version of the unicode string - operator char*() const; -#endif - PRUnichar* operator()() const; PRUnichar operator()(PRInt32 i) const; PRUnichar& operator[](PRInt32 i) const; @@ -199,7 +195,6 @@ typedef PRUnichar chartype; chartype* mStr; PRInt32 mLength; PRInt32 mCapacity; - static PRInt32 mInstanceCount; }; extern NS_BASE int fputs(const nsString& aString, FILE* out); diff --git a/mozilla/xpcom/ds/nsString.cpp b/mozilla/xpcom/ds/nsString.cpp index e7027e6c183..848a91a58c7 100644 --- a/mozilla/xpcom/ds/nsString.cpp +++ b/mozilla/xpcom/ds/nsString.cpp @@ -37,23 +37,25 @@ const char* kNullPointerError = "Error: unexpected null ptr"; //********************************************** -PRInt32 nsString::mInstanceCount=0; +/** + * 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. + */ +nsString::nsString() { + mLength = mCapacity = 0; + mStr = 0; + // Size to 4*kGrowthDelta (EnsureCapacityFor adds in kGrowthDelta so + // subtract it before calling) + EnsureCapacityFor(4*kGrowthDelta - kGrowthDelta); +} -/**------------------------------------------------------- - * Default constructor - * - * @update gess 3/31/98 - * @param - * @return - *------------------------------------------------------*/ -nsString::nsString(const char* anISOLatin1/*=""*/) { +nsString::nsString(const char* anISOLatin1) { mLength=mCapacity=0; mStr=0; PRInt32 len=strlen(anISOLatin1); EnsureCapacityFor(len); this->SetString(anISOLatin1,len); - if(++mInstanceCount==1) - SelfTest(); } /*------------------------------------------------------- @@ -67,8 +69,6 @@ nsString::nsString(const nsString &aString) { mStr=0; EnsureCapacityFor(aString.mLength); this->SetString(aString.mStr,aString.mLength); - if(++mInstanceCount==1) - SelfTest(); } /*------------------------------------------------------- @@ -83,8 +83,6 @@ nsString::nsString(const PRUnichar* aUnicodeStr){ PRInt32 len=(aUnicodeStr) ? nsCRT::strlen(aUnicodeStr) : 0; EnsureCapacityFor(len); this->SetString(aUnicodeStr,len); - if(++mInstanceCount==1) - SelfTest(); } /*------------------------------------------------------- @@ -103,8 +101,6 @@ nsString::nsString(PRBool aSubclassBuffer) EnsureCapacityFor(1); this->SetString(""); } - if(++mInstanceCount==1) - SelfTest(); } /*------------------------------------------------------- @@ -409,7 +405,8 @@ void nsString::ToUpperCase() *------------------------------------------------------*/ void nsString::ToLowerCase(nsString& aOut) const { - aOut.SetLength(mLength); + aOut.EnsureCapacityFor(mLength); + aOut.mLength = mLength; chartype* to = aOut.mStr; chartype* from = mStr; chartype* end = from + mLength; @@ -431,7 +428,8 @@ void nsString::ToLowerCase(nsString& aOut) const *------------------------------------------------------*/ void nsString::ToUpperCase(nsString& aOut) const { - aOut.SetLength(mLength); + aOut.EnsureCapacityFor(mLength); + aOut.mLength = mLength; chartype* to = aOut.mStr; chartype* from = mStr; chartype* end = from + mLength; @@ -494,7 +492,7 @@ PRUnichar* nsString::ToNewUnicode() const *------------------------------------------------------*/ void nsString::ToString(nsString& aString) const { - aString.SetLength(0); + aString.mLength = 0; aString.Append(mStr, mLength); } diff --git a/mozilla/xpcom/ds/nsString.h b/mozilla/xpcom/ds/nsString.h index 7b924473907..075b014e1a8 100644 --- a/mozilla/xpcom/ds/nsString.h +++ b/mozilla/xpcom/ds/nsString.h @@ -40,11 +40,13 @@ class NS_BASE nsString { public: - nsString(const char* anISOLatin1=""); + nsString(); + nsString(const char* anISOLatin1); nsString(const nsString&); nsString(const PRUnichar* aUnicode); protected: - nsString(PRBool aSubclassBuffer); // special subclas constructor + // special subclass constructor + nsString(PRBool aSubclassBuffer); public: virtual ~nsString(); @@ -59,12 +61,6 @@ class NS_BASE nsString { PRUnichar* GetUnicode(void) const; operator PRUnichar*() const; -#if 0 - // This is NOT allowed because it has to do a malloc to - // create the iso-latin-1 version of the unicode string - operator char*() const; -#endif - PRUnichar* operator()() const; PRUnichar operator()(PRInt32 i) const; PRUnichar& operator[](PRInt32 i) const; @@ -199,7 +195,6 @@ typedef PRUnichar chartype; chartype* mStr; PRInt32 mLength; PRInt32 mCapacity; - static PRInt32 mInstanceCount; }; extern NS_BASE int fputs(const nsString& aString, FILE* out); diff --git a/mozilla/xpcom/string/obsolete/nsString.cpp b/mozilla/xpcom/string/obsolete/nsString.cpp index e7027e6c183..848a91a58c7 100644 --- a/mozilla/xpcom/string/obsolete/nsString.cpp +++ b/mozilla/xpcom/string/obsolete/nsString.cpp @@ -37,23 +37,25 @@ const char* kNullPointerError = "Error: unexpected null ptr"; //********************************************** -PRInt32 nsString::mInstanceCount=0; +/** + * 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. + */ +nsString::nsString() { + mLength = mCapacity = 0; + mStr = 0; + // Size to 4*kGrowthDelta (EnsureCapacityFor adds in kGrowthDelta so + // subtract it before calling) + EnsureCapacityFor(4*kGrowthDelta - kGrowthDelta); +} -/**------------------------------------------------------- - * Default constructor - * - * @update gess 3/31/98 - * @param - * @return - *------------------------------------------------------*/ -nsString::nsString(const char* anISOLatin1/*=""*/) { +nsString::nsString(const char* anISOLatin1) { mLength=mCapacity=0; mStr=0; PRInt32 len=strlen(anISOLatin1); EnsureCapacityFor(len); this->SetString(anISOLatin1,len); - if(++mInstanceCount==1) - SelfTest(); } /*------------------------------------------------------- @@ -67,8 +69,6 @@ nsString::nsString(const nsString &aString) { mStr=0; EnsureCapacityFor(aString.mLength); this->SetString(aString.mStr,aString.mLength); - if(++mInstanceCount==1) - SelfTest(); } /*------------------------------------------------------- @@ -83,8 +83,6 @@ nsString::nsString(const PRUnichar* aUnicodeStr){ PRInt32 len=(aUnicodeStr) ? nsCRT::strlen(aUnicodeStr) : 0; EnsureCapacityFor(len); this->SetString(aUnicodeStr,len); - if(++mInstanceCount==1) - SelfTest(); } /*------------------------------------------------------- @@ -103,8 +101,6 @@ nsString::nsString(PRBool aSubclassBuffer) EnsureCapacityFor(1); this->SetString(""); } - if(++mInstanceCount==1) - SelfTest(); } /*------------------------------------------------------- @@ -409,7 +405,8 @@ void nsString::ToUpperCase() *------------------------------------------------------*/ void nsString::ToLowerCase(nsString& aOut) const { - aOut.SetLength(mLength); + aOut.EnsureCapacityFor(mLength); + aOut.mLength = mLength; chartype* to = aOut.mStr; chartype* from = mStr; chartype* end = from + mLength; @@ -431,7 +428,8 @@ void nsString::ToLowerCase(nsString& aOut) const *------------------------------------------------------*/ void nsString::ToUpperCase(nsString& aOut) const { - aOut.SetLength(mLength); + aOut.EnsureCapacityFor(mLength); + aOut.mLength = mLength; chartype* to = aOut.mStr; chartype* from = mStr; chartype* end = from + mLength; @@ -494,7 +492,7 @@ PRUnichar* nsString::ToNewUnicode() const *------------------------------------------------------*/ void nsString::ToString(nsString& aString) const { - aString.SetLength(0); + aString.mLength = 0; aString.Append(mStr, mLength); } diff --git a/mozilla/xpcom/string/obsolete/nsString.h b/mozilla/xpcom/string/obsolete/nsString.h index 7b924473907..075b014e1a8 100644 --- a/mozilla/xpcom/string/obsolete/nsString.h +++ b/mozilla/xpcom/string/obsolete/nsString.h @@ -40,11 +40,13 @@ class NS_BASE nsString { public: - nsString(const char* anISOLatin1=""); + nsString(); + nsString(const char* anISOLatin1); nsString(const nsString&); nsString(const PRUnichar* aUnicode); protected: - nsString(PRBool aSubclassBuffer); // special subclas constructor + // special subclass constructor + nsString(PRBool aSubclassBuffer); public: virtual ~nsString(); @@ -59,12 +61,6 @@ class NS_BASE nsString { PRUnichar* GetUnicode(void) const; operator PRUnichar*() const; -#if 0 - // This is NOT allowed because it has to do a malloc to - // create the iso-latin-1 version of the unicode string - operator char*() const; -#endif - PRUnichar* operator()() const; PRUnichar operator()(PRInt32 i) const; PRUnichar& operator[](PRInt32 i) const; @@ -199,7 +195,6 @@ typedef PRUnichar chartype; chartype* mStr; PRInt32 mLength; PRInt32 mCapacity; - static PRInt32 mInstanceCount; }; extern NS_BASE int fputs(const nsString& aString, FILE* out);