Return-Path: Delivered-To: apmail-xml-cocoon-dev-archive@xml.apache.org Received: (qmail 30775 invoked by uid 500); 25 Oct 2001 19:01:36 -0000 Mailing-List: contact cocoon-dev-help@xml.apache.org; run by ezmlm Precedence: bulk list-help: list-unsubscribe: list-post: Reply-To: cocoon-dev@xml.apache.org Delivered-To: mailing list cocoon-dev@xml.apache.org Received: (qmail 30758 invoked from network); 25 Oct 2001 19:01:36 -0000 Message-ID: <3BD861BB.E99E5EEE@apache.org> Date: Thu, 25 Oct 2001 15:02:19 -0400 From: Berin Loritsch X-Mailer: Mozilla 4.75 [en] (Windows NT 5.0; U) X-Accept-Language: en MIME-Version: 1.0 To: "cocoon-dev@xml.apache.org" Subject: StringBuffers and String Concatenation Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit X-Spam-Rating: daedalus.apache.org 1.6.2 0/1000/N 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