From ccf746783bb821fb918f615a084bbc2a953b1dc4 Mon Sep 17 00:00:00 2001 From: "darin%netscape.com" Date: Wed, 2 Apr 2003 06:24:47 +0000 Subject: [PATCH] fixes bug 199221 "provide inline implementations of common string methods" r=dbaron sr=jag git-svn-id: svn://10.0.0.236/trunk@140568 18797224-902f-48f8-a5cc-f745e15eee43 --- mozilla/string/obsolete/nsString.h | 2 ++ mozilla/string/obsolete/nsString2.cpp | 13 ------------- mozilla/string/obsolete/nsString2.h | 4 +++- mozilla/string/public/nsDependentString.h | 10 ++++++++++ mozilla/xpcom/string/obsolete/nsString.h | 2 ++ mozilla/xpcom/string/obsolete/nsString2.cpp | 13 ------------- mozilla/xpcom/string/obsolete/nsString2.h | 4 +++- mozilla/xpcom/string/public/nsDependentString.h | 10 ++++++++++ 8 files changed, 30 insertions(+), 28 deletions(-) diff --git a/mozilla/string/obsolete/nsString.h b/mozilla/string/obsolete/nsString.h index aaed3069216..5ce0fe71a1e 100644 --- a/mozilla/string/obsolete/nsString.h +++ b/mozilla/string/obsolete/nsString.h @@ -71,6 +71,8 @@ protected: public: virtual const char* get() const { return mStr; } + PRBool IsEmpty() const { return mLength == 0; } + public: /** * Default constructor. diff --git a/mozilla/string/obsolete/nsString2.cpp b/mozilla/string/obsolete/nsString2.cpp index c3d92a8dd9b..5b03921b8a9 100644 --- a/mozilla/string/obsolete/nsString2.cpp +++ b/mozilla/string/obsolete/nsString2.cpp @@ -197,19 +197,6 @@ nsString::SetCapacity( PRUint32 aNewCapacity ) *********************************************************************/ -/** - * This method returns the internal unicode buffer. - * Now that we've factored the string class, this should never - * be able to return a 1 byte string. - * - * @update gess1/4/99 - * @return ptr to internal (2-byte) buffer; - */ -const PRUnichar* nsString::get() const { - const PRUnichar* result=(eOneByte==GetCharSize()) ? 0 : mUStr; - return result; -} - /** * set a char inside this string at given index * @param aChar is the char you want to write into this string diff --git a/mozilla/string/obsolete/nsString2.h b/mozilla/string/obsolete/nsString2.h index 950b0fcf43c..1750d7ab0f9 100644 --- a/mozilla/string/obsolete/nsString2.h +++ b/mozilla/string/obsolete/nsString2.h @@ -111,7 +111,9 @@ protected: virtual PRUnichar* GetWritableFragment( nsWritableFragment&, nsFragmentRequest, PRUint32 ); public: - virtual const PRUnichar* get() const; + virtual const PRUnichar* get() const { return mUStr; } + + PRBool IsEmpty() const { return mLength == 0; } public: /** diff --git a/mozilla/string/public/nsDependentString.h b/mozilla/string/public/nsDependentString.h index f0577db7334..b777351041a 100644 --- a/mozilla/string/public/nsDependentString.h +++ b/mozilla/string/public/nsDependentString.h @@ -102,6 +102,11 @@ class NS_COM nsDependentString // nsDependentString( const self_type& ); // auto-generated copy-constructor OK // ~nsDependentString(); // auto-generated destructor OK + // optimize these when possible + virtual const char_type* get() const { return mHandle.DataStart(); } + virtual PRUint32 Length() const { return mHandle.DataLength(); } + PRBool IsEmpty() const { return mHandle.DataLength() == 0; } + private: // NOT TO BE IMPLEMENTED void operator=( const self_type& ); // we're immutable, so no copy-assignment operator @@ -176,6 +181,11 @@ class NS_COM nsDependentCString // nsDependentCString( const self_type& ); // auto-generated copy-constructor OK // ~nsDependentCString(); // auto-generated destructor OK + // optimize these when possible + virtual const char_type* get() const { return mHandle.DataStart(); } + virtual PRUint32 Length() const { return mHandle.DataLength(); } + PRBool IsEmpty() const { return mHandle.DataLength() == 0; } + private: // NOT TO BE IMPLEMENTED void operator=( const self_type& ); // we're immutable, so no copy-assignment operator diff --git a/mozilla/xpcom/string/obsolete/nsString.h b/mozilla/xpcom/string/obsolete/nsString.h index aaed3069216..5ce0fe71a1e 100644 --- a/mozilla/xpcom/string/obsolete/nsString.h +++ b/mozilla/xpcom/string/obsolete/nsString.h @@ -71,6 +71,8 @@ protected: public: virtual const char* get() const { return mStr; } + PRBool IsEmpty() const { return mLength == 0; } + public: /** * Default constructor. diff --git a/mozilla/xpcom/string/obsolete/nsString2.cpp b/mozilla/xpcom/string/obsolete/nsString2.cpp index c3d92a8dd9b..5b03921b8a9 100644 --- a/mozilla/xpcom/string/obsolete/nsString2.cpp +++ b/mozilla/xpcom/string/obsolete/nsString2.cpp @@ -197,19 +197,6 @@ nsString::SetCapacity( PRUint32 aNewCapacity ) *********************************************************************/ -/** - * This method returns the internal unicode buffer. - * Now that we've factored the string class, this should never - * be able to return a 1 byte string. - * - * @update gess1/4/99 - * @return ptr to internal (2-byte) buffer; - */ -const PRUnichar* nsString::get() const { - const PRUnichar* result=(eOneByte==GetCharSize()) ? 0 : mUStr; - return result; -} - /** * set a char inside this string at given index * @param aChar is the char you want to write into this string diff --git a/mozilla/xpcom/string/obsolete/nsString2.h b/mozilla/xpcom/string/obsolete/nsString2.h index 950b0fcf43c..1750d7ab0f9 100644 --- a/mozilla/xpcom/string/obsolete/nsString2.h +++ b/mozilla/xpcom/string/obsolete/nsString2.h @@ -111,7 +111,9 @@ protected: virtual PRUnichar* GetWritableFragment( nsWritableFragment&, nsFragmentRequest, PRUint32 ); public: - virtual const PRUnichar* get() const; + virtual const PRUnichar* get() const { return mUStr; } + + PRBool IsEmpty() const { return mLength == 0; } public: /** diff --git a/mozilla/xpcom/string/public/nsDependentString.h b/mozilla/xpcom/string/public/nsDependentString.h index f0577db7334..b777351041a 100644 --- a/mozilla/xpcom/string/public/nsDependentString.h +++ b/mozilla/xpcom/string/public/nsDependentString.h @@ -102,6 +102,11 @@ class NS_COM nsDependentString // nsDependentString( const self_type& ); // auto-generated copy-constructor OK // ~nsDependentString(); // auto-generated destructor OK + // optimize these when possible + virtual const char_type* get() const { return mHandle.DataStart(); } + virtual PRUint32 Length() const { return mHandle.DataLength(); } + PRBool IsEmpty() const { return mHandle.DataLength() == 0; } + private: // NOT TO BE IMPLEMENTED void operator=( const self_type& ); // we're immutable, so no copy-assignment operator @@ -176,6 +181,11 @@ class NS_COM nsDependentCString // nsDependentCString( const self_type& ); // auto-generated copy-constructor OK // ~nsDependentCString(); // auto-generated destructor OK + // optimize these when possible + virtual const char_type* get() const { return mHandle.DataStart(); } + virtual PRUint32 Length() const { return mHandle.DataLength(); } + PRBool IsEmpty() const { return mHandle.DataLength() == 0; } + private: // NOT TO BE IMPLEMENTED void operator=( const self_type& ); // we're immutable, so no copy-assignment operator