private List<ObjectToPack> sortByName() { if (sortedByName == null) { int cnt = 0; cnt += objectsLists[OBJ_COMMIT].size(); cnt += objectsLists[OBJ_TREE].size(); cnt += objectsLists[OBJ_BLOB].size(); cnt += objectsLists[OBJ_TAG].size(); sortedByName = new BlockList<>(cnt); sortedByName.addAll(objectsLists[OBJ_COMMIT]); sortedByName.addAll(objectsLists[OBJ_TREE]); sortedByName.addAll(objectsLists[OBJ_BLOB]); sortedByName.addAll(objectsLists[OBJ_TAG]); Collections.sort(sortedByName); } return sortedByName; }
/** * Quickly append all elements from an array. * * @param src * the source array. * @param srcIdx * first index to copy. * @param srcCnt * number of elements to copy. */ public void addAll(T[] src, int srcIdx, int srcCnt) { while (0 < srcCnt) { int i = tailBlkIdx; int n = Math.min(srcCnt, BLOCK_SIZE - i); if (n == 0) { // Our tail is full, expand by one. add(src[srcIdx++]); srcCnt--; continue; } System.arraycopy(src, srcIdx, tailBlock, i, n); tailBlkIdx += n; size += n; srcIdx += n; srcCnt -= n; } }
private void searchForReuse(ProgressMonitor monitor) throws IOException { long cnt = 0; cnt += objectsLists[OBJ_COMMIT].size(); cnt += objectsLists[OBJ_TREE].size(); cnt += objectsLists[OBJ_BLOB].size(); cnt += objectsLists[OBJ_TAG].size(); if (cnt <= 4096) { BlockList<ObjectToPack> tmp = new BlockList<>((int) cnt); tmp.addAll(objectsLists[OBJ_TAG]); tmp.addAll(objectsLists[OBJ_COMMIT]); tmp.addAll(objectsLists[OBJ_TREE]); tmp.addAll(objectsLists[OBJ_BLOB]); searchForReuse(monitor, tmp); if (pruneCurrentObjectList) {
/** * Initialize an empty list. */ public BlockList() { directory = BlockList.<T> newDirectory(256); directory[0] = BlockList.<T> newBlock(); tailBlock = directory[0]; }
/** * Initialize an empty list with an expected capacity. * * @param capacity * number of elements expected to be in the list. */ public BlockList(int capacity) { int dirSize = toDirectoryIndex(capacity); if ((capacity & BLOCK_MASK) != 0 || dirSize == 0) dirSize++; directory = BlockList.<T> newDirectory(dirSize); directory[0] = BlockList.<T> newBlock(); tailBlock = directory[0]; }
/** {@inheritDoc} */ @Override public void add(int index, T element) { if (index == size) { // Fast-path: append onto the end of the list. add(element); } else if (index < 0 || size < index) { throw new IndexOutOfBoundsException(String.valueOf(index)); } else { // Slow-path: the list needs to expand and insert. // Do this the naive way, callers shouldn't abuse // this class by entering this code path. // add(null); // expand the list by one for (int oldIdx = size - 2; index <= oldIdx; oldIdx--) set(oldIdx + 1, get(oldIdx)); set(index, element); } }
if (index == size - 1) { T[] blockRef = directory[toDirectoryIndex(index)]; int blockIdx = toBlockIndex(index); T old = blockRef[blockIdx]; blockRef[blockIdx] = null; tailBlkIdx--; else resetTailBlock(); return old; T old = get(index); for (; index < size - 1; index++) set(index, get(index + 1)); set(size - 1, null); size--; resetTailBlock(); return old;
BlockList<BitmapCommit> selections = new BlockList<>( selectionHelper.reusedCommits.size() + newCommits / recentCommitSpan + 1); for (BitmapCommit reuse : selectionHelper.reusedCommits) { selections.add(reuse); selections.add(new BitmapCommit(id, false, 0)); selections.addAll(chain); selections.add(new BitmapCommit(remainingWant, false, 0));
private void beginPack() throws IOException { objectList = new BlockList<>(); objectMap = new ObjectIdOwnerMap<>(); rollback = true; tmpPack = File.createTempFile("insert_", ".pack", db.getDirectory()); //$NON-NLS-1$ //$NON-NLS-2$ packOut = new PackStream(tmpPack); // Write the header as though it were a single object pack. packOut.write(packOut.hdrBuf, 0, writePackHeader(packOut.hdrBuf, 1)); }
private void cutDeltaChains(BlockList<ObjectToPack> list) throws IOException { int max = config.getMaxDeltaDepth(); for (int idx = list.size() - 1; idx >= 0; idx--) { int d = 0; ObjectToPack b = list.get(idx).getDeltaBase(); while (b != null) { if (d < b.getChainLength()) break; b.setChainLength(++d); if (d >= max && b.isDeltaRepresentation()) { reselectNonDelta(b); break; } b = b.getDeltaBase(); } } if (config.isDeltaCompress()) { for (ObjectToPack otp : list) otp.clearChainLength(); } }
/** {@inheritDoc} */ @Override public ObjectId getObject(int position) throws IllegalArgumentException { ObjectId objectId = byOffset.get(position); if (objectId == null) throw new IllegalArgumentException(); return objectId; }
/** * Remove all the bitmaps entries added. */ public void clearBitmaps() { byAddOrder.clear(); getBitmaps().clear(); }
/** * Quickly append all elements of another BlockList. * * @param src * the list to copy elements from. */ public void addAll(BlockList<T> src) { if (src.size == 0) return; int srcDirIdx = 0; for (; srcDirIdx < src.tailDirIdx; srcDirIdx++) addAll(src.directory[srcDirIdx], 0, BLOCK_SIZE); if (src.tailBlkIdx != 0) addAll(src.tailBlock, 0, src.tailBlkIdx); }
@Override public T remove(int index) { if (index == size - 1) { // Fast-path: remove the last element. T[] blockRef = directory[toDirectoryIndex(index)]; int blockIdx = toBlockIndex(index); T old = blockRef[blockIdx]; blockRef[blockIdx] = null; size--; if (0 < tailBlkIdx) tailBlkIdx--; else resetTailBlock(); return old; } else if (index < 0 || size <= index) { throw new IndexOutOfBoundsException(String.valueOf(index)); } else { // Slow-path: the list needs to contract and remove. // Do this the naive way, callers shouldn't abuse // this class by entering this code path. // T old = get(index); for (; index < size - 1; index++) set(index, get(index + 1)); set(size - 1, null); size--; resetTailBlock(); return old; } }
BlockList<BitmapCommit> selections = new BlockList<BitmapCommit>( totCommits / recentCommitSpan + 1); for (BitmapCommit reuse : selectionHelper.reusedCommits) { selections.add(reuse); selections.add(new BitmapCommit(id, false, 0)); selections.addAll(chain); selections.add(new BitmapCommit(remainingWant, false, 0));
@Override public void add(int index, T element) { if (index == size) { // Fast-path: append onto the end of the list. add(element); } else if (index < 0 || size < index) { throw new IndexOutOfBoundsException(String.valueOf(index)); } else { // Slow-path: the list needs to expand and insert. // Do this the naive way, callers shouldn't abuse // this class by entering this code path. // add(null); // expand the list by one for (int oldIdx = size - 2; index <= oldIdx; oldIdx--) set(oldIdx + 1, get(oldIdx)); set(index, element); } }