Name: rmT116609 Date: 05/01/2003
A DESCRIPTION OF THE REQUEST :
I propose some changes in the String/StringBuffer - code:
1.) add a package local method to the String-class
void getChars( char dst[], int dstBegin ) {
System.arrayCopy( value, offset, dst, dstBegin, count );
}
2.) check and change the StringBuffer-class to replace calls
str.getChars( 0, len, value, count )
to
str.getChars( value, count )
there are some of these calls, most of them can be changed.
I think, this '0' in the parameter-list is one of the most often
redundantly passed and best checked 0's in the java-world.
This few superflous statements are a bigger part of the
fixed cost of string-buffer appending, besides growing the buffer
and the actual copying.
JUSTIFICATION :
Yes, maybe a smart Hotspot VM can inline away some of the old
getChars()-code, but still the modified code is faster than before.
And all not so smart JVM's will benefit too - and older JDK's should also...
When saving cpu-cycles is so central and so simple, it should be done.
PS: It would be easy to set up a simple benchmark which proves
'StringBuffer-appending speed-up by 50%'
EXPECTED VERSUS ACTUAL BEHAVIOR :
some speed-up of StringBuffer.append( string )
more noticable effect for shorter strings
(Review ID: 185141)
======================================================================
- duplicates
-
JDK-4822325 Remove String/StringBuffer sharing
-
- Resolved
-