re PR libgcj/21753 (String.substring sharing heuristic should be improved)
authorTom Tromey <tromey@redhat.com>
Wed, 1 Jun 2005 15:52:45 +0000 (15:52 +0000)
committerTom Tromey <tromey@gcc.gnu.org>
Wed, 1 Jun 2005 15:52:45 +0000 (15:52 +0000)
PR libgcj/21753:
* java/lang/natString.cc (substring): Changed sharing heuristic.

From-SVN: r100454

libjava/ChangeLog
libjava/java/lang/natString.cc

index ca9f2f45fe13dc7fcbd68a03ed39158e72147e19..cddaecbd1d984042d365497f954c5d8b30c84a46 100644 (file)
@@ -1,3 +1,8 @@
+2005-06-01  Tom Tromey  <tromey@redhat.com>
+
+       PR libgcj/21753:
+       * java/lang/natString.cc (substring): Changed sharing heuristic.
+
 2005-05-30  Bryce McKinlay  <mckinlay@redhat.com>
 
        PR libgcj/21821
index a14f5de9d6ecfca08d389bd04b805443b1e78c9f..c8f3129a2129a77d2dbc44a7b4948af905ddbed1 100644 (file)
@@ -833,7 +833,10 @@ java::lang::String::substring (jint beginIndex, jint endIndex)
   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;