This is the mail archive of the
java@gcc.gnu.org
mailing list for the Java project.
Re: String.substring() question
- To: tromey at redhat dot com
- Subject: Re: String.substring() question
- From: Per Bothner <per at bothner dot com>
- Date: 16 May 2001 17:31:56 -0700
- Cc: Java Discuss List <java at gcc dot gnu dot org>
- References: <87heykbztx.fsf@creche.redhat.com>
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/