X-Git-Url: http://source.jalview.org/gitweb/?a=blobdiff_plain;f=src%2Fjalview%2Fdatamodel%2FHiddenColumns.java;h=3b1a574d1bf15cb27f93556fad72c435d3427278;hb=4d3cf3e91660d6b1c5bcdee4bef34c2747ac7023;hp=fa5d0a001012c6b29ad2da089fc1ae6a187f1f15;hpb=caa89ac856d432b159653d92d2f6fbb001dc42d6;p=jalview.git diff --git a/src/jalview/datamodel/HiddenColumns.java b/src/jalview/datamodel/HiddenColumns.java index fa5d0a0..3b1a574 100644 --- a/src/jalview/datamodel/HiddenColumns.java +++ b/src/jalview/datamodel/HiddenColumns.java @@ -188,10 +188,28 @@ public class HiddenColumns wasAlreadyLocked = true; } + int previndex = 0; + int prevHiddenCount = 0; + int regionindex = 0; if (hiddenColumns == null) { hiddenColumns = new ArrayList<>(); } + else + { + // set up cursor reset values + HiddenCursorPosition cursorPos = cursor.findRegionForColumn(start); + regionindex = cursorPos.getRegionIndex(); + + if (regionindex > 0) + { + // get previous index and hidden count for updating the cursor later + previndex = regionindex - 1; + int[] prevRegion = hiddenColumns.get(previndex); + prevHiddenCount = cursorPos.getHiddenSoFar() + - (prevRegion[1] - prevRegion[0] + 1); + } + } /* * new range follows everything else; check first to avoid looping over whole hiddenColumns collection @@ -208,18 +226,23 @@ public class HiddenColumns * appropriate */ boolean added = false; - for (int i = 0; !added && i < hiddenColumns.size(); i++) + if (regionindex > 0) + { + added = insertRangeAtRegion(regionindex - 1, start, end); + } + if (!added && regionindex < hiddenColumns.size()) { - added = insertRangeAtRegion(i, start, end); - } // for + insertRangeAtRegion(regionindex, start, end); + } } - if (!wasAlreadyLocked) - { - cursor.resetCursor(hiddenColumns); - // reset the number of columns so they will be recounted - numColumns = 0; - } + // reset the cursor to just before our insertion point: this saves + // a lot of reprocessing in large alignments + cursor.resetCursor(hiddenColumns, previndex, prevHiddenCount); + + // reset the number of columns so they will be recounted + numColumns = 0; + } finally { if (!wasAlreadyLocked) @@ -287,6 +310,9 @@ public class HiddenColumns break; } region[1] = Math.max(nextRegion[1], end); + + // in theory this is faster than hiddenColumns.remove(i+1) + // benchmarking results a bit ambivalent hiddenColumns.subList(i + 1, i + 2).clear(); } added = true;