summaryrefslogtreecommitdiff
path: root/javax
diff options
context:
space:
mode:
authorRoman Kennke <roman@kennke.org>2006-11-25 20:31:08 +0000
committerRoman Kennke <roman@kennke.org>2006-11-25 20:31:08 +0000
commitc63e4bad2a93744fd6c6cb5966c20b2ce544bc4b (patch)
treebb35ddebb59a023be015abd6e0d5664fae872932 /javax
parent150c84b7c5588c2085a7463af3c48ac3dbbdd5fa (diff)
downloadclasspath-c63e4bad2a93744fd6c6cb5966c20b2ce544bc4b.tar.gz
2006-11-25 Roman Kennke <kennke@aicas.com>
* javax/swing/text/GapContent.java (getPositionsInRange): Rewritten to use the more efficient binary search searchFirst() and avoid an NPE that was caused by GC'ed positions.
Diffstat (limited to 'javax')
-rw-r--r--javax/swing/text/GapContent.java39
1 files changed, 24 insertions, 15 deletions
diff --git a/javax/swing/text/GapContent.java b/javax/swing/text/GapContent.java
index b3f515050..08a318d8b 100644
--- a/javax/swing/text/GapContent.java
+++ b/javax/swing/text/GapContent.java
@@ -888,22 +888,32 @@ public class GapContent
*/
protected Vector getPositionsInRange(Vector v, int offset, int length)
{
- Vector res = v;
- if (res == null)
- res = new Vector();
-
- int endOffs = offset + length;
-
- for (Iterator i = marks.iterator(); i.hasNext();)
+ int end = offset + length;
+ int startIndex;
+ int endIndex;
+ if (offset < gapStart)
{
- Mark m = (Mark) i.next();
- GapContentPosition p = m.getPosition();
- int offs = p.getOffset();
- if (offs >= offset && offs <= endOffs)
- res.add(new UndoPosRef(p.mark));
+ if (offset == 0)
+ startIndex = 0;
+ else
+ startIndex = searchFirst(offset);
+ if (end >= gapStart)
+ endIndex = searchFirst(end + (gapEnd - gapStart) + 1);
+ else
+ endIndex = searchFirst(end + 1);
}
-
- return res;
+ else
+ {
+ startIndex = searchFirst(offset + (gapEnd - gapStart));
+ endIndex = searchFirst(end + (gapEnd - gapStart) + 1);
+ }
+ if (v == null)
+ v = new Vector();
+ for (int i = startIndex; i < endIndex; i++)
+ {
+ v.add(new UndoPosRef((Mark) marks.get(i)));
+ }
+ return v;
}
/**
@@ -993,7 +1003,6 @@ public class GapContent
* list. The meaning of the return value is the same as in
* <code>Collections.binarySearch()</code>.
*
- * @param l the list to search through
* @param o the object to be searched
*
* @return the index of the first occurance of o in l, or -i + 1 if not found