cocoon-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Berin Loritsch <>
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

    new StringBuffer(
        new StringBuffer(
            new StringBuffer(
                new StringBuffer("<").append(prefix).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:


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:
For additional commands, email:

View raw message