From 2ee4564df22571f44f1312ea391d5fb71576de47 Mon Sep 17 00:00:00 2001 From: "scc%mozilla.org" Date: Mon, 16 Jul 2001 20:29:30 +0000 Subject: [PATCH] bug #90981 (top-crash): sr=mscott, rs=waterson. the new |nsXPIDLC?String| implementation doesn't always have a buffer handle to give up. |BeginReading| won't do what you want in this case, so modify |do_AssignFromReadable| to elide copies from empty strings. git-svn-id: svn://10.0.0.236/trunk@99334 18797224-902f-48f8-a5cc-f745e15eee43 --- mozilla/string/src/nsAString.cpp | 30 +++++++++++++++----------- mozilla/xpcom/string/src/nsAString.cpp | 30 +++++++++++++++----------- 2 files changed, 36 insertions(+), 24 deletions(-) diff --git a/mozilla/string/src/nsAString.cpp b/mozilla/string/src/nsAString.cpp index 3f390f84ab2..60b3246a898 100644 --- a/mozilla/string/src/nsAString.cpp +++ b/mozilla/string/src/nsAString.cpp @@ -244,13 +244,16 @@ void nsAString::do_AssignFromReadable( const self_type& aReadable ) { SetLength(0); - SetLength(aReadable.Length()); - // first setting the length to |0| avoids copying characters only to be overwritten later - // in the case where the implementation decides to re-allocate + if ( !aReadable.IsEmpty() ) + { + SetLength(aReadable.Length()); + // first setting the length to |0| avoids copying characters only to be overwritten later + // in the case where the implementation decides to re-allocate - const_iterator fromBegin, fromEnd; - iterator toBegin; - copy_string(aReadable.BeginReading(fromBegin), aReadable.EndReading(fromEnd), BeginWriting(toBegin)); + const_iterator fromBegin, fromEnd; + iterator toBegin; + copy_string(aReadable.BeginReading(fromBegin), aReadable.EndReading(fromEnd), BeginWriting(toBegin)); + } } void @@ -704,13 +707,16 @@ void nsACString::do_AssignFromReadable( const self_type& aReadable ) { SetLength(0); - SetLength(aReadable.Length()); - // first setting the length to |0| avoids copying characters only to be overwritten later - // in the case where the implementation decides to re-allocate + if ( !aReadable.IsEmpty() ) + { + SetLength(aReadable.Length()); + // first setting the length to |0| avoids copying characters only to be overwritten later + // in the case where the implementation decides to re-allocate - const_iterator fromBegin, fromEnd; - iterator toBegin; - copy_string(aReadable.BeginReading(fromBegin), aReadable.EndReading(fromEnd), BeginWriting(toBegin)); + const_iterator fromBegin, fromEnd; + iterator toBegin; + copy_string(aReadable.BeginReading(fromBegin), aReadable.EndReading(fromEnd), BeginWriting(toBegin)); + } } void diff --git a/mozilla/xpcom/string/src/nsAString.cpp b/mozilla/xpcom/string/src/nsAString.cpp index 3f390f84ab2..60b3246a898 100644 --- a/mozilla/xpcom/string/src/nsAString.cpp +++ b/mozilla/xpcom/string/src/nsAString.cpp @@ -244,13 +244,16 @@ void nsAString::do_AssignFromReadable( const self_type& aReadable ) { SetLength(0); - SetLength(aReadable.Length()); - // first setting the length to |0| avoids copying characters only to be overwritten later - // in the case where the implementation decides to re-allocate + if ( !aReadable.IsEmpty() ) + { + SetLength(aReadable.Length()); + // first setting the length to |0| avoids copying characters only to be overwritten later + // in the case where the implementation decides to re-allocate - const_iterator fromBegin, fromEnd; - iterator toBegin; - copy_string(aReadable.BeginReading(fromBegin), aReadable.EndReading(fromEnd), BeginWriting(toBegin)); + const_iterator fromBegin, fromEnd; + iterator toBegin; + copy_string(aReadable.BeginReading(fromBegin), aReadable.EndReading(fromEnd), BeginWriting(toBegin)); + } } void @@ -704,13 +707,16 @@ void nsACString::do_AssignFromReadable( const self_type& aReadable ) { SetLength(0); - SetLength(aReadable.Length()); - // first setting the length to |0| avoids copying characters only to be overwritten later - // in the case where the implementation decides to re-allocate + if ( !aReadable.IsEmpty() ) + { + SetLength(aReadable.Length()); + // first setting the length to |0| avoids copying characters only to be overwritten later + // in the case where the implementation decides to re-allocate - const_iterator fromBegin, fromEnd; - iterator toBegin; - copy_string(aReadable.BeginReading(fromBegin), aReadable.EndReading(fromEnd), BeginWriting(toBegin)); + const_iterator fromBegin, fromEnd; + iterator toBegin; + copy_string(aReadable.BeginReading(fromBegin), aReadable.EndReading(fromEnd), BeginWriting(toBegin)); + } } void