This is the mail archive of the java-patches@gcc.gnu.org mailing list for the Java project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Patch: FYI: String.substring, aka PR libgcj/21753


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;


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]