You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@pivot.apache.org by tv...@apache.org on 2009/03/15 00:44:10 UTC
svn commit: r754557 - /incubator/pivot/trunk/wtk/src/pivot/wtk/TreeView.java
Author: tvolkert
Date: Sat Mar 14 23:44:10 2009
New Revision: 754557
URL: http://svn.apache.org/viewvc?rev=754557&view=rev
Log:
Improved implementatin of TreeView$BranchHandler#clearAndDecrementPaths()
Modified:
incubator/pivot/trunk/wtk/src/pivot/wtk/TreeView.java
Modified: incubator/pivot/trunk/wtk/src/pivot/wtk/TreeView.java
URL: http://svn.apache.org/viewvc/incubator/pivot/trunk/wtk/src/pivot/wtk/TreeView.java?rev=754557&r1=754556&r2=754557&view=diff
==============================================================================
--- incubator/pivot/trunk/wtk/src/pivot/wtk/TreeView.java (original)
+++ incubator/pivot/trunk/wtk/src/pivot/wtk/TreeView.java Sat Mar 14 23:44:10 2009
@@ -557,52 +557,26 @@
Sequence<Integer> basePath, int index, int count) {
int depth = basePath.getLength();
- // Calculate the first removed child's path
- Sequence<Integer> childPath = new ArrayList<Integer>(basePath);
- childPath.add(index);
+ // Find the index of the first path to clear (inclusive)
+ Sequence<Integer> testPath = new ArrayList<Integer>(basePath);
+ testPath.add(index);
- // Find the first removed child's place in our sorted paths sequence
- int start = Sequence.Search.binarySearch(paths, childPath, PATH_COMPARATOR);
+ int start = Sequence.Search.binarySearch(paths, testPath, PATH_COMPARATOR);
if (start < 0) {
start = -(start + 1);
}
- int end = start;
-
- // See if our start index points to a path that needs to be cleared
- if (start < paths.getLength()) {
- Sequence<Integer> testPath = paths.get(start);
- int testIndex = (depth < testPath.getLength() ? testPath.get(depth) : -1);
-
- if (testIndex >= index
- && testIndex < index + count
- && Sequence.Tree.isDescendant(basePath, testPath)) {
- // Confirmed: we will need to clear at least one path
- childPath.remove(depth, 1);
- childPath.add(index + count - 1);
-
- end = Sequence.Search.binarySearch(paths, childPath, PATH_COMPARATOR);
- if (end < 0) {
- end = -(end + 1);
- }
-
- assert (end >= start) : "end < start";
+ // Find the index of the last path to clear (exclusive)
+ testPath.update(depth, index + count);
- // Scan forward to find the index of the last path to clear
- for (int n = paths.getLength(); end < n; end++) {
- testPath = paths.get(end);
- testIndex = (depth < testPath.getLength() ? testPath.get(depth) : -1);
-
- if (!(testIndex >= index
- && testIndex < index + count
- && Sequence.Tree.isDescendant(basePath, testPath))) {
- break;
- }
- }
+ int end = Sequence.Search.binarySearch(paths, testPath, PATH_COMPARATOR);
+ if (end < 0) {
+ end = -(end + 1);
+ }
- // Clear all paths within [start, end>
- paths.remove(start, end - start);
- }
+ // Clear affected paths
+ if (end > start) {
+ paths.remove(start, end - start);
}
// Decrement paths as necessary