static L lineComp_replacePairWithUpdatingPairCount(IContentsIndexedList2 l, IntPair p, L y, LineComp_PairCounts pairCounts) { int i = 0; Int pa = p.a, pb = p.b; // box them once while (true) { i = indexOfIntPairInContentsIndexedList(l, pa, pb, i); if (i < 0) break; int to = i+l(x), to_new = i+l(y); ifdef lineComp_replaceSublistWithUpdatingPairCount_debug print("Replacing " + subList(l, i, to) + " at " + i); endifdef pairCounts.removeAll(overlappingIntPairs(subList(l, i-1, to+1))); replaceSublist(l, i, to, y); pairCounts.addAll(overlappingIntPairs(subList(l, i-1, to_new+1))); i = to_new; } ret l; }