[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [cp-patches] StringBuilder and Appendable for CVS HEAD
From: |
Tom Tromey |
Subject: |
Re: [cp-patches] StringBuilder and Appendable for CVS HEAD |
Date: |
18 Dec 2004 23:29:08 -0700 |
User-agent: |
Gnus/5.09 (Gnus v5.9.0) Emacs/21.3.50 |
Jeroen> Doesn't help. If StringBuilder is busy modifying the character
Jeroen> array in one thread (after it checked the shared flag) and on
Jeroen> another thread a new String is constructed from that
Jeroen> StringBuilder object, you now have a mutable String.
I don't know why I've been so dense about this.
I'm checking in the appended to the generics branch.
Tom
Index: ChangeLog
from Tom Tromey <address@hidden>
* java/lang/String.java (String(StringBuilder)): Rewrote.
* java/lang/StringBuilder.java (shared): Removed.
(ensureCapacity): Updated.
(substrinng): Likewise.
(toString): Likewise.
Index: java/lang/String.java
===================================================================
RCS file: /cvsroot/classpath/classpath/java/lang/String.java,v
retrieving revision 1.58.2.2
diff -u -r1.58.2.2 String.java
--- java/lang/String.java 9 Oct 2004 23:39:06 -0000 1.58.2.2
+++ java/lang/String.java 19 Dec 2004 06:31:38 -0000
@@ -449,22 +449,7 @@
*/
public String(StringBuilder buffer)
{
- synchronized (buffer)
- {
- offset = 0;
- count = buffer.count;
- // Share unless buffer is 3/4 empty.
- if ((count << 2) < buffer.value.length)
- {
- value = new char[count];
- System.arraycopy(buffer.value, 0, value, 0, count);
- }
- else
- {
- buffer.shared = true;
- value = buffer.value;
- }
- }
+ this(buffer.value, 0, buffer.count);
}
/**
Index: java/lang/StringBuilder.java
===================================================================
RCS file: /cvsroot/classpath/classpath/java/lang/Attic/StringBuilder.java,v
retrieving revision 1.1.2.3
diff -u -r1.1.2.3 StringBuilder.java
--- java/lang/StringBuilder.java 15 Oct 2004 00:55:26 -0000 1.1.2.3
+++ java/lang/StringBuilder.java 19 Dec 2004 06:31:38 -0000
@@ -103,16 +103,6 @@
char[] value;
/**
- * True if the buffer is shared with another object (StringBuilder or
- * String); this means the buffer must be copied before writing to it again.
- * Note that this has permissions set this way so that String can get the
- * value.
- *
- * @serial whether the buffer is shared
- */
- boolean shared;
-
- /**
* The default capacity of a buffer.
*/
private final static int DEFAULT_CAPACITY = 16;
@@ -211,19 +201,13 @@
*/
public void ensureCapacity(int minimumCapacity)
{
- if (shared || minimumCapacity > value.length)
+ if (minimumCapacity > value.length)
{
- // We don't want to make a larger vector when `shared' is
- // set. If we do, then setLength becomes very inefficient
- // when repeatedly reusing a StringBuilder in a loop.
- int max = (minimumCapacity > value.length
- ? value.length * 2 + 2
- : value.length);
+ int max = value.length * 2 + 2;
minimumCapacity = (minimumCapacity < max ? max : minimumCapacity);
char[] nb = new char[minimumCapacity];
System.arraycopy(value, 0, nb, 0, count);
value = nb;
- shared = false;
}
}
@@ -661,12 +645,7 @@
throw new StringIndexOutOfBoundsException();
if (len == 0)
return "";
- // Don't copy unless substring is smaller than 1/4 of the buffer.
- boolean share_buffer = ((len << 2) >= value.length);
- if (share_buffer)
- this.shared = true;
- // Package constructor avoids an array copy.
- return new String(value, beginIndex, len, share_buffer);
+ return new String(value, beginIndex, len);
}
/**
@@ -951,7 +930,6 @@
*/
public String toString()
{
- // The string will set this.shared = true.
return new String(this);
}
- Re: [cp-patches] StringBuilder and Appendable for CVS HEAD, (continued)
RE: [cp-patches] StringBuilder and Appendable for CVS HEAD, Jeroen Frijters, 2004/12/15
RE: [cp-patches] StringBuilder and Appendable for CVS HEAD, Jeroen Frijters, 2004/12/16
RE: [cp-patches] StringBuilder and Appendable for CVS HEAD, Jeroen Frijters, 2004/12/16
RE: [cp-patches] StringBuilder and Appendable for CVS HEAD, Jeroen Frijters, 2004/12/16
- Re: [cp-patches] StringBuilder and Appendable for CVS HEAD,
Tom Tromey <=