Index: javax/swing/text/GapContent.java =================================================================== RCS file: /cvsroot/classpath/classpath/javax/swing/text/GapContent.java,v retrieving revision 1.24 diff -u -r1.24 GapContent.java --- javax/swing/text/GapContent.java 7 Sep 2005 18:07:57 -0000 1.24 +++ javax/swing/text/GapContent.java 8 Sep 2005 09:51:37 -0000 @@ -39,8 +39,8 @@ package javax.swing.text; import java.io.Serializable; +import java.util.ArrayList; import java.util.Collections; -import java.util.LinkedList; import java.util.ListIterator; import javax.swing.undo.UndoableEdit; @@ -59,7 +59,6 @@ public class GapContent implements AbstractDocument.Content, Serializable { - /** * A address@hidden Position} implementation for GapContent. */ @@ -114,14 +113,18 @@ */ public int getOffset() { - if (mark <= gapEnd) + // Check precondition. + assert(mark <= gapStart || mark > gapEnd); + + if (mark <= gapStart) return mark; else return mark - (gapEnd - gapStart); } } - private static final long serialVersionUID = 8374645204155842629L; + /** The serialization UID (compatible with JDK1.5). */ + private static final long serialVersionUID = -6226052713477823730L; /** * This is the default buffer size and the amount of bytes that a buffer is @@ -148,7 +151,7 @@ * The positions generated by this GapContent. They are kept in an ordered * fashion, so they can be looked up easily. */ - LinkedList positions; + ArrayList positions; /** * Creates a new GapContent object. @@ -169,7 +172,7 @@ gapStart = 0; gapEnd = size - 1; buffer[size - 1] = '\n'; - positions = new LinkedList(); + positions = new ArrayList(); } /** @@ -415,6 +418,9 @@ */ protected void shiftGap(int newGapStart) { + if (newGapStart == gapStart) + return; + int newGapEnd = newGapStart + (gapEnd - gapStart); // Update the positions between newGapEnd and (old) gapEnd. The marks @@ -437,9 +443,7 @@ } } - if (newGapStart == gapStart) - return; - else if (newGapStart < gapStart) + if (newGapStart < gapStart) { System.arraycopy(buffer, newGapStart, buffer, newGapEnd, gapStart - newGapStart);