String.substring() question

Tom Tromey
Thu May 17 10:56:00 GMT 2001

Per>   if (newCount <= 8)  // Optimization, mainly for GC.
Per>     return JvNewString(JvGetStringChars(this) + beginIndex, newCount);

Thanks, I missed that.

This isn't really what I was getting at though.  If we are making a
substring of a String which is already small, then copying it seems
less efficient than referring to it.  But if we make a small substring
of a very large String then copying it might often be better -- if if
the "small" is only relative.  For instance a 1K substring of a 1M
String "should" (if we had perfect knowledge) be copied if it is the
only thing keeping the String alive.


More information about the Java mailing list