This is the mail archive of the java@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]

Re: String.substring() question


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/


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