From: Juraj Skripsky Date: Sun, 1 Jun 2008 17:57:48 +0000 (-0000) Subject: 2008-06-01 Juraj Skripsky X-Git-Url: http://wien.tomnetworks.com/gitweb/?a=commitdiff_plain;h=169c1ff0f6e24d97a757d67ac8971a386116c846;p=mono.git 2008-06-01 Juraj Skripsky * StringBuilder.cs (ToString): Use String.SubstringUnchecked instead of String.Substring, as the former is guaranteed to create a new string object. Fixes bug #395904. * String.cs (Substring): Blocking bug #395904 has been fixed, re-enable optimization. * StringTest.cs (Substring2): Blocking bug #395904 has been fixed, re-enable test. svn path=/trunk/mcs/; revision=104629 --- diff --git a/mcs/class/corlib/System.Text/ChangeLog b/mcs/class/corlib/System.Text/ChangeLog index 6b2a683ca23..ea22ad83217 100644 --- a/mcs/class/corlib/System.Text/ChangeLog +++ b/mcs/class/corlib/System.Text/ChangeLog @@ -1,3 +1,9 @@ +2008-06-01 Juraj Skripsky + + * StringBuilder.cs (ToString): Use String.SubstringUnchecked instead + of String.Substring, as the former is guaranteed to create a new + string object. Fixes bug #395904. + 2008-05-15 Andreas Nahr * StringBuilder.cs: Resubmit uncritical parts of String cleanup patch diff --git a/mcs/class/corlib/System.Text/StringBuilder.cs b/mcs/class/corlib/System.Text/StringBuilder.cs index f9ff5c34259..a3c37831dae 100644 --- a/mcs/class/corlib/System.Text/StringBuilder.cs +++ b/mcs/class/corlib/System.Text/StringBuilder.cs @@ -203,7 +203,9 @@ namespace System.Text { // If we only have a half-full buffer we return a new string. if (_length < (_str.Length >> 1)) { - _cached_str = _str.Substring(0, _length); + // use String.SubstringUnchecked instead of String.Substring + // as the former is guaranteed to create a new string object + _cached_str = _str.SubstringUnchecked (0, _length); return _cached_str; } @@ -219,7 +221,12 @@ namespace System.Text { if (startIndex < 0 || length < 0 || startIndex > _length - length) throw new ArgumentOutOfRangeException(); - return _str.Substring (startIndex, length); + // use String.SubstringUnchecked instead of String.Substring + // as the former is guaranteed to create a new string object + if (startIndex == 0 && length == _length) + return ToString (); + else + return _str.SubstringUnchecked (startIndex, length); } public int EnsureCapacity (int capacity) diff --git a/mcs/class/corlib/System/ChangeLog b/mcs/class/corlib/System/ChangeLog index 8f2edd62c12..bd2ea28cec3 100644 --- a/mcs/class/corlib/System/ChangeLog +++ b/mcs/class/corlib/System/ChangeLog @@ -1,3 +1,8 @@ +2008-06-01 Juraj Skripsky + + * String.cs (Substring): Blocking bug #395904 has been fixed, + re-enable optimization. + 2008-06-01 Andreas Nahr * String.cs: Replace Split IndexOf diff --git a/mcs/class/corlib/System/String.cs b/mcs/class/corlib/System/String.cs index 4f86afcffc9..87e92947462 100644 --- a/mcs/class/corlib/System/String.cs +++ b/mcs/class/corlib/System/String.cs @@ -362,16 +362,15 @@ namespace System if (startIndex > this.length - length) throw new ArgumentOutOfRangeException ("length", "startIndex + length > this.length"); #if NET_2_0 - // FIXME: this causes regressions in System.Xml - /* if (startIndex == 0 && length == this.length) return this; - */ #endif return SubstringUnchecked (startIndex, length); } + // This method is used by StringBuilder.ToString() and is expected to + // always create a new string object (or return String.Empty). internal unsafe String SubstringUnchecked (int startIndex, int length) { if (length == 0) diff --git a/mcs/class/corlib/Test/System/ChangeLog b/mcs/class/corlib/Test/System/ChangeLog index 555c5cff10d..d08106c40ca 100644 --- a/mcs/class/corlib/Test/System/ChangeLog +++ b/mcs/class/corlib/Test/System/ChangeLog @@ -1,3 +1,8 @@ +2008-06-01 Juraj Skripsky + + * StringTest.cs (Substring2): Blocking bug #395904 has been fixed, + re-enable test. + 2008-05-24 Andreas Nahr * StringTest.cs: Comment out a test that currently fails by checking for diff --git a/mcs/class/corlib/Test/System/StringTest.cs b/mcs/class/corlib/Test/System/StringTest.cs index 8bbef31d334..1b0c4a4445c 100644 --- a/mcs/class/corlib/Test/System/StringTest.cs +++ b/mcs/class/corlib/Test/System/StringTest.cs @@ -3454,8 +3454,7 @@ public class StringTest : TestCase AssertEquals ("#3", "origina", s.Substring (0, s.Length - 1)); AssertEquals ("#4", s, s.Substring (0, s.Length)); #if NET_2_0 - // FIXME: enabling the fix for this causes regressions in System.Xml - //AssertSame ("#5", s, s.Substring (0, s.Length)); + AssertSame ("#5", s, s.Substring (0, s.Length)); #else Assert ("#5", !object.ReferenceEquals (s, s.Substring (0, s.Length))); #endif