cocoon-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Berin Loritsch <blorit...@apache.org>
Subject StringBuffers and String Concatenation
Date Thu, 25 Oct 2001 19:02:19 GMT
Friends, going through the source code looking for
places to optimize the critical path (i.e. the path
taken when no error or log message is performed),
I went through adding StringBuffers where there were
three or more strings to concatenate.

I found an enigma.

In several places, where the code was already using
a StringBuffer, I found code snippets like this:

buffer.append("<" + prefix + ":" + name + "/>");

This gets expanded into the much more complex code as
follows:

buffer.append(
    new StringBuffer(
        new StringBuffer(
            new StringBuffer(
                new StringBuffer("<").append(prefix).toString()
            ).append(":").toString()
        ).append(name).toString()
    ).append("/>").toString()
);

That means four additional StringBuffers were created
behind the scenes.  This is ludicrous when we are already
using StringBuffers--and wasteful of resources.

Instead, please write the code to explicitly take advantage
of the StringBuffer when it is available:

buffer.append("<").append(prefix).append(":").append(name).append("/>");

This is more respectful of the environment, and is much quicker
to execute on any JVM.

Please, be mindful in the future.

---------------------------------------------------------------------
To unsubscribe, e-mail: cocoon-dev-unsubscribe@xml.apache.org
For additional commands, email: cocoon-dev-help@xml.apache.org


Mime
View raw message