This is the mail archive of the
java-patches@gcc.gnu.org
mailing list for the Java project.
Patch: FYI: String.substring, aka PR libgcj/21753
- From: Tom Tromey <tromey at redhat dot com>
- To: Java Patch List <java-patches at gcc dot gnu dot org>
- Date: 01 Jun 2005 09:37:49 -0600
- Subject: Patch: FYI: String.substring, aka PR libgcj/21753
- Reply-to: tromey at redhat dot com
I'm checking this in on the trunk and the 4.0 branch.
I changed the heuristic to require more than half of the original
string, per Bryce's suggestion. I also changed the expression to
avoid possible overflow, per Hans' suggestion.
Hans, I didn't see a nice way to reduce the number of checks.
Tom
Index: ChangeLog
from Tom Tromey <tromey@redhat.com>
PR libgcj/21753:
* java/lang/natString.cc (substring): Changed sharing heuristic.
Index: java/lang/natString.cc
===================================================================
RCS file: /cvs/gcc/gcc/libjava/java/lang/natString.cc,v
retrieving revision 1.38
diff -u -r1.38 natString.cc
--- java/lang/natString.cc 25 May 2005 15:23:56 -0000 1.38
+++ java/lang/natString.cc 1 Jun 2005 15:36:25 -0000
@@ -833,7 +833,10 @@
if (beginIndex == 0 && endIndex == count)
return this;
jint newCount = endIndex - beginIndex;
- if (newCount <= 8) // Optimization, mainly for GC.
+ // For very small strings, just allocate a new one. For other
+ // substrings, allocate a new one unless the substring is over half
+ // of the original string.
+ if (newCount <= 8 || newCount < (count >> 1))
return JvNewString(JvGetStringChars(this) + beginIndex, newCount);
jstring s = new String();
s->data = data;