So, I'm having a hard time seeing how this "optimization" actually makes the code faster under any reasonable assumptions of what an optimizing JIT is going to do. It seems mostly harmless to have it (although it makes the method larger, and thus a slightly less attractive candidate for inlining), but if it actually buys you any measurable speedup on a "high performance" VM, then you should really take a hard look at your VM/JIT and find out why they didn't do a good job on the "unoptimized" version in the first place. clone() on an array is just a short hand for a new followed by an arraycopy, and the new followed by arraycopy idiom shows up all over the place so you need to do a good job on it.
--dave [EMAIL PROTECTED] wrote on 07/12/2005 04:54:01 AM: > On Tue, 2005-07-12 at 13:02 +1200, Simon Kitching wrote: > > I just wondered if it was time to remove this hack... > > Wow, that is a very old workaround. And indeed a nice optimization to > have. A quick startup of eclipse (with just a little project) shows 4642 > hits of String.toCharArray() of which 4200 have (count == value.length). > Thanks for finding this. > > Committed as: > > Reported by Simon Kitching <[EMAIL PROTECTED]> > * java/lang/String.java (toCharArray): Return value.clone() when > count == value.length. > > Cheers, > > Mark > > diff -u -r1.67 String.java > --- java/lang/String.java 11 Jul 2005 22:30:07 -0000 1.67 > +++ java/lang/String.java 12 Jul 2005 08:48:23 -0000 > @@ -1499,10 +1499,9 @@ > */ > public char[] toCharArray() > { > - // XXX ORP 1.0.9 crashes on (char[]) clone() during bootstrap, so we > - // omit this optimization for now. > - // if (count == value.length) > - // return (char[]) value.clone(); > + if (count == value.length) > + return (char[]) value.clone(); > + > char[] copy = new char[count]; > VMSystem.arraycopy(value, offset, copy, 0, count); > return copy; > > [attachment "signature.asc" deleted by David P Grove/Watson/IBM] > _______________________________________________ > Classpath mailing list > Classpath@gnu.org > http://lists.gnu.org/mailman/listinfo/classpath _______________________________________________ Classpath mailing list Classpath@gnu.org http://lists.gnu.org/mailman/listinfo/classpath