Talk About Network



Register and Login
Nick
Password
Register create new account Sign up is FREE and you can post replies, new topics, bookmark posts and more!
Recover lost password


Programming > Java Machine > Optimising Stri...
Latest [ Topics | Posts ] Archive Post A New Topic Post a Reply
<< Topic < Post Post 1 of 5 Topic 801 of 803
Post > Topic >>

Optimising StringBuilder

by Roedy Green <see_website@[EMAIL PROTECTED] > Apr 4, 2008 at 09:19 PM

I'm curious just how clever HotSpot is about optimising StringBuilder,

Here are some possible optimisations.

1. when allocating the StringBuilder, compute the length where
possible to create the exact size.

2. when doing append ( "xxx");
append ("yyy");
convert that to append( "xxxyyy");

3. when doing toString, if char[] internally is the correct length,
steal that array to use in the string, and lazily make a copy (which
should be rarely needed.)

4. convert append ( " " ) to append ( ' ' );

5 convert  append ( a + b + c ) to append (a ); append (b); append
(c);

If it is not clever, then consider how you might implement these with
a BYTE CODE optimiser.
-- 

Roedy Green Canadian Mind Products
The Java Glossary
http://mindprod.com




 5 Posts in Topic:
Optimising StringBuilder
Roedy Green <see_websi  2008-04-04 21:19:34 
Re: Optimising StringBuilder
Roedy Green <see_websi  2008-04-04 22:14:42 
Re: Optimising StringBuilder
"Boudewijn Dijkstra&  2008-04-19 00:05:37 
Re: Optimising StringBuilder
Roedy Green <see_websi  2008-04-20 10:44:22 
Re: Optimising StringBuilder
"Boudewijn Dijkstra&  2008-04-20 13:57:38 

Post A Reply:
  Go here to Signup

AddThis Feed Button


About - Advertising - Contact - Frequently Asked Questions - Privacy Policy - Terms of Use - Signup

Contact
tan12V112 Thu May 15 0:05:43 CDT 2008.