UpdatedRanges (@NotNull List<? extends DocumentEvent> events, @NotNull UpdatedRanges struct) { FrozenDocument frozen = struct.myResultDocument; ManualRangeMarker[] resultMarkers = struct.myMarkers.clone(); for (DocumentEvent event : events) { FrozenDocument before = frozen; frozen = frozen.applyEvent(event, 0); DocumentEvent corrected = new DocumentEventImpl(frozen, event.getOffset(), event.getOldFragment(), event.getNewFragment(), event.getOldTimeStamp(), event.isWholeTextReplaced(), ((DocumentEventImpl)event).getInitialStartOffset(), ((DocumentEventImpl)event).getInitialOldLength(), event.getMoveOffset()); int i = 0; while (i < resultMarkers.length) { ManualRangeMarker currentRange = resultMarkers[i]; int sameMarkersEnd = i + 1; while (sameMarkersEnd < resultMarkers.length && resultMarkers[sameMarkersEnd] == currentRange) { sameMarkersEnd++; } ManualRangeMarker updatedRange = currentRange == null ? null : currentRange.getUpdatedRange(corrected, before); while (i < sameMarkersEnd) { resultMarkers[i] = updatedRange; i++; } } } return new UpdatedRanges(struct.myEventCount + events.size(), frozen, struct.mySortedInfos, resultMarkers); }