String.substring() question

Per Bothner per@bothner.com
Wed May 16 17:25:00 GMT 2001


Tom Tromey <tromey@redhat.com> writes:

> Right now String.substring() always creates a reference to the old
> string's data.

No it doesn't:

java::lang::String::substring (jint beginIndex, jint endIndex)
{
  ...
  if (newCount <= 8)  // Optimization, mainly for GC.
    return JvNewString(JvGetStringChars(this) + beginIndex, newCount);
  ...
}

The magic number 8 is somewhat arbitrary - 16 is also reasonable.
But something too much bigger than the String header is probably
a bad idea.
-- 
	--Per Bothner
per@bothner.com   http://www.bothner.com/per/



More information about the Java mailing list