1 11 package org.eclipse.core.internal.resources; 12 13 import java.util.*; 14 15 24 class MarkerDeltaManager { 25 private static final int DEFAULT_SIZE = 10; 26 private long[] startIds = new long[DEFAULT_SIZE]; 27 private Map[] batches = new Map[DEFAULT_SIZE]; 28 private int nextFree = 0; 29 30 34 protected Map assembleDeltas(long start) { 35 Map result = null; 36 for (int i = 0; i < nextFree; i++) 37 if (startIds[i] >= start) 38 result = MarkerDelta.merge(result, batches[i]); 39 return result; 40 } 41 42 45 protected void resetDeltas(long startId) { 46 int startOffset = 0; 48 for (; startOffset < nextFree; startOffset++) 49 if (startIds[startOffset] >= startId) 50 break; 51 if (startOffset == 0) 52 return; 53 long[] newIds = startIds; 54 Map[] newBatches = batches; 55 if (startIds.length > DEFAULT_SIZE && (nextFree - startOffset < DEFAULT_SIZE)) { 57 newIds = new long[DEFAULT_SIZE]; 58 newBatches = new Map[DEFAULT_SIZE]; 59 } 60 int remaining = nextFree - startOffset; 62 System.arraycopy(startIds, startOffset, newIds, 0, remaining); 63 System.arraycopy(batches, startOffset, newBatches, 0, remaining); 64 Arrays.fill(startIds, remaining, startIds.length, 0); 66 Arrays.fill(batches, remaining, startIds.length, null); 67 startIds = newIds; 68 batches = newBatches; 69 nextFree = remaining; 70 } 71 72 protected Map newGeneration(long start) { 73 int len = startIds.length; 74 if (nextFree >= len) { 75 long[] newIds = new long[len * 2]; 76 Map[] newBatches = new Map[len * 2]; 77 System.arraycopy(startIds, 0, newIds, 0, len); 78 System.arraycopy(batches, 0, newBatches, 0, len); 79 startIds = newIds; 80 batches = newBatches; 81 } 82 startIds[nextFree] = start; 83 batches[nextFree] = new HashMap(11); 84 return batches[nextFree++]; 85 } 86 } 87 | Popular Tags |