Hi, the following patch should affect PlainDocument.insertUpdate memory performance in a positive way.
Before the change it contained this evil line: String str = content.getString(0, content.getLength()); which is now changed to: String str = content.getString(offset, eventLength); Without the patch the complete document was copied into a string on each and every keypress. That is a huge waste when the document is big. Now only the changed area is copied which often means a one-character-string (e.g. when typing). Apart from that I fixed the copyright header and authors. @Mark: It would be a nice to have patch for the upcomming release. 2006-03-06 Robert Schuster <[EMAIL PROTECTED]> * javax/swing/text/PlainDocument.java: Fix copyright header, added author tags. (insertUpdate): Do not copy the whole document any more, added some more variables to prevent needless method calls. cya Robert
Index: javax/swing/text/PlainDocument.java =================================================================== RCS file: /cvsroot/classpath/classpath/javax/swing/text/PlainDocument.java,v retrieving revision 1.20 diff -u -r1.20 PlainDocument.java --- javax/swing/text/PlainDocument.java 6 Mar 2006 01:16:13 -0000 1.20 +++ javax/swing/text/PlainDocument.java 6 Mar 2006 10:47:48 -0000 @@ -1,5 +1,5 @@ /* PlainDocument.java -- - Copyright (C) 2002, 2004 Free Software Foundation, Inc. + Copyright (C) 2002, 2004, 2006 Free Software Foundation, Inc. This file is part of GNU Classpath. @@ -40,6 +40,15 @@ import java.util.ArrayList; +/** + * A simple document class which maps lines to [EMAIL PROTECTED] Element}s. + * + * @author Anthony Balkissoon ([EMAIL PROTECTED]) + * @author Graydon Hoare ([EMAIL PROTECTED]) + * @author Roman Kennke ([EMAIL PROTECTED]) + * @author Michael Koch ([EMAIL PROTECTED]) + * @author Robert Schuster ([EMAIL PROTECTED]) + */ public class PlainDocument extends AbstractDocument { private static final long serialVersionUID = 4758290289196893664L; @@ -109,6 +118,7 @@ AttributeSet attributes) { int offset = event.getOffset(); + int eventLength = event.getLength(); int end = offset + event.getLength(); int oldElementIndex, elementIndex = rootElement.getElementIndex(offset); Element firstElement = rootElement.getElement(elementIndex); @@ -161,24 +171,25 @@ Element[] added; try { - String str = content.getString(0, content.length()); + String str = content.getString(offset, eventLength); ArrayList elts = new ArrayList(); // Determine how many NEW lines were added by finding the newline // characters within the newly inserted text int j = firstElement.getStartOffset(); - int i = str.indexOf('\n', offset); + int i = str.indexOf('\n', 0); + int contentLength = content.length(); - while (i != -1 && i <= end) + while (i != -1 && i <= eventLength) { // For each new line, create a new element elts.add(createLeafElement(rootElement, SimpleAttributeSet.EMPTY, - j, i + 1)); + j, offset + i + 1)); - j = i + 1; - if (j >= str.length()) + j = offset + i + 1; + if (j >= contentLength) break; - i = str.indexOf('\n', j); + i = str.indexOf('\n', i + 1); } // If there were new lines added we have to add an ElementEdit to
signature.asc
Description: OpenPGP digital signature