[jdom-commits] CVS update: jdom/src/java/org/jdom/input

cvs at jools.org cvs at jools.org
Mon Jan 28 21:21:11 PST 2002

Date:	Tuesday January 29, 2002 @ 0:21
Author:	cvs

Update of /home/cvspublic/jdom/src/java/org/jdom/input
In directory jools.org:/tmp/cvs-serv31035

Modified Files:
Log Message:
Patch to improve the performance of SAXHandler.  It was created by 
Brad Huffman following the suggestion of Phil AT triloggroup.com.

Here's the email from Phil:

I saw that you integrated the new SAXHandler but also change the way 
StringBuffer is used. In fact, in order to save memory, we should not 
use textBuffer.toString(). Because character arrays are shared between 
String and StringBuffer, you will loose memory because all the entire 
array  won't be used in many cases. Moreover, when your dealing with big
amount of text , it will reallocate the buffer several times. The 
solution I found for that is to use a unique StringBuffer, that is 
first allocated with a quite big amount of characters (textBuffer 
= new StringBuffer(4096)). Then, when you want to get the String from 
that buffer, use the substring() extractor (String 
result=textBuffer.substring(0)).  Using that statement, the String class 
allocates a new and well sized array of characters, and do not share the 
one already used by the StringBuffer. And the setLength() method just 
reset the counter, leaving the array as is.  I think this is the most 
optimized way to implement the StringBuffer.

Note, Brad, I changed 

textBuffer.substring(0, textBuffer.length());



Because it's the same effect with one less method call.

I didn't profile the change.  Perhaps someone wants to.


File: no file SAXHandler.java		Status: Needs Checkout

   Working revision:	1.32	Tue Jan 29 05:21:11 2002
   Repository revision:	1.32	/home/cvspublic/jdom/src/java/org/jdom/input/SAXHandler.java,v

   Existing Tags:
	jdom_prefilter           	(revision: 1.27)
	jdom_1_0_b7              	(revision: 1.18)

More information about the jdom-commits mailing list