private void EnsureRowIndexListCurrent() { int rebuildIndex = rowListRebuild; int journalCount = EventRegistry.EventCount; while (rebuildIndex < journalCount) { var command = EventRegistry.GetEvent(rebuildIndex); if (command is TableRowEvent) { var rowEvent = (TableRowEvent)command; var index = rowEvent.RowNumber; if (rowEvent.EventType == TableRowEventType.Add || rowEvent.EventType == TableRowEventType.UpdateAdd) { // Add to 'row_list'. if (!RowIndex.UniqueInsertSort(index)) { throw new InvalidOperationException(String.Format("Row index already used in this table ({0})", index)); } } else if (rowEvent.EventType == TableRowEventType.Remove || rowEvent.EventType == TableRowEventType.UpdateRemove) { // Remove from 'row_list' if (!RowIndex.RemoveSort(index)) { throw new InvalidOperationException("Row index removed that wasn't in this table!"); } } else { throw new InvalidOperationException(String.Format("Table row event type {0} is invalid.", rowEvent.EventType)); } } ++rebuildIndex; } // It's now current (row_list_rebuild == journal_count); rowListRebuild = rebuildIndex; }