The only way these methods could be slow is by the getter methods of ExtensionInfoRec or CustomizeRecItem being slow. BTW, using StringBuffer doesn't buy you anything here. Using String would be as fast and improve readability. Why do you think you need to improve performance of these methods?
The soul is dyed the color of its thoughts. Think only on those things that are in line with your principles and can bear the light of day. The content of your character is your choice. Day by day, what you do is who you become. Your integrity is your destiny - it is the light that guides your way. - Heraclitus
Joined: Jul 24, 2002
But if the method was invoked 3862 times with every operation , Doesn't StringBuffer help here?? Thanks very much!
Joined: Jul 11, 2001
Originally posted by Javan Li: But if the method was invoked 3862 times with every operation , Doesn't StringBuffer help here?? Thanks very much!
strAliasName.append("REP_PRO").append("_").append(extInfo.getColName()); But use String instead of above , doesn't it create 3862*3 Strings here ?? [ July 02, 2003: Message edited by: Javan Li ]
Joined: Jul 11, 2001
No - the typical Java compiler uses a single StringBuffer for all String concatenations in an expression. For example "REP_PRO" + "_" + extInfo.getColName() would be *identical* to new StringBuffer().append("REP_PRO").append("_").append(String.valueOf(extInfo.getColName)).toString()
Originally posted by James Fisk: static final String onlyCreatedOnce= "REP_PRO_";
String newString = onlyCreatedOnce + (new stuff)
Doesn't buy you anything, too. As stated by the Java Language Specification, String literals are put into a pool and reused throughout the application. Try System.out.println("myString" == "myString"); You should get "true" as output, as both literals are resolved to the *same* String object in the constant pool. There is no instanciation overhead involved at all!
Joined: Jul 02, 2003
I was referring to having only one concatenation instead of TWO
I know about the String pool.. duh... JAVA 101 each concatenation creates a NEW STRING he had TWO concatenation operators in his expression.
Additionally, "REP_PRO" + "_" is a Compile Time Constant Expression and therefore evaluated at compile time, not at runtime - I missed that in my first post... So "REP_PRO" + "_" + extInfo.getColName() would in fact be identical to new StringBuffer().append("REP_PRO_").append(String.valueOf(extInfo.getColName)).toString() !!!
subject: Who can help me improve performance of these methods? thanks!