Jody Garnett ha scritto:
> Hi Andrea:
>
> StringBuilder is supposed to be slightly faster (and non threadsafe);
> but it is murder on readability.
Slightly faster than StringBuffer, but if you look the bytecode below
you'll see normal string concatenation already uses it.
So there is no difference between using StringBuilder and direct
concatenation.
> I used a java 5 trick in some GeoTools code that I am starting to be
> very fond of. Using the Object... param syntax to hide the
> concatenation.
>
> If we were add such a method to LOGGER the the example would be:
>
> LOGGER.fine( "Got empty intersection for granule ", this, " with
> request ", request );
Mind this is creating an Object[] in memory every time it's called,
so it's not zero cost.
However it avoids the concatenation if the current logging level
is below the FINE threshold, so it's a good way to avoid the
if(Logger.isLoggable(...)) for non tight loops.
For tight loops array creation will kill you anyways, I think
Gabriel had a horror story about using varargs in his binary
gml encoder and getting a solid and non obvious slowdown
Cheers
Andrea
>> Compiled from "Concatenate.java" public class Concatenate extends
>> java.lang.Object{ public Concatenate(); Code: 0: aload_0 1:
>> invokespecial #8; //Method java/lang/Object."<init>":()V 4: return
>>
>> public static void main(java.lang.String[]); Code: 0: new #16;
>> //class java/lang/StringBuilder 3: dup 4: ldc #18; //String abc 6:
>> invokespecial #20; //Method
>> java/lang/StringBuilder."<init>":(Ljava/lang/String;)V 9:
>> invokestatic #23; //Method java/lang/Math.random:()D 12:
>> invokevirtual #29; //Method
>> java/lang/StringBuilder.append:(D)Ljava/lang/StringBuilder; 15: ldc
>> #33; //String def 17: invokevirtual #35; //Method
>> java/lang/StringBuilder.append:(Ljava/lang/String;)Ljava/lang/StringBuilder;
>> 20: invokevirtual #38; //Method
>> java/lang/StringBuilder.toString:()Ljava/lang/String; 23: astore_1
>> 24: new #16; //class java/lang/StringBuilder 27: dup 28: ldc
>> #42;
>> //String abc 30: invokespecial #20; //Method
>> java/lang/StringBuilder."<init>":(Ljava/lang/String;)V 33:
>> invokestatic #23; //Method java/lang/Math.random:()D 36:
>> invokevirtual #29; //Method
>> java/lang/StringBuilder.append:(D)Ljava/lang/StringBuilder; 39: ldc
>> #44; //String def 41: invokevirtual #35; //Method
>> java/lang/StringBuilder.append:(Ljava/lang/String;)Ljava/lang/StringBuilder;
>> 44: invokevirtual #38; //Method
>> java/lang/StringBuilder.toString:()Ljava/lang/String; 47: astore_2
>> 48: return
--
Andrea Aime
OpenGeo - http://opengeo.org
Expert service straight from the developers.
------------------------------------------------------------------------------
This SF.net email is sponsored by Sprint
What will you do first with EVO, the first 4G phone?
Visit sprint.com/first -- http://p.sf.net/sfu/sprint-com-first
_______________________________________________
Geotools-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/geotools-devel