Commit 88962108 by Ralph Loader Committed by Bryce McKinlay

re PR libgcj/12350 (StringBuffer.substring handles shared flag incorrected.)

2003-09-21  Ralph Loader  <suckfish@ihug.co.nz>

        PR java/12350:
        * java/lang/StringBuffer.java (substring): Fix handling of shared
        flag.

2003-09-21  Ralph Loader  <suckfish@ihug.co.nz>

        PR java/12350
        * libjava.lang/PR12350.java: New file.
        * libjava.lang/PR12350.out: New file.

From-SVN: r71651
parent b5bb72ec
2003-09-21 Ralph Loader <suckfish@ihug.co.nz>
PR java/12350:
* java/lang/StringBuffer.java (substring): Fix handling of shared flag.
2003-09-22 Michael Koch <konqueror@gmx.de> 2003-09-22 Michael Koch <konqueror@gmx.de>
* jni.cc (_Jv_LookupJNIMethod): Remove workaround that should hide a * jni.cc (_Jv_LookupJNIMethod): Remove workaround that should hide a
......
...@@ -564,8 +564,9 @@ public final class StringBuffer implements Serializable, CharSequence ...@@ -564,8 +564,9 @@ public final class StringBuffer implements Serializable, CharSequence
throw new StringIndexOutOfBoundsException(); throw new StringIndexOutOfBoundsException();
if (len == 0) if (len == 0)
return ""; return "";
// Share the char[] unless 3/4 empty. // Share unless substring is smaller than 1/4 of the buffer.
shared = (len << 2) >= value.length; if ((len << 2) >= value.length)
shared = true;
// Package constructor avoids an array copy. // Package constructor avoids an array copy.
return new String(value, beginIndex, len, shared); return new String(value, beginIndex, len, shared);
} }
......
2003-09-21 Ralph Loader <suckfish@ihug.co.nz>
PR java/12350
* libjava.lang/PR12350.java: New file.
* libjava.lang/PR12350.out: New file.
2003-09-17 Ranjit Mathew <rmathew@hotmail.com> 2003-09-17 Ranjit Mathew <rmathew@hotmail.com>
PR java/9577 PR java/9577
......
public class PR12350
{
static public void main (String[] ignored) throws Throwable
{
StringBuffer b = new StringBuffer ("Good string. More than 16 chars.");
// Should cause sharing.
String s = b.toString();
// Take a char by char unshared copy of s.
String t = new String (s.toCharArray());
b.substring (0, 4); // BUG: Clears shared flag.
b.replace (0, 4, "Bad "); // Modifies shared data.
System.out.println (s);
assert s.equals (t);
}
}
Good string. More than 16 chars.
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment