From d7c8a2d045b48f8dad3dbc537f63fa75c91cf6fe Mon Sep 17 00:00:00 2001 From: "jaggernaut%netscape.com" Date: Wed, 15 May 2002 03:28:44 +0000 Subject: [PATCH] Bug 139649: Fix string code to use IsDependentOn instead of depending on nsAPromiseString type. r=scc, sr=darin git-svn-id: svn://10.0.0.236/trunk@121513 18797224-902f-48f8-a5cc-f745e15eee43 --- mozilla/string/public/MANIFEST | 1 - mozilla/string/public/Makefile.in | 1 - mozilla/string/public/makefile.win | 1 - mozilla/string/public/nsAPromiseString.h | 38 --- mozilla/string/public/nsAString.h | 107 ++------- .../string/public/nsDependentConcatenation.h | 6 +- mozilla/string/public/nsDependentSubstring.h | 6 +- mozilla/string/public/nsPromiseFlatString.h | 6 +- mozilla/string/public/nsSlidingString.h | 4 +- mozilla/string/public/nsStringFwd.h | 8 - mozilla/string/public/nsStringTraits.h | 3 - mozilla/string/src/nsAString.cpp | 226 +++++++++--------- .../string/src/nsDependentConcatenation.cpp | 12 - mozilla/string/src/nsPromiseFlatString.cpp | 12 - mozilla/xpcom/string/public/MANIFEST | 1 - mozilla/xpcom/string/public/Makefile.in | 1 - mozilla/xpcom/string/public/makefile.win | 1 - .../xpcom/string/public/nsAPromiseString.h | 38 --- mozilla/xpcom/string/public/nsAString.h | 107 ++------- .../string/public/nsDependentConcatenation.h | 6 +- .../string/public/nsDependentSubstring.h | 6 +- .../xpcom/string/public/nsPromiseFlatString.h | 6 +- mozilla/xpcom/string/public/nsSlidingString.h | 4 +- mozilla/xpcom/string/public/nsStringFwd.h | 8 - mozilla/xpcom/string/public/nsStringTraits.h | 3 - mozilla/xpcom/string/src/nsAString.cpp | 226 +++++++++--------- .../string/src/nsDependentConcatenation.cpp | 12 - .../xpcom/string/src/nsPromiseFlatString.cpp | 12 - 28 files changed, 276 insertions(+), 586 deletions(-) delete mode 100644 mozilla/string/public/nsAPromiseString.h delete mode 100644 mozilla/xpcom/string/public/nsAPromiseString.h diff --git a/mozilla/string/public/MANIFEST b/mozilla/string/public/MANIFEST index 56e022df06b..8bb8db520cc 100644 --- a/mozilla/string/public/MANIFEST +++ b/mozilla/string/public/MANIFEST @@ -23,7 +23,6 @@ nsAFlatString.h nsAlgorithm.h -nsAPromiseString.h nsASingleFragmentString.h nsAString.h nsAStringGenerator.h diff --git a/mozilla/string/public/Makefile.in b/mozilla/string/public/Makefile.in index c39effea38d..aecb05922ae 100644 --- a/mozilla/string/public/Makefile.in +++ b/mozilla/string/public/Makefile.in @@ -33,7 +33,6 @@ MODULE = string EXPORTS = \ nsAFlatString.h \ nsAlgorithm.h \ - nsAPromiseString.h \ nsASingleFragmentString.h \ nsAString.h \ nsAStringGenerator.h \ diff --git a/mozilla/string/public/makefile.win b/mozilla/string/public/makefile.win index 52b4a2f979a..6d85e27c2df 100644 --- a/mozilla/string/public/makefile.win +++ b/mozilla/string/public/makefile.win @@ -29,7 +29,6 @@ MODULE=string EXPORTS = \ nsAFlatString.h \ nsAlgorithm.h \ - nsAPromiseString.h \ nsASingleFragmentString.h \ nsAString.h \ nsAStringGenerator.h \ diff --git a/mozilla/string/public/nsAPromiseString.h b/mozilla/string/public/nsAPromiseString.h deleted file mode 100644 index 70bb5187785..00000000000 --- a/mozilla/string/public/nsAPromiseString.h +++ /dev/null @@ -1,38 +0,0 @@ -/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ -/* - * The contents of this file are subject to the Mozilla Public - * License Version 1.1 (the "License"); you may not use this file - * except in compliance with the License. You may obtain a copy of - * the License at http://www.mozilla.org/MPL/ - * - * Software distributed under the License is distributed on an "AS - * IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or - * implied. See the License for the specific language governing - * rights and limitations under the License. - * - * The Original Code is Mozilla. - * - * The Initial Developer of the Original Code is Netscape - * Communications. Portions created by Netscape Communications are - * Copyright (C) 2001 by Netscape Communications. All - * Rights Reserved. - * - * Contributor(s): - * Scott Collins (original author) - */ - -/* nsAPromiseString.h --- abstract base class for strings don't actually own their own characters, but proxy data from other strings */ - -#ifndef nsAPromiseString_h___ -#define nsAPromiseString_h___ - - /** - * Don't |#include| this file yourself. You will get it automatically if you need it. - * - * Why is it a separate file? To make it easier to find the classes in your local tree. - */ - -class NS_COM nsAPromiseString : public nsAString { }; -class NS_COM nsAPromiseCString : public nsACString { }; - -#endif /* !defined(nsAPromiseString_h___) */ diff --git a/mozilla/string/public/nsAString.h b/mozilla/string/public/nsAString.h index d5d46816f8d..c5168b04b50 100644 --- a/mozilla/string/public/nsAString.h +++ b/mozilla/string/public/nsAString.h @@ -105,8 +105,6 @@ class NS_COM nsAString typedef nsReadingIterator const_iterator; typedef nsWritingIterator iterator; - typedef nsAPromiseString promise_type; - typedef PRUint32 size_type; typedef PRUint32 index_type; @@ -240,8 +238,7 @@ class NS_COM nsAString * the buffer into their own buffer. */ - void Assign( const self_type& aReadable ) { AssignFromReadable(aReadable); } - inline void Assign( const promise_type& aReadable ); + void Assign( const self_type& aReadable ) { do_AssignFromReadable(aReadable); } void Assign( const char_type* aPtr ) { aPtr ? do_AssignFromElementPtr(aPtr) : SetLength(0); } void Assign( const char_type* aPtr, size_type aLength ) { do_AssignFromElementPtrLength(aPtr, aLength); } void Assign( char_type aChar ) { do_AssignFromElement(aChar); } @@ -249,7 +246,6 @@ class NS_COM nsAString // copy-assignment operator. I must define my own if I don't want the compiler to make me one self_type& operator=( const self_type& aReadable ) { Assign(aReadable); return *this; } - self_type& operator=( const promise_type& aReadable ) { Assign(aReadable); return *this; } self_type& operator=( const char_type* aPtr ) { Assign(aPtr); return *this; } self_type& operator=( char_type aChar ) { Assign(aChar); return *this; } @@ -259,14 +255,12 @@ class NS_COM nsAString // |Append()|, |operator+=()| // - void Append( const self_type& aReadable ) { AppendFromReadable(aReadable); } - inline void Append( const promise_type& aReadable ); + void Append( const self_type& aReadable ) { do_AppendFromReadable(aReadable); } void Append( const char_type* aPtr ) { if (aPtr) do_AppendFromElementPtr(aPtr); } void Append( const char_type* aPtr, size_type aLength ) { do_AppendFromElementPtrLength(aPtr, aLength); } void Append( char_type aChar ) { do_AppendFromElement(aChar); } self_type& operator+=( const self_type& aReadable ) { Append(aReadable); return *this; } - self_type& operator+=( const promise_type& aReadable ) { Append(aReadable); return *this; } self_type& operator+=( const char_type* aPtr ) { Append(aPtr); return *this; } self_type& operator+=( char_type aChar ) { Append(aChar); return *this; } @@ -281,8 +275,7 @@ class NS_COM nsAString // Note: I would really like to move the |atPosition| parameter to the front of the argument list // - void Insert( const self_type& aReadable, index_type atPosition ) { InsertFromReadable(aReadable, atPosition); } - inline void Insert( const promise_type& aReadable, index_type atPosition ); + void Insert( const self_type& aReadable, index_type atPosition ) { do_InsertFromReadable(aReadable, atPosition); } void Insert( const char_type* aPtr, index_type atPosition ) { if (aPtr) do_InsertFromElementPtr(aPtr, atPosition); } void Insert( const char_type* aPtr, index_type atPosition, size_type aLength ) { do_InsertFromElementPtrLength(aPtr, atPosition, aLength); } void Insert( char_type aChar, index_type atPosition ) { do_InsertFromElement(aChar, atPosition); } @@ -293,8 +286,7 @@ class NS_COM nsAString - void Replace( index_type cutStart, size_type cutLength, const self_type& aReadable ) { ReplaceFromReadable(cutStart, cutLength, aReadable); } -// void Replace( index_type cutStart, size_type cutLength, const promise_type& aReadable ) { ReplaceFromPromise(cutStart, cutLength, aReadable); } + void Replace( index_type cutStart, size_type cutLength, const self_type& aReadable ) { do_ReplaceFromReadable(cutStart, cutLength, aReadable); } private: // NOT TO BE IMPLEMENTED @@ -307,29 +299,25 @@ class NS_COM nsAString protected: - void AssignFromReadable( const self_type& ); - void AssignFromPromise( const self_type& ); + void UncheckedAssignFromReadable( const self_type& ); virtual void do_AssignFromReadable( const self_type& ); virtual void do_AssignFromElementPtr( const char_type* ); virtual void do_AssignFromElementPtrLength( const char_type*, size_type ); virtual void do_AssignFromElement( char_type ); - void AppendFromReadable( const self_type& ); - void AppendFromPromise( const self_type& ); + void UncheckedAppendFromReadable( const self_type& ); virtual void do_AppendFromReadable( const self_type& ); virtual void do_AppendFromElementPtr( const char_type* ); virtual void do_AppendFromElementPtrLength( const char_type*, size_type ); virtual void do_AppendFromElement( char_type ); - void InsertFromReadable( const self_type&, index_type ); - void InsertFromPromise( const self_type&, index_type ); + void UncheckedInsertFromReadable( const self_type&, index_type ); virtual void do_InsertFromReadable( const self_type&, index_type ); virtual void do_InsertFromElementPtr( const char_type*, index_type ); virtual void do_InsertFromElementPtrLength( const char_type*, index_type, size_type ); virtual void do_InsertFromElement( char_type, index_type ); - void ReplaceFromReadable( index_type, size_type, const self_type& ); - void ReplaceFromPromise( index_type, size_type, const self_type& ); + void UncheckedReplaceFromReadable( index_type, size_type, const self_type& ); virtual void do_ReplaceFromReadable( index_type, size_type, const self_type& ); @@ -337,7 +325,8 @@ class NS_COM nsAString public: virtual const char_type* GetReadableFragment( const_fragment_type&, nsFragmentRequest, PRUint32 = 0 ) const = 0; virtual char_type* GetWritableFragment( fragment_type&, nsFragmentRequest, PRUint32 = 0 ) = 0; - virtual PRBool IsDependentOn( const self_type& aString ) const { return &aString == this; } + + PRBool IsDependentOn( const self_type& aString ) const; }; class NS_COM nsACString @@ -359,8 +348,6 @@ class NS_COM nsACString typedef nsReadingIterator const_iterator; typedef nsWritingIterator iterator; - typedef nsAPromiseCString promise_type; - typedef PRUint32 size_type; typedef PRUint32 index_type; @@ -494,8 +481,7 @@ class NS_COM nsACString * the buffer into their own buffer. */ - void Assign( const self_type& aReadable ) { AssignFromReadable(aReadable); } - inline void Assign( const promise_type& aReadable ); + void Assign( const self_type& aReadable ) { do_AssignFromReadable(aReadable); } void Assign( const char_type* aPtr ) { aPtr ? do_AssignFromElementPtr(aPtr) : SetLength(0); } void Assign( const char_type* aPtr, size_type aLength ) { do_AssignFromElementPtrLength(aPtr, aLength); } void Assign( char_type aChar ) { do_AssignFromElement(aChar); } @@ -503,7 +489,6 @@ class NS_COM nsACString // copy-assignment operator. I must define my own if I don't want the compiler to make me one self_type& operator=( const self_type& aReadable ) { Assign(aReadable); return *this; } - self_type& operator=( const promise_type& aReadable ) { Assign(aReadable); return *this; } self_type& operator=( const char_type* aPtr ) { Assign(aPtr); return *this; } self_type& operator=( char_type aChar ) { Assign(aChar); return *this; } @@ -513,14 +498,12 @@ class NS_COM nsACString // |Append()|, |operator+=()| // - void Append( const self_type& aReadable ) { AppendFromReadable(aReadable); } - inline void Append( const promise_type& aReadable ); + void Append( const self_type& aReadable ) { do_AppendFromReadable(aReadable); } void Append( const char_type* aPtr ) { if (aPtr) do_AppendFromElementPtr(aPtr); } void Append( const char_type* aPtr, size_type aLength ) { do_AppendFromElementPtrLength(aPtr, aLength); } void Append( char_type aChar ) { do_AppendFromElement(aChar); } self_type& operator+=( const self_type& aReadable ) { Append(aReadable); return *this; } - self_type& operator+=( const promise_type& aReadable ) { Append(aReadable); return *this; } self_type& operator+=( const char_type* aPtr ) { Append(aPtr); return *this; } self_type& operator+=( char_type aChar ) { Append(aChar); return *this; } @@ -535,8 +518,7 @@ class NS_COM nsACString // Note: I would really like to move the |atPosition| parameter to the front of the argument list // - void Insert( const self_type& aReadable, index_type atPosition ) { InsertFromReadable(aReadable, atPosition); } - inline void Insert( const promise_type& aReadable, index_type atPosition ); + void Insert( const self_type& aReadable, index_type atPosition ) { do_InsertFromReadable(aReadable, atPosition); } void Insert( const char_type* aPtr, index_type atPosition ) { if (aPtr) do_InsertFromElementPtr(aPtr, atPosition); } void Insert( const char_type* aPtr, index_type atPosition, size_type aLength ) { do_InsertFromElementPtrLength(aPtr, atPosition, aLength); } void Insert( char_type aChar, index_type atPosition ) { do_InsertFromElement(aChar, atPosition); } @@ -547,8 +529,7 @@ class NS_COM nsACString - void Replace( index_type cutStart, size_type cutLength, const self_type& aReadable ) { ReplaceFromReadable(cutStart, cutLength, aReadable); } -// void Replace( index_type cutStart, size_type cutLength, const promise_type& aReadable ) { ReplaceFromPromise(cutStart, cutLength, aReadable); } + void Replace( index_type cutStart, size_type cutLength, const self_type& aReadable ) { do_ReplaceFromReadable(cutStart, cutLength, aReadable); } private: // NOT TO BE IMPLEMENTED @@ -561,29 +542,25 @@ class NS_COM nsACString protected: - void AssignFromReadable( const self_type& ); - void AssignFromPromise( const self_type& ); + void UncheckedAssignFromReadable( const self_type& ); virtual void do_AssignFromReadable( const self_type& ); virtual void do_AssignFromElementPtr( const char_type* ); virtual void do_AssignFromElementPtrLength( const char_type*, size_type ); virtual void do_AssignFromElement( char_type ); - void AppendFromReadable( const self_type& ); - void AppendFromPromise( const self_type& ); + void UncheckedAppendFromReadable( const self_type& ); virtual void do_AppendFromReadable( const self_type& ); virtual void do_AppendFromElementPtr( const char_type* ); virtual void do_AppendFromElementPtrLength( const char_type*, size_type ); virtual void do_AppendFromElement( char_type ); - void InsertFromReadable( const self_type&, index_type ); - void InsertFromPromise( const self_type&, index_type ); + void UncheckedInsertFromReadable( const self_type&, index_type ); virtual void do_InsertFromReadable( const self_type&, index_type ); virtual void do_InsertFromElementPtr( const char_type*, index_type ); virtual void do_InsertFromElementPtrLength( const char_type*, index_type, size_type ); virtual void do_InsertFromElement( char_type, index_type ); - void ReplaceFromReadable( index_type, size_type, const self_type& ); - void ReplaceFromPromise( index_type, size_type, const self_type& ); + void UncheckedReplaceFromReadable( index_type, size_type, const self_type& ); virtual void do_ReplaceFromReadable( index_type, size_type, const self_type& ); @@ -591,54 +568,10 @@ class NS_COM nsACString public: virtual const char_type* GetReadableFragment( const_fragment_type&, nsFragmentRequest, PRUint32 = 0 ) const = 0; virtual char_type* GetWritableFragment( fragment_type&, nsFragmentRequest, PRUint32 = 0 ) = 0; - virtual PRBool IsDependentOn( const self_type& aString ) const { return &aString == this; } + + PRBool IsDependentOn( const abstract_string_type& aString ) const; }; -#include "nsAPromiseString.h" - -inline -void -nsAString::Assign( const nsAPromiseString& aReadable ) - { - AssignFromPromise(aReadable); - } - -inline -void -nsAString::Append( const nsAPromiseString& aReadable ) - { - AppendFromPromise(aReadable); - } - -inline -void -nsAString::Insert( const nsAPromiseString& aReadable, index_type atPosition ) - { - InsertFromPromise(aReadable, atPosition); - } - -inline -void -nsACString::Assign( const nsAPromiseCString& aReadable ) - { - AssignFromPromise(aReadable); - } - -inline -void -nsACString::Append( const nsAPromiseCString& aReadable ) - { - AppendFromPromise(aReadable); - } - -inline -void -nsACString::Insert( const nsAPromiseCString& aReadable, index_type atPosition ) - { - InsertFromPromise(aReadable, atPosition); - } - - /** * Note: measure -- should the |Begin...| and |End...| be |inline|? */ diff --git a/mozilla/string/public/nsDependentConcatenation.h b/mozilla/string/public/nsDependentConcatenation.h index 090a7b634db..2a4b6de4f4a 100644 --- a/mozilla/string/public/nsDependentConcatenation.h +++ b/mozilla/string/public/nsDependentConcatenation.h @@ -48,7 +48,7 @@ */ class NS_COM nsDependentConcatenation - : public nsAPromiseString + : public nsAString { public: typedef nsDependentConcatenation self_type; @@ -104,7 +104,6 @@ class NS_COM nsDependentConcatenation public: virtual PRUint32 Length() const; - virtual PRBool IsDependentOn( const abstract_string_type& ) const; // virtual PRBool PromisesExactly( const abstract_string_type& ) const; // const self_type operator+( const abstract_string_type& rhs ) const; @@ -122,7 +121,7 @@ class NS_COM nsDependentConcatenation }; class NS_COM nsDependentCConcatenation - : public nsAPromiseCString + : public nsACString { public: typedef nsDependentCConcatenation self_type; @@ -178,7 +177,6 @@ class NS_COM nsDependentCConcatenation public: virtual PRUint32 Length() const; - virtual PRBool IsDependentOn( const abstract_string_type& ) const; // virtual PRBool PromisesExactly( const abstract_string_type& ) const; // const self_type operator+( const abstract_string_type& rhs ) const; diff --git a/mozilla/string/public/nsDependentSubstring.h b/mozilla/string/public/nsDependentSubstring.h index 1f517d75a16..98463e68ab9 100644 --- a/mozilla/string/public/nsDependentSubstring.h +++ b/mozilla/string/public/nsDependentSubstring.h @@ -43,7 +43,7 @@ // class NS_COM nsDependentSubstring - : public nsAPromiseString + : public nsAString /* NOT FOR USE BY HUMANS (mostly) @@ -87,7 +87,6 @@ class NS_COM nsDependentSubstring public: virtual PRUint32 Length() const; - virtual PRBool IsDependentOn( const abstract_string_type& aString ) const { return mString.IsDependentOn(aString); } private: const abstract_string_type& mString; @@ -96,7 +95,7 @@ class NS_COM nsDependentSubstring }; class NS_COM nsDependentCSubstring - : public nsAPromiseCString + : public nsACString /* NOT FOR USE BY HUMANS (mostly) @@ -140,7 +139,6 @@ class NS_COM nsDependentCSubstring public: virtual PRUint32 Length() const; - virtual PRBool IsDependentOn( const abstract_string_type& aString ) const { return mString.IsDependentOn(aString); } private: const abstract_string_type& mString; diff --git a/mozilla/string/public/nsPromiseFlatString.h b/mozilla/string/public/nsPromiseFlatString.h index 3c63bc20112..23ca8b8daaf 100644 --- a/mozilla/string/public/nsPromiseFlatString.h +++ b/mozilla/string/public/nsPromiseFlatString.h @@ -81,7 +81,7 @@ */ class NS_COM nsPromiseFlatString - : public nsAFlatString /* , public nsAPromiseString */ + : public nsAFlatString { friend const nsPromiseFlatString PromiseFlatString( const abstract_string_type& ); @@ -99,7 +99,6 @@ class NS_COM nsPromiseFlatString virtual const buffer_handle_type* GetFlatBufferHandle() const; virtual const buffer_handle_type* GetBufferHandle() const; virtual const shared_buffer_handle_type* GetSharedBufferHandle() const; - virtual PRBool IsDependentOn( const abstract_string_type& ) const; // things we are forwarding now, but won't when we finally fix obsolete/nsString et al @@ -120,7 +119,7 @@ class NS_COM nsPromiseFlatString }; class NS_COM nsPromiseFlatCString - : public nsAFlatCString /* , public nsAPromiseCString */ + : public nsAFlatCString { friend const nsPromiseFlatCString PromiseFlatCString( const abstract_string_type& ); @@ -138,7 +137,6 @@ class NS_COM nsPromiseFlatCString virtual const buffer_handle_type* GetFlatBufferHandle() const; virtual const buffer_handle_type* GetBufferHandle() const; virtual const shared_buffer_handle_type* GetSharedBufferHandle() const; - virtual PRBool IsDependentOn( const abstract_string_type& ) const; // things we are forwarding now, but won't when we finally fix obsolete/nsString et al diff --git a/mozilla/string/public/nsSlidingString.h b/mozilla/string/public/nsSlidingString.h index 0f7a34248a6..547daf59f15 100755 --- a/mozilla/string/public/nsSlidingString.h +++ b/mozilla/string/public/nsSlidingString.h @@ -84,7 +84,7 @@ class nsSlidingString; * a substring over a buffer list, this */ class NS_COM nsSlidingSubstring - : virtual public nsAPromiseString + : virtual public nsAString { friend class nsSlidingString; @@ -170,7 +170,7 @@ class NS_COM nsSlidingSubstring * */ class NS_COM nsSlidingString - : virtual public nsAPromiseString, + : virtual public nsAString, private nsSlidingSubstring { friend class nsSlidingSubstring; diff --git a/mozilla/string/public/nsStringFwd.h b/mozilla/string/public/nsStringFwd.h index 4f68b5febb5..89c99b61bf8 100644 --- a/mozilla/string/public/nsStringFwd.h +++ b/mozilla/string/public/nsStringFwd.h @@ -39,14 +39,6 @@ class nsAString; class nsACString; - /** - * @see nsAPromiseString.h - */ - -class nsAPromiseString; -class nsAPromiseCString; - - /** * @see nsAFlatString.h */ diff --git a/mozilla/string/public/nsStringTraits.h b/mozilla/string/public/nsStringTraits.h index fd7b2829e53..94e1ba968c5 100644 --- a/mozilla/string/public/nsStringTraits.h +++ b/mozilla/string/public/nsStringTraits.h @@ -45,7 +45,6 @@ template struct nsStringTraits { typedef nsAString abstract_string_type; - typedef nsAPromiseString abstract_promise_type; typedef nsAFlatString abstract_flat_type; typedef const nsDependentString literal_string_type; }; @@ -57,7 +56,6 @@ NS_SPECIALIZE_TEMPLATE struct nsStringTraits { typedef nsAString abstract_string_type; - typedef nsAPromiseString abstract_promise_type; typedef nsAFlatString abstract_flat_type; typedef const nsDependentString literal_string_type; }; @@ -67,7 +65,6 @@ NS_SPECIALIZE_TEMPLATE struct nsStringTraits { typedef nsACString abstract_string_type; - typedef nsAPromiseCString abstract_promise_type; typedef nsAFlatCString abstract_flat_type; typedef const nsDependentCString literal_string_type; }; diff --git a/mozilla/string/src/nsAString.cpp b/mozilla/string/src/nsAString.cpp index a059afdfe21..0d56b9f2443 100644 --- a/mozilla/string/src/nsAString.cpp +++ b/mozilla/string/src/nsAString.cpp @@ -205,23 +205,42 @@ nsAString::FindChar( char_type aChar, PRUint32 aOffset ) const return -1; } +PRBool +nsAString::IsDependentOn( const self_type& aString ) const + { + const_fragment_type f1; + const char_type* s1 = GetReadableFragment(f1, kFirstFragment); + while ( s1 ) + { + const_fragment_type f2; + const char_type* s2 = aString.GetReadableFragment(f2, kFirstFragment); + while ( s2 ) + { + // if it _isn't_ the case that + // one fragment starts after the other ends, + // or ends before the other starts, + // then, they conflict: + // !(f2.mStart>=f1.mEnd || f2.mEnd<=f1.mStart) + // + // Simplified, that gives us: + if ( f2.mStart < f1.mEnd && f2.mEnd > f1.mStart ) + return PR_TRUE; + + s2 = aString.GetReadableFragment(f2, kNextFragment); + } + s1 = GetReadableFragment(f1, kNextFragment); + } + return PR_FALSE; + } // // |Assign()| // void -nsAString::AssignFromReadable( const self_type& rhs ) - { - if ( this != &rhs ) - do_AssignFromReadable(rhs); - // else, self-assign is a no-op - } - -void -nsAString::AssignFromPromise( const self_type& aReadable ) +nsAString::do_AssignFromReadable( const self_type& aReadable ) /* - ...this function is only called when a promise that somehow references |this| is assigned _into_ |this|. + ...we need to check whether the string that's being assigned into |this| somehow references |this|. E.g., ... writable& w ... @@ -241,8 +260,12 @@ nsAString::AssignFromPromise( const self_type& aReadable ) option to fix either the callers or this mechanism. */ { + // self-assign is a no-op + if ( this == &aReadable) + return; + if ( !aReadable.IsDependentOn(*this) ) - do_AssignFromReadable(aReadable); + UncheckedAssignFromReadable(aReadable); else { size_type length = aReadable.Length(); @@ -262,7 +285,7 @@ nsAString::AssignFromPromise( const self_type& aReadable ) } void -nsAString::do_AssignFromReadable( const self_type& aReadable ) +nsAString::UncheckedAssignFromReadable( const self_type& aReadable ) { SetLength(0); if ( !aReadable.IsEmpty() ) @@ -280,19 +303,19 @@ nsAString::do_AssignFromReadable( const self_type& aReadable ) void nsAString::do_AssignFromElementPtr( const char_type* aPtr ) { - do_AssignFromReadable(nsDependentString(aPtr)); + UncheckedAssignFromReadable(nsDependentString(aPtr)); } void nsAString::do_AssignFromElementPtrLength( const char_type* aPtr, size_type aLength ) { - do_AssignFromReadable(Substring(aPtr, aPtr+aLength)); + UncheckedAssignFromReadable(Substring(aPtr, aPtr+aLength)); } void nsAString::do_AssignFromElement( char_type aChar ) { - do_AssignFromReadable(Substring(&aChar, &aChar+1)); + UncheckedAssignFromReadable(Substring(&aChar, &aChar+1)); } @@ -302,19 +325,10 @@ nsAString::do_AssignFromElement( char_type aChar ) // void -nsAString::AppendFromReadable( const self_type& aReadable ) - { - if ( this != &aReadable ) - do_AppendFromReadable(aReadable); - else - AppendFromPromise(aReadable); - } - -void -nsAString::AppendFromPromise( const self_type& aReadable ) +nsAString::do_AppendFromReadable( const self_type& aReadable ) { if ( !aReadable.IsDependentOn(*this) ) - do_AppendFromReadable(aReadable); + UncheckedAppendFromReadable(aReadable); else { size_type length = aReadable.Length(); @@ -332,7 +346,7 @@ nsAString::AppendFromPromise( const self_type& aReadable ) } void -nsAString::do_AppendFromReadable( const self_type& aReadable ) +nsAString::UncheckedAppendFromReadable( const self_type& aReadable) { size_type oldLength = this->Length(); SetLength(oldLength + aReadable.Length()); @@ -342,22 +356,23 @@ nsAString::do_AppendFromReadable( const self_type& aReadable ) copy_string(aReadable.BeginReading(fromBegin), aReadable.EndReading(fromEnd), BeginWriting(toBegin).advance( PRInt32(oldLength) ) ); } + void nsAString::do_AppendFromElementPtr( const char_type* aPtr ) { - do_AppendFromReadable(nsDependentString(aPtr)); + UncheckedAppendFromReadable(nsDependentString(aPtr)); } void nsAString::do_AppendFromElementPtrLength( const char_type* aPtr, size_type aLength ) { - do_AppendFromReadable(Substring(aPtr, aPtr+aLength)); + UncheckedAppendFromReadable(Substring(aPtr, aPtr+aLength)); } void nsAString::do_AppendFromElement( char_type aChar ) { - do_AppendFromReadable(Substring(&aChar, &aChar + 1)); + UncheckedAppendFromReadable(Substring(&aChar, &aChar + 1)); } @@ -367,19 +382,10 @@ nsAString::do_AppendFromElement( char_type aChar ) // void -nsAString::InsertFromReadable( const self_type& aReadable, index_type atPosition ) - { - if ( this != &aReadable ) - do_InsertFromReadable(aReadable, atPosition); - else - InsertFromPromise(aReadable, atPosition); - } - -void -nsAString::InsertFromPromise( const self_type& aReadable, index_type atPosition ) +nsAString::do_InsertFromReadable( const self_type& aReadable, index_type atPosition ) { if ( !aReadable.IsDependentOn(*this) ) - do_InsertFromReadable(aReadable, atPosition); + UncheckedInsertFromReadable(aReadable, atPosition); else { size_type length = aReadable.Length(); @@ -397,7 +403,7 @@ nsAString::InsertFromPromise( const self_type& aReadable, index_type atPosition } void -nsAString::do_InsertFromReadable( const self_type& aReadable, index_type atPosition ) +nsAString::UncheckedInsertFromReadable( const self_type& aReadable, index_type atPosition ) { size_type oldLength = this->Length(); SetLength(oldLength + aReadable.Length()); @@ -414,19 +420,19 @@ nsAString::do_InsertFromReadable( const self_type& aReadable, index_type atPosit void nsAString::do_InsertFromElementPtr( const char_type* aPtr, index_type atPosition ) { - do_InsertFromReadable(nsDependentString(aPtr), atPosition); + UncheckedInsertFromReadable(nsDependentString(aPtr), atPosition); } void nsAString::do_InsertFromElementPtrLength( const char_type* aPtr, index_type atPosition, size_type aLength ) { - do_InsertFromReadable(Substring(aPtr, aPtr+aLength), atPosition); + UncheckedInsertFromReadable(Substring(aPtr, aPtr+aLength), atPosition); } void nsAString::do_InsertFromElement( char_type aChar, index_type atPosition ) { - do_InsertFromReadable(Substring(&aChar, &aChar+1), atPosition); + UncheckedInsertFromReadable(Substring(&aChar, &aChar+1), atPosition); } @@ -456,19 +462,10 @@ nsAString::Cut( index_type cutStart, size_type cutLength ) // void -nsAString::ReplaceFromReadable( index_type cutStart, size_type cutLength, const self_type& aReplacement ) - { - if ( this != &aReplacement ) - do_ReplaceFromReadable(cutStart, cutLength, aReplacement); - else - ReplaceFromPromise(cutStart, cutLength, aReplacement); - } - -void -nsAString::ReplaceFromPromise( index_type cutStart, size_type cutLength, const self_type& aReadable ) +nsAString::do_ReplaceFromReadable( index_type cutStart, size_type cutLength, const self_type& aReadable ) { if ( !aReadable.IsDependentOn(*this) ) - do_ReplaceFromReadable(cutStart, cutLength, aReadable); + UncheckedReplaceFromReadable(cutStart, cutLength, aReadable); else { size_type length = aReadable.Length(); @@ -478,7 +475,7 @@ nsAString::ReplaceFromPromise( index_type cutStart, size_type cutLength, const s const_iterator fromBegin, fromEnd; char_type* toBegin = buffer; copy_string(aReadable.BeginReading(fromBegin), aReadable.EndReading(fromEnd), toBegin); - do_ReplaceFromReadable(cutStart, cutLength, nsDependentString(buffer, length)); + UncheckedReplaceFromReadable(cutStart, cutLength, nsDependentString(buffer, length)); delete[] buffer; } // else assert? @@ -486,7 +483,7 @@ nsAString::ReplaceFromPromise( index_type cutStart, size_type cutLength, const s } void -nsAString::do_ReplaceFromReadable( index_type cutStart, size_type cutLength, const self_type& aReplacement ) +nsAString::UncheckedReplaceFromReadable( index_type cutStart, size_type cutLength, const self_type& aReplacement ) { size_type oldLength = this->Length(); @@ -511,6 +508,7 @@ nsAString::do_ReplaceFromReadable( index_type cutStart, size_type cutLength, con } + int nsDefaultCStringComparator::operator()( const char_type* lhs, const char_type* rhs, PRUint32 aLength ) const { @@ -704,23 +702,42 @@ nsACString::FindChar( char_type aChar, PRUint32 aOffset ) const return -1; } +PRBool +nsACString::IsDependentOn( const self_type& aString ) const + { + const_fragment_type f1; + const char_type* s1 = GetReadableFragment(f1, kFirstFragment); + while ( s1 ) + { + const_fragment_type f2; + const char_type* s2 = aString.GetReadableFragment(f2, kFirstFragment); + while ( s2 ) + { + // if it _isn't_ the case that + // one fragment starts after the other ends, + // or ends before the other starts, + // then, they conflict: + // !(f2.mStart>=f1.mEnd || f2.mEnd<=f1.mStart) + // + // Simplified, that gives us: + if ( f2.mStart < f1.mEnd && f2.mEnd > f1.mStart ) + return PR_TRUE; + + s2 = aString.GetReadableFragment(f2, kNextFragment); + } + s1 = GetReadableFragment(f1, kNextFragment); + } + return PR_FALSE; + } // // |Assign()| // void -nsACString::AssignFromReadable( const self_type& rhs ) - { - if ( this != &rhs ) - do_AssignFromReadable(rhs); - // else, self-assign is a no-op - } - -void -nsACString::AssignFromPromise( const self_type& aReadable ) +nsACString::do_AssignFromReadable( const self_type& aReadable ) /* - ...this function is only called when a promise that somehow references |this| is assigned _into_ |this|. + ...we need to check whether the string that's being assigned into |this| somehow references |this|. E.g., ... writable& w ... @@ -740,8 +757,12 @@ nsACString::AssignFromPromise( const self_type& aReadable ) option to fix either the callers or this mechanism. */ { + // self-assign is a no-op + if (this == &aReadable) + return; + if ( !aReadable.IsDependentOn(*this) ) - do_AssignFromReadable(aReadable); + UncheckedAssignFromReadable(aReadable); else { size_type length = aReadable.Length(); @@ -761,7 +782,7 @@ nsACString::AssignFromPromise( const self_type& aReadable ) } void -nsACString::do_AssignFromReadable( const self_type& aReadable ) +nsACString::UncheckedAssignFromReadable( const self_type& aReadable ) { SetLength(0); if ( !aReadable.IsEmpty() ) @@ -779,19 +800,19 @@ nsACString::do_AssignFromReadable( const self_type& aReadable ) void nsACString::do_AssignFromElementPtr( const char_type* aPtr ) { - do_AssignFromReadable(nsDependentCString(aPtr)); + UncheckedAssignFromReadable(nsDependentCString(aPtr)); } void nsACString::do_AssignFromElementPtrLength( const char_type* aPtr, size_type aLength ) { - do_AssignFromReadable(Substring(aPtr, aPtr+aLength)); + UncheckedAssignFromReadable(Substring(aPtr, aPtr+aLength)); } void nsACString::do_AssignFromElement( char_type aChar ) { - do_AssignFromReadable(Substring(&aChar, &aChar+1)); + UncheckedAssignFromReadable(Substring(&aChar, &aChar+1)); } @@ -801,19 +822,10 @@ nsACString::do_AssignFromElement( char_type aChar ) // void -nsACString::AppendFromReadable( const self_type& aReadable ) - { - if ( this != &aReadable ) - do_AppendFromReadable(aReadable); - else - AppendFromPromise(aReadable); - } - -void -nsACString::AppendFromPromise( const self_type& aReadable ) +nsACString::do_AppendFromReadable( const self_type& aReadable ) { if ( !aReadable.IsDependentOn(*this) ) - do_AppendFromReadable(aReadable); + UncheckedAppendFromReadable(aReadable); else { size_type length = aReadable.Length(); @@ -831,7 +843,7 @@ nsACString::AppendFromPromise( const self_type& aReadable ) } void -nsACString::do_AppendFromReadable( const self_type& aReadable ) +nsACString::UncheckedAppendFromReadable( const self_type& aReadable ) { size_type oldLength = this->Length(); SetLength(oldLength + aReadable.Length()); @@ -844,19 +856,19 @@ nsACString::do_AppendFromReadable( const self_type& aReadable ) void nsACString::do_AppendFromElementPtr( const char_type* aPtr ) { - do_AppendFromReadable(nsDependentCString(aPtr)); + UncheckedAppendFromReadable(nsDependentCString(aPtr)); } void nsACString::do_AppendFromElementPtrLength( const char_type* aPtr, size_type aLength ) { - do_AppendFromReadable(Substring(aPtr, aPtr+aLength)); + UncheckedAppendFromReadable(Substring(aPtr, aPtr+aLength)); } void nsACString::do_AppendFromElement( char_type aChar ) { - do_AppendFromReadable(Substring(&aChar, &aChar + 1)); + UncheckedAppendFromReadable(Substring(&aChar, &aChar + 1)); } @@ -866,19 +878,10 @@ nsACString::do_AppendFromElement( char_type aChar ) // void -nsACString::InsertFromReadable( const self_type& aReadable, index_type atPosition ) - { - if ( this != &aReadable ) - do_InsertFromReadable(aReadable, atPosition); - else - InsertFromPromise(aReadable, atPosition); - } - -void -nsACString::InsertFromPromise( const self_type& aReadable, index_type atPosition ) +nsACString::do_InsertFromReadable( const self_type& aReadable, index_type atPosition ) { if ( !aReadable.IsDependentOn(*this) ) - do_InsertFromReadable(aReadable, atPosition); + UncheckedInsertFromReadable(aReadable, atPosition); else { size_type length = aReadable.Length(); @@ -896,7 +899,7 @@ nsACString::InsertFromPromise( const self_type& aReadable, index_type atPosition } void -nsACString::do_InsertFromReadable( const self_type& aReadable, index_type atPosition ) +nsACString::UncheckedInsertFromReadable( const self_type& aReadable, index_type atPosition ) { size_type oldLength = this->Length(); SetLength(oldLength + aReadable.Length()); @@ -913,19 +916,19 @@ nsACString::do_InsertFromReadable( const self_type& aReadable, index_type atPosi void nsACString::do_InsertFromElementPtr( const char_type* aPtr, index_type atPosition ) { - do_InsertFromReadable(nsDependentCString(aPtr), atPosition); + UncheckedInsertFromReadable(nsDependentCString(aPtr), atPosition); } void nsACString::do_InsertFromElementPtrLength( const char_type* aPtr, index_type atPosition, size_type aLength ) { - do_InsertFromReadable(Substring(aPtr, aPtr+aLength), atPosition); + UncheckedInsertFromReadable(Substring(aPtr, aPtr+aLength), atPosition); } void nsACString::do_InsertFromElement( char_type aChar, index_type atPosition ) { - do_InsertFromReadable(Substring(&aChar, &aChar+1), atPosition); + UncheckedInsertFromReadable(Substring(&aChar, &aChar+1), atPosition); } @@ -955,19 +958,10 @@ nsACString::Cut( index_type cutStart, size_type cutLength ) // void -nsACString::ReplaceFromReadable( index_type cutStart, size_type cutLength, const self_type& aReplacement ) - { - if ( this != &aReplacement ) - do_ReplaceFromReadable(cutStart, cutLength, aReplacement); - else - ReplaceFromPromise(cutStart, cutLength, aReplacement); - } - -void -nsACString::ReplaceFromPromise( index_type cutStart, size_type cutLength, const self_type& aReadable ) +nsACString::do_ReplaceFromReadable( index_type cutStart, size_type cutLength, const self_type& aReadable ) { if ( !aReadable.IsDependentOn(*this) ) - do_ReplaceFromReadable(cutStart, cutLength, aReadable); + UncheckedReplaceFromReadable(cutStart, cutLength, aReadable); else { size_type length = aReadable.Length(); @@ -977,7 +971,7 @@ nsACString::ReplaceFromPromise( index_type cutStart, size_type cutLength, const const_iterator fromBegin, fromEnd; char_type* toBegin = buffer; copy_string(aReadable.BeginReading(fromBegin), aReadable.EndReading(fromEnd), toBegin); - do_ReplaceFromReadable(cutStart, cutLength, nsDependentCString(buffer, length)); + UncheckedReplaceFromReadable(cutStart, cutLength, nsDependentCString(buffer, length)); delete[] buffer; } // else assert? @@ -985,7 +979,7 @@ nsACString::ReplaceFromPromise( index_type cutStart, size_type cutLength, const } void -nsACString::do_ReplaceFromReadable( index_type cutStart, size_type cutLength, const self_type& aReplacement ) +nsACString::UncheckedReplaceFromReadable( index_type cutStart, size_type cutLength, const self_type& aReplacement ) { size_type oldLength = this->Length(); diff --git a/mozilla/string/src/nsDependentConcatenation.cpp b/mozilla/string/src/nsDependentConcatenation.cpp index f9ecc3b84d2..3a9fd92dfb3 100644 --- a/mozilla/string/src/nsDependentConcatenation.cpp +++ b/mozilla/string/src/nsDependentConcatenation.cpp @@ -38,12 +38,6 @@ nsDependentConcatenation::Length() const return mStrings[kFirstString]->Length() + mStrings[kLastString]->Length(); } -PRBool -nsDependentConcatenation::IsDependentOn( const abstract_string_type& aString ) const - { - return mStrings[kFirstString]->IsDependentOn(aString) || mStrings[kLastString]->IsDependentOn(aString); - } - #if 0 PRBool nsDependentConcatenation::PromisesExactly( const abstract_string_type& aString ) const @@ -123,12 +117,6 @@ nsDependentCConcatenation::Length() const return mStrings[kFirstString]->Length() + mStrings[kLastString]->Length(); } -PRBool -nsDependentCConcatenation::IsDependentOn( const abstract_string_type& aString ) const - { - return mStrings[kFirstString]->IsDependentOn(aString) || mStrings[kLastString]->IsDependentOn(aString); - } - #if 0 PRBool nsDependentCConcatenation::PromisesExactly( const abstract_string_type& aString ) const diff --git a/mozilla/string/src/nsPromiseFlatString.cpp b/mozilla/string/src/nsPromiseFlatString.cpp index 907e5e64acb..f16395f65b2 100644 --- a/mozilla/string/src/nsPromiseFlatString.cpp +++ b/mozilla/string/src/nsPromiseFlatString.cpp @@ -62,12 +62,6 @@ nsPromiseFlatString::GetSharedBufferHandle() const return mPromisedString->GetSharedBufferHandle(); } -PRBool -nsPromiseFlatString::IsDependentOn( const abstract_string_type& aString ) const - { - return mPromisedString->IsDependentOn(aString); - } - const nsPromiseFlatString::char_type* nsPromiseFlatString::get() const { @@ -126,12 +120,6 @@ nsPromiseFlatCString::GetSharedBufferHandle() const return mPromisedString->GetSharedBufferHandle(); } -PRBool -nsPromiseFlatCString::IsDependentOn( const abstract_string_type& aString ) const - { - return mPromisedString->IsDependentOn(aString); - } - const nsPromiseFlatCString::char_type* nsPromiseFlatCString::get() const { diff --git a/mozilla/xpcom/string/public/MANIFEST b/mozilla/xpcom/string/public/MANIFEST index 56e022df06b..8bb8db520cc 100644 --- a/mozilla/xpcom/string/public/MANIFEST +++ b/mozilla/xpcom/string/public/MANIFEST @@ -23,7 +23,6 @@ nsAFlatString.h nsAlgorithm.h -nsAPromiseString.h nsASingleFragmentString.h nsAString.h nsAStringGenerator.h diff --git a/mozilla/xpcom/string/public/Makefile.in b/mozilla/xpcom/string/public/Makefile.in index c39effea38d..aecb05922ae 100644 --- a/mozilla/xpcom/string/public/Makefile.in +++ b/mozilla/xpcom/string/public/Makefile.in @@ -33,7 +33,6 @@ MODULE = string EXPORTS = \ nsAFlatString.h \ nsAlgorithm.h \ - nsAPromiseString.h \ nsASingleFragmentString.h \ nsAString.h \ nsAStringGenerator.h \ diff --git a/mozilla/xpcom/string/public/makefile.win b/mozilla/xpcom/string/public/makefile.win index 52b4a2f979a..6d85e27c2df 100644 --- a/mozilla/xpcom/string/public/makefile.win +++ b/mozilla/xpcom/string/public/makefile.win @@ -29,7 +29,6 @@ MODULE=string EXPORTS = \ nsAFlatString.h \ nsAlgorithm.h \ - nsAPromiseString.h \ nsASingleFragmentString.h \ nsAString.h \ nsAStringGenerator.h \ diff --git a/mozilla/xpcom/string/public/nsAPromiseString.h b/mozilla/xpcom/string/public/nsAPromiseString.h deleted file mode 100644 index 70bb5187785..00000000000 --- a/mozilla/xpcom/string/public/nsAPromiseString.h +++ /dev/null @@ -1,38 +0,0 @@ -/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ -/* - * The contents of this file are subject to the Mozilla Public - * License Version 1.1 (the "License"); you may not use this file - * except in compliance with the License. You may obtain a copy of - * the License at http://www.mozilla.org/MPL/ - * - * Software distributed under the License is distributed on an "AS - * IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or - * implied. See the License for the specific language governing - * rights and limitations under the License. - * - * The Original Code is Mozilla. - * - * The Initial Developer of the Original Code is Netscape - * Communications. Portions created by Netscape Communications are - * Copyright (C) 2001 by Netscape Communications. All - * Rights Reserved. - * - * Contributor(s): - * Scott Collins (original author) - */ - -/* nsAPromiseString.h --- abstract base class for strings don't actually own their own characters, but proxy data from other strings */ - -#ifndef nsAPromiseString_h___ -#define nsAPromiseString_h___ - - /** - * Don't |#include| this file yourself. You will get it automatically if you need it. - * - * Why is it a separate file? To make it easier to find the classes in your local tree. - */ - -class NS_COM nsAPromiseString : public nsAString { }; -class NS_COM nsAPromiseCString : public nsACString { }; - -#endif /* !defined(nsAPromiseString_h___) */ diff --git a/mozilla/xpcom/string/public/nsAString.h b/mozilla/xpcom/string/public/nsAString.h index d5d46816f8d..c5168b04b50 100644 --- a/mozilla/xpcom/string/public/nsAString.h +++ b/mozilla/xpcom/string/public/nsAString.h @@ -105,8 +105,6 @@ class NS_COM nsAString typedef nsReadingIterator const_iterator; typedef nsWritingIterator iterator; - typedef nsAPromiseString promise_type; - typedef PRUint32 size_type; typedef PRUint32 index_type; @@ -240,8 +238,7 @@ class NS_COM nsAString * the buffer into their own buffer. */ - void Assign( const self_type& aReadable ) { AssignFromReadable(aReadable); } - inline void Assign( const promise_type& aReadable ); + void Assign( const self_type& aReadable ) { do_AssignFromReadable(aReadable); } void Assign( const char_type* aPtr ) { aPtr ? do_AssignFromElementPtr(aPtr) : SetLength(0); } void Assign( const char_type* aPtr, size_type aLength ) { do_AssignFromElementPtrLength(aPtr, aLength); } void Assign( char_type aChar ) { do_AssignFromElement(aChar); } @@ -249,7 +246,6 @@ class NS_COM nsAString // copy-assignment operator. I must define my own if I don't want the compiler to make me one self_type& operator=( const self_type& aReadable ) { Assign(aReadable); return *this; } - self_type& operator=( const promise_type& aReadable ) { Assign(aReadable); return *this; } self_type& operator=( const char_type* aPtr ) { Assign(aPtr); return *this; } self_type& operator=( char_type aChar ) { Assign(aChar); return *this; } @@ -259,14 +255,12 @@ class NS_COM nsAString // |Append()|, |operator+=()| // - void Append( const self_type& aReadable ) { AppendFromReadable(aReadable); } - inline void Append( const promise_type& aReadable ); + void Append( const self_type& aReadable ) { do_AppendFromReadable(aReadable); } void Append( const char_type* aPtr ) { if (aPtr) do_AppendFromElementPtr(aPtr); } void Append( const char_type* aPtr, size_type aLength ) { do_AppendFromElementPtrLength(aPtr, aLength); } void Append( char_type aChar ) { do_AppendFromElement(aChar); } self_type& operator+=( const self_type& aReadable ) { Append(aReadable); return *this; } - self_type& operator+=( const promise_type& aReadable ) { Append(aReadable); return *this; } self_type& operator+=( const char_type* aPtr ) { Append(aPtr); return *this; } self_type& operator+=( char_type aChar ) { Append(aChar); return *this; } @@ -281,8 +275,7 @@ class NS_COM nsAString // Note: I would really like to move the |atPosition| parameter to the front of the argument list // - void Insert( const self_type& aReadable, index_type atPosition ) { InsertFromReadable(aReadable, atPosition); } - inline void Insert( const promise_type& aReadable, index_type atPosition ); + void Insert( const self_type& aReadable, index_type atPosition ) { do_InsertFromReadable(aReadable, atPosition); } void Insert( const char_type* aPtr, index_type atPosition ) { if (aPtr) do_InsertFromElementPtr(aPtr, atPosition); } void Insert( const char_type* aPtr, index_type atPosition, size_type aLength ) { do_InsertFromElementPtrLength(aPtr, atPosition, aLength); } void Insert( char_type aChar, index_type atPosition ) { do_InsertFromElement(aChar, atPosition); } @@ -293,8 +286,7 @@ class NS_COM nsAString - void Replace( index_type cutStart, size_type cutLength, const self_type& aReadable ) { ReplaceFromReadable(cutStart, cutLength, aReadable); } -// void Replace( index_type cutStart, size_type cutLength, const promise_type& aReadable ) { ReplaceFromPromise(cutStart, cutLength, aReadable); } + void Replace( index_type cutStart, size_type cutLength, const self_type& aReadable ) { do_ReplaceFromReadable(cutStart, cutLength, aReadable); } private: // NOT TO BE IMPLEMENTED @@ -307,29 +299,25 @@ class NS_COM nsAString protected: - void AssignFromReadable( const self_type& ); - void AssignFromPromise( const self_type& ); + void UncheckedAssignFromReadable( const self_type& ); virtual void do_AssignFromReadable( const self_type& ); virtual void do_AssignFromElementPtr( const char_type* ); virtual void do_AssignFromElementPtrLength( const char_type*, size_type ); virtual void do_AssignFromElement( char_type ); - void AppendFromReadable( const self_type& ); - void AppendFromPromise( const self_type& ); + void UncheckedAppendFromReadable( const self_type& ); virtual void do_AppendFromReadable( const self_type& ); virtual void do_AppendFromElementPtr( const char_type* ); virtual void do_AppendFromElementPtrLength( const char_type*, size_type ); virtual void do_AppendFromElement( char_type ); - void InsertFromReadable( const self_type&, index_type ); - void InsertFromPromise( const self_type&, index_type ); + void UncheckedInsertFromReadable( const self_type&, index_type ); virtual void do_InsertFromReadable( const self_type&, index_type ); virtual void do_InsertFromElementPtr( const char_type*, index_type ); virtual void do_InsertFromElementPtrLength( const char_type*, index_type, size_type ); virtual void do_InsertFromElement( char_type, index_type ); - void ReplaceFromReadable( index_type, size_type, const self_type& ); - void ReplaceFromPromise( index_type, size_type, const self_type& ); + void UncheckedReplaceFromReadable( index_type, size_type, const self_type& ); virtual void do_ReplaceFromReadable( index_type, size_type, const self_type& ); @@ -337,7 +325,8 @@ class NS_COM nsAString public: virtual const char_type* GetReadableFragment( const_fragment_type&, nsFragmentRequest, PRUint32 = 0 ) const = 0; virtual char_type* GetWritableFragment( fragment_type&, nsFragmentRequest, PRUint32 = 0 ) = 0; - virtual PRBool IsDependentOn( const self_type& aString ) const { return &aString == this; } + + PRBool IsDependentOn( const self_type& aString ) const; }; class NS_COM nsACString @@ -359,8 +348,6 @@ class NS_COM nsACString typedef nsReadingIterator const_iterator; typedef nsWritingIterator iterator; - typedef nsAPromiseCString promise_type; - typedef PRUint32 size_type; typedef PRUint32 index_type; @@ -494,8 +481,7 @@ class NS_COM nsACString * the buffer into their own buffer. */ - void Assign( const self_type& aReadable ) { AssignFromReadable(aReadable); } - inline void Assign( const promise_type& aReadable ); + void Assign( const self_type& aReadable ) { do_AssignFromReadable(aReadable); } void Assign( const char_type* aPtr ) { aPtr ? do_AssignFromElementPtr(aPtr) : SetLength(0); } void Assign( const char_type* aPtr, size_type aLength ) { do_AssignFromElementPtrLength(aPtr, aLength); } void Assign( char_type aChar ) { do_AssignFromElement(aChar); } @@ -503,7 +489,6 @@ class NS_COM nsACString // copy-assignment operator. I must define my own if I don't want the compiler to make me one self_type& operator=( const self_type& aReadable ) { Assign(aReadable); return *this; } - self_type& operator=( const promise_type& aReadable ) { Assign(aReadable); return *this; } self_type& operator=( const char_type* aPtr ) { Assign(aPtr); return *this; } self_type& operator=( char_type aChar ) { Assign(aChar); return *this; } @@ -513,14 +498,12 @@ class NS_COM nsACString // |Append()|, |operator+=()| // - void Append( const self_type& aReadable ) { AppendFromReadable(aReadable); } - inline void Append( const promise_type& aReadable ); + void Append( const self_type& aReadable ) { do_AppendFromReadable(aReadable); } void Append( const char_type* aPtr ) { if (aPtr) do_AppendFromElementPtr(aPtr); } void Append( const char_type* aPtr, size_type aLength ) { do_AppendFromElementPtrLength(aPtr, aLength); } void Append( char_type aChar ) { do_AppendFromElement(aChar); } self_type& operator+=( const self_type& aReadable ) { Append(aReadable); return *this; } - self_type& operator+=( const promise_type& aReadable ) { Append(aReadable); return *this; } self_type& operator+=( const char_type* aPtr ) { Append(aPtr); return *this; } self_type& operator+=( char_type aChar ) { Append(aChar); return *this; } @@ -535,8 +518,7 @@ class NS_COM nsACString // Note: I would really like to move the |atPosition| parameter to the front of the argument list // - void Insert( const self_type& aReadable, index_type atPosition ) { InsertFromReadable(aReadable, atPosition); } - inline void Insert( const promise_type& aReadable, index_type atPosition ); + void Insert( const self_type& aReadable, index_type atPosition ) { do_InsertFromReadable(aReadable, atPosition); } void Insert( const char_type* aPtr, index_type atPosition ) { if (aPtr) do_InsertFromElementPtr(aPtr, atPosition); } void Insert( const char_type* aPtr, index_type atPosition, size_type aLength ) { do_InsertFromElementPtrLength(aPtr, atPosition, aLength); } void Insert( char_type aChar, index_type atPosition ) { do_InsertFromElement(aChar, atPosition); } @@ -547,8 +529,7 @@ class NS_COM nsACString - void Replace( index_type cutStart, size_type cutLength, const self_type& aReadable ) { ReplaceFromReadable(cutStart, cutLength, aReadable); } -// void Replace( index_type cutStart, size_type cutLength, const promise_type& aReadable ) { ReplaceFromPromise(cutStart, cutLength, aReadable); } + void Replace( index_type cutStart, size_type cutLength, const self_type& aReadable ) { do_ReplaceFromReadable(cutStart, cutLength, aReadable); } private: // NOT TO BE IMPLEMENTED @@ -561,29 +542,25 @@ class NS_COM nsACString protected: - void AssignFromReadable( const self_type& ); - void AssignFromPromise( const self_type& ); + void UncheckedAssignFromReadable( const self_type& ); virtual void do_AssignFromReadable( const self_type& ); virtual void do_AssignFromElementPtr( const char_type* ); virtual void do_AssignFromElementPtrLength( const char_type*, size_type ); virtual void do_AssignFromElement( char_type ); - void AppendFromReadable( const self_type& ); - void AppendFromPromise( const self_type& ); + void UncheckedAppendFromReadable( const self_type& ); virtual void do_AppendFromReadable( const self_type& ); virtual void do_AppendFromElementPtr( const char_type* ); virtual void do_AppendFromElementPtrLength( const char_type*, size_type ); virtual void do_AppendFromElement( char_type ); - void InsertFromReadable( const self_type&, index_type ); - void InsertFromPromise( const self_type&, index_type ); + void UncheckedInsertFromReadable( const self_type&, index_type ); virtual void do_InsertFromReadable( const self_type&, index_type ); virtual void do_InsertFromElementPtr( const char_type*, index_type ); virtual void do_InsertFromElementPtrLength( const char_type*, index_type, size_type ); virtual void do_InsertFromElement( char_type, index_type ); - void ReplaceFromReadable( index_type, size_type, const self_type& ); - void ReplaceFromPromise( index_type, size_type, const self_type& ); + void UncheckedReplaceFromReadable( index_type, size_type, const self_type& ); virtual void do_ReplaceFromReadable( index_type, size_type, const self_type& ); @@ -591,54 +568,10 @@ class NS_COM nsACString public: virtual const char_type* GetReadableFragment( const_fragment_type&, nsFragmentRequest, PRUint32 = 0 ) const = 0; virtual char_type* GetWritableFragment( fragment_type&, nsFragmentRequest, PRUint32 = 0 ) = 0; - virtual PRBool IsDependentOn( const self_type& aString ) const { return &aString == this; } + + PRBool IsDependentOn( const abstract_string_type& aString ) const; }; -#include "nsAPromiseString.h" - -inline -void -nsAString::Assign( const nsAPromiseString& aReadable ) - { - AssignFromPromise(aReadable); - } - -inline -void -nsAString::Append( const nsAPromiseString& aReadable ) - { - AppendFromPromise(aReadable); - } - -inline -void -nsAString::Insert( const nsAPromiseString& aReadable, index_type atPosition ) - { - InsertFromPromise(aReadable, atPosition); - } - -inline -void -nsACString::Assign( const nsAPromiseCString& aReadable ) - { - AssignFromPromise(aReadable); - } - -inline -void -nsACString::Append( const nsAPromiseCString& aReadable ) - { - AppendFromPromise(aReadable); - } - -inline -void -nsACString::Insert( const nsAPromiseCString& aReadable, index_type atPosition ) - { - InsertFromPromise(aReadable, atPosition); - } - - /** * Note: measure -- should the |Begin...| and |End...| be |inline|? */ diff --git a/mozilla/xpcom/string/public/nsDependentConcatenation.h b/mozilla/xpcom/string/public/nsDependentConcatenation.h index 090a7b634db..2a4b6de4f4a 100644 --- a/mozilla/xpcom/string/public/nsDependentConcatenation.h +++ b/mozilla/xpcom/string/public/nsDependentConcatenation.h @@ -48,7 +48,7 @@ */ class NS_COM nsDependentConcatenation - : public nsAPromiseString + : public nsAString { public: typedef nsDependentConcatenation self_type; @@ -104,7 +104,6 @@ class NS_COM nsDependentConcatenation public: virtual PRUint32 Length() const; - virtual PRBool IsDependentOn( const abstract_string_type& ) const; // virtual PRBool PromisesExactly( const abstract_string_type& ) const; // const self_type operator+( const abstract_string_type& rhs ) const; @@ -122,7 +121,7 @@ class NS_COM nsDependentConcatenation }; class NS_COM nsDependentCConcatenation - : public nsAPromiseCString + : public nsACString { public: typedef nsDependentCConcatenation self_type; @@ -178,7 +177,6 @@ class NS_COM nsDependentCConcatenation public: virtual PRUint32 Length() const; - virtual PRBool IsDependentOn( const abstract_string_type& ) const; // virtual PRBool PromisesExactly( const abstract_string_type& ) const; // const self_type operator+( const abstract_string_type& rhs ) const; diff --git a/mozilla/xpcom/string/public/nsDependentSubstring.h b/mozilla/xpcom/string/public/nsDependentSubstring.h index 1f517d75a16..98463e68ab9 100644 --- a/mozilla/xpcom/string/public/nsDependentSubstring.h +++ b/mozilla/xpcom/string/public/nsDependentSubstring.h @@ -43,7 +43,7 @@ // class NS_COM nsDependentSubstring - : public nsAPromiseString + : public nsAString /* NOT FOR USE BY HUMANS (mostly) @@ -87,7 +87,6 @@ class NS_COM nsDependentSubstring public: virtual PRUint32 Length() const; - virtual PRBool IsDependentOn( const abstract_string_type& aString ) const { return mString.IsDependentOn(aString); } private: const abstract_string_type& mString; @@ -96,7 +95,7 @@ class NS_COM nsDependentSubstring }; class NS_COM nsDependentCSubstring - : public nsAPromiseCString + : public nsACString /* NOT FOR USE BY HUMANS (mostly) @@ -140,7 +139,6 @@ class NS_COM nsDependentCSubstring public: virtual PRUint32 Length() const; - virtual PRBool IsDependentOn( const abstract_string_type& aString ) const { return mString.IsDependentOn(aString); } private: const abstract_string_type& mString; diff --git a/mozilla/xpcom/string/public/nsPromiseFlatString.h b/mozilla/xpcom/string/public/nsPromiseFlatString.h index 3c63bc20112..23ca8b8daaf 100644 --- a/mozilla/xpcom/string/public/nsPromiseFlatString.h +++ b/mozilla/xpcom/string/public/nsPromiseFlatString.h @@ -81,7 +81,7 @@ */ class NS_COM nsPromiseFlatString - : public nsAFlatString /* , public nsAPromiseString */ + : public nsAFlatString { friend const nsPromiseFlatString PromiseFlatString( const abstract_string_type& ); @@ -99,7 +99,6 @@ class NS_COM nsPromiseFlatString virtual const buffer_handle_type* GetFlatBufferHandle() const; virtual const buffer_handle_type* GetBufferHandle() const; virtual const shared_buffer_handle_type* GetSharedBufferHandle() const; - virtual PRBool IsDependentOn( const abstract_string_type& ) const; // things we are forwarding now, but won't when we finally fix obsolete/nsString et al @@ -120,7 +119,7 @@ class NS_COM nsPromiseFlatString }; class NS_COM nsPromiseFlatCString - : public nsAFlatCString /* , public nsAPromiseCString */ + : public nsAFlatCString { friend const nsPromiseFlatCString PromiseFlatCString( const abstract_string_type& ); @@ -138,7 +137,6 @@ class NS_COM nsPromiseFlatCString virtual const buffer_handle_type* GetFlatBufferHandle() const; virtual const buffer_handle_type* GetBufferHandle() const; virtual const shared_buffer_handle_type* GetSharedBufferHandle() const; - virtual PRBool IsDependentOn( const abstract_string_type& ) const; // things we are forwarding now, but won't when we finally fix obsolete/nsString et al diff --git a/mozilla/xpcom/string/public/nsSlidingString.h b/mozilla/xpcom/string/public/nsSlidingString.h index 0f7a34248a6..547daf59f15 100755 --- a/mozilla/xpcom/string/public/nsSlidingString.h +++ b/mozilla/xpcom/string/public/nsSlidingString.h @@ -84,7 +84,7 @@ class nsSlidingString; * a substring over a buffer list, this */ class NS_COM nsSlidingSubstring - : virtual public nsAPromiseString + : virtual public nsAString { friend class nsSlidingString; @@ -170,7 +170,7 @@ class NS_COM nsSlidingSubstring * */ class NS_COM nsSlidingString - : virtual public nsAPromiseString, + : virtual public nsAString, private nsSlidingSubstring { friend class nsSlidingSubstring; diff --git a/mozilla/xpcom/string/public/nsStringFwd.h b/mozilla/xpcom/string/public/nsStringFwd.h index 4f68b5febb5..89c99b61bf8 100644 --- a/mozilla/xpcom/string/public/nsStringFwd.h +++ b/mozilla/xpcom/string/public/nsStringFwd.h @@ -39,14 +39,6 @@ class nsAString; class nsACString; - /** - * @see nsAPromiseString.h - */ - -class nsAPromiseString; -class nsAPromiseCString; - - /** * @see nsAFlatString.h */ diff --git a/mozilla/xpcom/string/public/nsStringTraits.h b/mozilla/xpcom/string/public/nsStringTraits.h index fd7b2829e53..94e1ba968c5 100644 --- a/mozilla/xpcom/string/public/nsStringTraits.h +++ b/mozilla/xpcom/string/public/nsStringTraits.h @@ -45,7 +45,6 @@ template struct nsStringTraits { typedef nsAString abstract_string_type; - typedef nsAPromiseString abstract_promise_type; typedef nsAFlatString abstract_flat_type; typedef const nsDependentString literal_string_type; }; @@ -57,7 +56,6 @@ NS_SPECIALIZE_TEMPLATE struct nsStringTraits { typedef nsAString abstract_string_type; - typedef nsAPromiseString abstract_promise_type; typedef nsAFlatString abstract_flat_type; typedef const nsDependentString literal_string_type; }; @@ -67,7 +65,6 @@ NS_SPECIALIZE_TEMPLATE struct nsStringTraits { typedef nsACString abstract_string_type; - typedef nsAPromiseCString abstract_promise_type; typedef nsAFlatCString abstract_flat_type; typedef const nsDependentCString literal_string_type; }; diff --git a/mozilla/xpcom/string/src/nsAString.cpp b/mozilla/xpcom/string/src/nsAString.cpp index a059afdfe21..0d56b9f2443 100644 --- a/mozilla/xpcom/string/src/nsAString.cpp +++ b/mozilla/xpcom/string/src/nsAString.cpp @@ -205,23 +205,42 @@ nsAString::FindChar( char_type aChar, PRUint32 aOffset ) const return -1; } +PRBool +nsAString::IsDependentOn( const self_type& aString ) const + { + const_fragment_type f1; + const char_type* s1 = GetReadableFragment(f1, kFirstFragment); + while ( s1 ) + { + const_fragment_type f2; + const char_type* s2 = aString.GetReadableFragment(f2, kFirstFragment); + while ( s2 ) + { + // if it _isn't_ the case that + // one fragment starts after the other ends, + // or ends before the other starts, + // then, they conflict: + // !(f2.mStart>=f1.mEnd || f2.mEnd<=f1.mStart) + // + // Simplified, that gives us: + if ( f2.mStart < f1.mEnd && f2.mEnd > f1.mStart ) + return PR_TRUE; + + s2 = aString.GetReadableFragment(f2, kNextFragment); + } + s1 = GetReadableFragment(f1, kNextFragment); + } + return PR_FALSE; + } // // |Assign()| // void -nsAString::AssignFromReadable( const self_type& rhs ) - { - if ( this != &rhs ) - do_AssignFromReadable(rhs); - // else, self-assign is a no-op - } - -void -nsAString::AssignFromPromise( const self_type& aReadable ) +nsAString::do_AssignFromReadable( const self_type& aReadable ) /* - ...this function is only called when a promise that somehow references |this| is assigned _into_ |this|. + ...we need to check whether the string that's being assigned into |this| somehow references |this|. E.g., ... writable& w ... @@ -241,8 +260,12 @@ nsAString::AssignFromPromise( const self_type& aReadable ) option to fix either the callers or this mechanism. */ { + // self-assign is a no-op + if ( this == &aReadable) + return; + if ( !aReadable.IsDependentOn(*this) ) - do_AssignFromReadable(aReadable); + UncheckedAssignFromReadable(aReadable); else { size_type length = aReadable.Length(); @@ -262,7 +285,7 @@ nsAString::AssignFromPromise( const self_type& aReadable ) } void -nsAString::do_AssignFromReadable( const self_type& aReadable ) +nsAString::UncheckedAssignFromReadable( const self_type& aReadable ) { SetLength(0); if ( !aReadable.IsEmpty() ) @@ -280,19 +303,19 @@ nsAString::do_AssignFromReadable( const self_type& aReadable ) void nsAString::do_AssignFromElementPtr( const char_type* aPtr ) { - do_AssignFromReadable(nsDependentString(aPtr)); + UncheckedAssignFromReadable(nsDependentString(aPtr)); } void nsAString::do_AssignFromElementPtrLength( const char_type* aPtr, size_type aLength ) { - do_AssignFromReadable(Substring(aPtr, aPtr+aLength)); + UncheckedAssignFromReadable(Substring(aPtr, aPtr+aLength)); } void nsAString::do_AssignFromElement( char_type aChar ) { - do_AssignFromReadable(Substring(&aChar, &aChar+1)); + UncheckedAssignFromReadable(Substring(&aChar, &aChar+1)); } @@ -302,19 +325,10 @@ nsAString::do_AssignFromElement( char_type aChar ) // void -nsAString::AppendFromReadable( const self_type& aReadable ) - { - if ( this != &aReadable ) - do_AppendFromReadable(aReadable); - else - AppendFromPromise(aReadable); - } - -void -nsAString::AppendFromPromise( const self_type& aReadable ) +nsAString::do_AppendFromReadable( const self_type& aReadable ) { if ( !aReadable.IsDependentOn(*this) ) - do_AppendFromReadable(aReadable); + UncheckedAppendFromReadable(aReadable); else { size_type length = aReadable.Length(); @@ -332,7 +346,7 @@ nsAString::AppendFromPromise( const self_type& aReadable ) } void -nsAString::do_AppendFromReadable( const self_type& aReadable ) +nsAString::UncheckedAppendFromReadable( const self_type& aReadable) { size_type oldLength = this->Length(); SetLength(oldLength + aReadable.Length()); @@ -342,22 +356,23 @@ nsAString::do_AppendFromReadable( const self_type& aReadable ) copy_string(aReadable.BeginReading(fromBegin), aReadable.EndReading(fromEnd), BeginWriting(toBegin).advance( PRInt32(oldLength) ) ); } + void nsAString::do_AppendFromElementPtr( const char_type* aPtr ) { - do_AppendFromReadable(nsDependentString(aPtr)); + UncheckedAppendFromReadable(nsDependentString(aPtr)); } void nsAString::do_AppendFromElementPtrLength( const char_type* aPtr, size_type aLength ) { - do_AppendFromReadable(Substring(aPtr, aPtr+aLength)); + UncheckedAppendFromReadable(Substring(aPtr, aPtr+aLength)); } void nsAString::do_AppendFromElement( char_type aChar ) { - do_AppendFromReadable(Substring(&aChar, &aChar + 1)); + UncheckedAppendFromReadable(Substring(&aChar, &aChar + 1)); } @@ -367,19 +382,10 @@ nsAString::do_AppendFromElement( char_type aChar ) // void -nsAString::InsertFromReadable( const self_type& aReadable, index_type atPosition ) - { - if ( this != &aReadable ) - do_InsertFromReadable(aReadable, atPosition); - else - InsertFromPromise(aReadable, atPosition); - } - -void -nsAString::InsertFromPromise( const self_type& aReadable, index_type atPosition ) +nsAString::do_InsertFromReadable( const self_type& aReadable, index_type atPosition ) { if ( !aReadable.IsDependentOn(*this) ) - do_InsertFromReadable(aReadable, atPosition); + UncheckedInsertFromReadable(aReadable, atPosition); else { size_type length = aReadable.Length(); @@ -397,7 +403,7 @@ nsAString::InsertFromPromise( const self_type& aReadable, index_type atPosition } void -nsAString::do_InsertFromReadable( const self_type& aReadable, index_type atPosition ) +nsAString::UncheckedInsertFromReadable( const self_type& aReadable, index_type atPosition ) { size_type oldLength = this->Length(); SetLength(oldLength + aReadable.Length()); @@ -414,19 +420,19 @@ nsAString::do_InsertFromReadable( const self_type& aReadable, index_type atPosit void nsAString::do_InsertFromElementPtr( const char_type* aPtr, index_type atPosition ) { - do_InsertFromReadable(nsDependentString(aPtr), atPosition); + UncheckedInsertFromReadable(nsDependentString(aPtr), atPosition); } void nsAString::do_InsertFromElementPtrLength( const char_type* aPtr, index_type atPosition, size_type aLength ) { - do_InsertFromReadable(Substring(aPtr, aPtr+aLength), atPosition); + UncheckedInsertFromReadable(Substring(aPtr, aPtr+aLength), atPosition); } void nsAString::do_InsertFromElement( char_type aChar, index_type atPosition ) { - do_InsertFromReadable(Substring(&aChar, &aChar+1), atPosition); + UncheckedInsertFromReadable(Substring(&aChar, &aChar+1), atPosition); } @@ -456,19 +462,10 @@ nsAString::Cut( index_type cutStart, size_type cutLength ) // void -nsAString::ReplaceFromReadable( index_type cutStart, size_type cutLength, const self_type& aReplacement ) - { - if ( this != &aReplacement ) - do_ReplaceFromReadable(cutStart, cutLength, aReplacement); - else - ReplaceFromPromise(cutStart, cutLength, aReplacement); - } - -void -nsAString::ReplaceFromPromise( index_type cutStart, size_type cutLength, const self_type& aReadable ) +nsAString::do_ReplaceFromReadable( index_type cutStart, size_type cutLength, const self_type& aReadable ) { if ( !aReadable.IsDependentOn(*this) ) - do_ReplaceFromReadable(cutStart, cutLength, aReadable); + UncheckedReplaceFromReadable(cutStart, cutLength, aReadable); else { size_type length = aReadable.Length(); @@ -478,7 +475,7 @@ nsAString::ReplaceFromPromise( index_type cutStart, size_type cutLength, const s const_iterator fromBegin, fromEnd; char_type* toBegin = buffer; copy_string(aReadable.BeginReading(fromBegin), aReadable.EndReading(fromEnd), toBegin); - do_ReplaceFromReadable(cutStart, cutLength, nsDependentString(buffer, length)); + UncheckedReplaceFromReadable(cutStart, cutLength, nsDependentString(buffer, length)); delete[] buffer; } // else assert? @@ -486,7 +483,7 @@ nsAString::ReplaceFromPromise( index_type cutStart, size_type cutLength, const s } void -nsAString::do_ReplaceFromReadable( index_type cutStart, size_type cutLength, const self_type& aReplacement ) +nsAString::UncheckedReplaceFromReadable( index_type cutStart, size_type cutLength, const self_type& aReplacement ) { size_type oldLength = this->Length(); @@ -511,6 +508,7 @@ nsAString::do_ReplaceFromReadable( index_type cutStart, size_type cutLength, con } + int nsDefaultCStringComparator::operator()( const char_type* lhs, const char_type* rhs, PRUint32 aLength ) const { @@ -704,23 +702,42 @@ nsACString::FindChar( char_type aChar, PRUint32 aOffset ) const return -1; } +PRBool +nsACString::IsDependentOn( const self_type& aString ) const + { + const_fragment_type f1; + const char_type* s1 = GetReadableFragment(f1, kFirstFragment); + while ( s1 ) + { + const_fragment_type f2; + const char_type* s2 = aString.GetReadableFragment(f2, kFirstFragment); + while ( s2 ) + { + // if it _isn't_ the case that + // one fragment starts after the other ends, + // or ends before the other starts, + // then, they conflict: + // !(f2.mStart>=f1.mEnd || f2.mEnd<=f1.mStart) + // + // Simplified, that gives us: + if ( f2.mStart < f1.mEnd && f2.mEnd > f1.mStart ) + return PR_TRUE; + + s2 = aString.GetReadableFragment(f2, kNextFragment); + } + s1 = GetReadableFragment(f1, kNextFragment); + } + return PR_FALSE; + } // // |Assign()| // void -nsACString::AssignFromReadable( const self_type& rhs ) - { - if ( this != &rhs ) - do_AssignFromReadable(rhs); - // else, self-assign is a no-op - } - -void -nsACString::AssignFromPromise( const self_type& aReadable ) +nsACString::do_AssignFromReadable( const self_type& aReadable ) /* - ...this function is only called when a promise that somehow references |this| is assigned _into_ |this|. + ...we need to check whether the string that's being assigned into |this| somehow references |this|. E.g., ... writable& w ... @@ -740,8 +757,12 @@ nsACString::AssignFromPromise( const self_type& aReadable ) option to fix either the callers or this mechanism. */ { + // self-assign is a no-op + if (this == &aReadable) + return; + if ( !aReadable.IsDependentOn(*this) ) - do_AssignFromReadable(aReadable); + UncheckedAssignFromReadable(aReadable); else { size_type length = aReadable.Length(); @@ -761,7 +782,7 @@ nsACString::AssignFromPromise( const self_type& aReadable ) } void -nsACString::do_AssignFromReadable( const self_type& aReadable ) +nsACString::UncheckedAssignFromReadable( const self_type& aReadable ) { SetLength(0); if ( !aReadable.IsEmpty() ) @@ -779,19 +800,19 @@ nsACString::do_AssignFromReadable( const self_type& aReadable ) void nsACString::do_AssignFromElementPtr( const char_type* aPtr ) { - do_AssignFromReadable(nsDependentCString(aPtr)); + UncheckedAssignFromReadable(nsDependentCString(aPtr)); } void nsACString::do_AssignFromElementPtrLength( const char_type* aPtr, size_type aLength ) { - do_AssignFromReadable(Substring(aPtr, aPtr+aLength)); + UncheckedAssignFromReadable(Substring(aPtr, aPtr+aLength)); } void nsACString::do_AssignFromElement( char_type aChar ) { - do_AssignFromReadable(Substring(&aChar, &aChar+1)); + UncheckedAssignFromReadable(Substring(&aChar, &aChar+1)); } @@ -801,19 +822,10 @@ nsACString::do_AssignFromElement( char_type aChar ) // void -nsACString::AppendFromReadable( const self_type& aReadable ) - { - if ( this != &aReadable ) - do_AppendFromReadable(aReadable); - else - AppendFromPromise(aReadable); - } - -void -nsACString::AppendFromPromise( const self_type& aReadable ) +nsACString::do_AppendFromReadable( const self_type& aReadable ) { if ( !aReadable.IsDependentOn(*this) ) - do_AppendFromReadable(aReadable); + UncheckedAppendFromReadable(aReadable); else { size_type length = aReadable.Length(); @@ -831,7 +843,7 @@ nsACString::AppendFromPromise( const self_type& aReadable ) } void -nsACString::do_AppendFromReadable( const self_type& aReadable ) +nsACString::UncheckedAppendFromReadable( const self_type& aReadable ) { size_type oldLength = this->Length(); SetLength(oldLength + aReadable.Length()); @@ -844,19 +856,19 @@ nsACString::do_AppendFromReadable( const self_type& aReadable ) void nsACString::do_AppendFromElementPtr( const char_type* aPtr ) { - do_AppendFromReadable(nsDependentCString(aPtr)); + UncheckedAppendFromReadable(nsDependentCString(aPtr)); } void nsACString::do_AppendFromElementPtrLength( const char_type* aPtr, size_type aLength ) { - do_AppendFromReadable(Substring(aPtr, aPtr+aLength)); + UncheckedAppendFromReadable(Substring(aPtr, aPtr+aLength)); } void nsACString::do_AppendFromElement( char_type aChar ) { - do_AppendFromReadable(Substring(&aChar, &aChar + 1)); + UncheckedAppendFromReadable(Substring(&aChar, &aChar + 1)); } @@ -866,19 +878,10 @@ nsACString::do_AppendFromElement( char_type aChar ) // void -nsACString::InsertFromReadable( const self_type& aReadable, index_type atPosition ) - { - if ( this != &aReadable ) - do_InsertFromReadable(aReadable, atPosition); - else - InsertFromPromise(aReadable, atPosition); - } - -void -nsACString::InsertFromPromise( const self_type& aReadable, index_type atPosition ) +nsACString::do_InsertFromReadable( const self_type& aReadable, index_type atPosition ) { if ( !aReadable.IsDependentOn(*this) ) - do_InsertFromReadable(aReadable, atPosition); + UncheckedInsertFromReadable(aReadable, atPosition); else { size_type length = aReadable.Length(); @@ -896,7 +899,7 @@ nsACString::InsertFromPromise( const self_type& aReadable, index_type atPosition } void -nsACString::do_InsertFromReadable( const self_type& aReadable, index_type atPosition ) +nsACString::UncheckedInsertFromReadable( const self_type& aReadable, index_type atPosition ) { size_type oldLength = this->Length(); SetLength(oldLength + aReadable.Length()); @@ -913,19 +916,19 @@ nsACString::do_InsertFromReadable( const self_type& aReadable, index_type atPosi void nsACString::do_InsertFromElementPtr( const char_type* aPtr, index_type atPosition ) { - do_InsertFromReadable(nsDependentCString(aPtr), atPosition); + UncheckedInsertFromReadable(nsDependentCString(aPtr), atPosition); } void nsACString::do_InsertFromElementPtrLength( const char_type* aPtr, index_type atPosition, size_type aLength ) { - do_InsertFromReadable(Substring(aPtr, aPtr+aLength), atPosition); + UncheckedInsertFromReadable(Substring(aPtr, aPtr+aLength), atPosition); } void nsACString::do_InsertFromElement( char_type aChar, index_type atPosition ) { - do_InsertFromReadable(Substring(&aChar, &aChar+1), atPosition); + UncheckedInsertFromReadable(Substring(&aChar, &aChar+1), atPosition); } @@ -955,19 +958,10 @@ nsACString::Cut( index_type cutStart, size_type cutLength ) // void -nsACString::ReplaceFromReadable( index_type cutStart, size_type cutLength, const self_type& aReplacement ) - { - if ( this != &aReplacement ) - do_ReplaceFromReadable(cutStart, cutLength, aReplacement); - else - ReplaceFromPromise(cutStart, cutLength, aReplacement); - } - -void -nsACString::ReplaceFromPromise( index_type cutStart, size_type cutLength, const self_type& aReadable ) +nsACString::do_ReplaceFromReadable( index_type cutStart, size_type cutLength, const self_type& aReadable ) { if ( !aReadable.IsDependentOn(*this) ) - do_ReplaceFromReadable(cutStart, cutLength, aReadable); + UncheckedReplaceFromReadable(cutStart, cutLength, aReadable); else { size_type length = aReadable.Length(); @@ -977,7 +971,7 @@ nsACString::ReplaceFromPromise( index_type cutStart, size_type cutLength, const const_iterator fromBegin, fromEnd; char_type* toBegin = buffer; copy_string(aReadable.BeginReading(fromBegin), aReadable.EndReading(fromEnd), toBegin); - do_ReplaceFromReadable(cutStart, cutLength, nsDependentCString(buffer, length)); + UncheckedReplaceFromReadable(cutStart, cutLength, nsDependentCString(buffer, length)); delete[] buffer; } // else assert? @@ -985,7 +979,7 @@ nsACString::ReplaceFromPromise( index_type cutStart, size_type cutLength, const } void -nsACString::do_ReplaceFromReadable( index_type cutStart, size_type cutLength, const self_type& aReplacement ) +nsACString::UncheckedReplaceFromReadable( index_type cutStart, size_type cutLength, const self_type& aReplacement ) { size_type oldLength = this->Length(); diff --git a/mozilla/xpcom/string/src/nsDependentConcatenation.cpp b/mozilla/xpcom/string/src/nsDependentConcatenation.cpp index f9ecc3b84d2..3a9fd92dfb3 100644 --- a/mozilla/xpcom/string/src/nsDependentConcatenation.cpp +++ b/mozilla/xpcom/string/src/nsDependentConcatenation.cpp @@ -38,12 +38,6 @@ nsDependentConcatenation::Length() const return mStrings[kFirstString]->Length() + mStrings[kLastString]->Length(); } -PRBool -nsDependentConcatenation::IsDependentOn( const abstract_string_type& aString ) const - { - return mStrings[kFirstString]->IsDependentOn(aString) || mStrings[kLastString]->IsDependentOn(aString); - } - #if 0 PRBool nsDependentConcatenation::PromisesExactly( const abstract_string_type& aString ) const @@ -123,12 +117,6 @@ nsDependentCConcatenation::Length() const return mStrings[kFirstString]->Length() + mStrings[kLastString]->Length(); } -PRBool -nsDependentCConcatenation::IsDependentOn( const abstract_string_type& aString ) const - { - return mStrings[kFirstString]->IsDependentOn(aString) || mStrings[kLastString]->IsDependentOn(aString); - } - #if 0 PRBool nsDependentCConcatenation::PromisesExactly( const abstract_string_type& aString ) const diff --git a/mozilla/xpcom/string/src/nsPromiseFlatString.cpp b/mozilla/xpcom/string/src/nsPromiseFlatString.cpp index 907e5e64acb..f16395f65b2 100644 --- a/mozilla/xpcom/string/src/nsPromiseFlatString.cpp +++ b/mozilla/xpcom/string/src/nsPromiseFlatString.cpp @@ -62,12 +62,6 @@ nsPromiseFlatString::GetSharedBufferHandle() const return mPromisedString->GetSharedBufferHandle(); } -PRBool -nsPromiseFlatString::IsDependentOn( const abstract_string_type& aString ) const - { - return mPromisedString->IsDependentOn(aString); - } - const nsPromiseFlatString::char_type* nsPromiseFlatString::get() const { @@ -126,12 +120,6 @@ nsPromiseFlatCString::GetSharedBufferHandle() const return mPromisedString->GetSharedBufferHandle(); } -PRBool -nsPromiseFlatCString::IsDependentOn( const abstract_string_type& aString ) const - { - return mPromisedString->IsDependentOn(aString); - } - const nsPromiseFlatCString::char_type* nsPromiseFlatCString::get() const {