2008-06-01 Juraj Skripsky <js@hotfeet.ch>
authorJuraj Skripsky <js@hotfeet.ch>
Sun, 1 Jun 2008 17:57:48 +0000 (17:57 -0000)
committerJuraj Skripsky <js@hotfeet.ch>
Sun, 1 Jun 2008 17:57:48 +0000 (17:57 -0000)
* 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

mcs/class/corlib/System.Text/ChangeLog
mcs/class/corlib/System.Text/StringBuilder.cs
mcs/class/corlib/System/ChangeLog
mcs/class/corlib/System/String.cs
mcs/class/corlib/Test/System/ChangeLog
mcs/class/corlib/Test/System/StringTest.cs

index 6b2a683ca23c06ec59cd46d9615682c9fffb68bc..ea22ad832172ac3e8436a8fd13423c235d9364fd 100644 (file)
@@ -1,3 +1,9 @@
+2008-06-01  Juraj Skripsky  <js@hotfeet.ch>
+
+       * 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 <ClassDevelopment@A-SoftTech.com>
 
        * StringBuilder.cs: Resubmit uncritical parts of String cleanup patch
index f9ff5c3425936f6e0e6a9de7c0702adc281a4977..a3c37831dae43266b81a3f6451ebbd91e6a6db26 100644 (file)
@@ -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) 
index 8f2edd62c12ad372f72275c016ab4bf43ac68d99..bd2ea28cec3747023df3a9e1ac271a8d0598d5b9 100644 (file)
@@ -1,3 +1,8 @@
+2008-06-01  Juraj Skripsky  <js@hotfeet.ch>
+
+       * String.cs (Substring): Blocking bug #395904 has been fixed,
+       re-enable optimization.
+
 2008-06-01  Andreas Nahr <ClassDevelopment@A-SoftTech.com>
 
        * String.cs: Replace Split IndexOf
index 4f86afcffc965901466c75391d0ed15f872359c4..87e92947462bd1683eb4e91d783c37704200f817 100644 (file)
@@ -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)
index 555c5cff10ddf20aabc38f093c57c90e4a808edd..d08106c40caedf6ef660380c09c5845cff9547bf 100644 (file)
@@ -1,3 +1,8 @@
+2008-06-01  Juraj Skripsky  <js@hotfeet.ch>
+
+       * StringTest.cs (Substring2): Blocking bug #395904 has been fixed,
+       re-enable test. 
+
 2008-05-24  Andreas Nahr <ClassDevelopment@A-SoftTech.com>
 
        * StringTest.cs: Comment out a test that currently fails by checking for
index 8bbef31d3348e9e8a1d9a734dfe5286e49cdf87b..1b0c4a4445c2351f3f8b44fd8f8e99c1d934dd00 100644 (file)
@@ -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