aboutsummaryrefslogtreecommitdiffstats
path: root/org.eclipse.jgit/src/org/eclipse/jgit/util
diff options
context:
space:
mode:
authorShawn O. Pearce <spearce@spearce.org>2011-03-18 09:07:25 -0700
committerShawn O. Pearce <spearce@spearce.org>2011-03-18 09:11:56 -0700
commit62fe7c7313e4e7a4339fe9df3a9dc2335461df29 (patch)
tree5c38b105842c4675351f8e98fa4631ae1c93fcda /org.eclipse.jgit/src/org/eclipse/jgit/util
parent48fb404a3f155805a67bdc18c7ca22d18df03be2 (diff)
downloadjgit-62fe7c7313e4e7a4339fe9df3a9dc2335461df29.tar.gz
jgit-62fe7c7313e4e7a4339fe9df3a9dc2335461df29.zip
BlockList: Micro-optimize appending from another BlockList
Simple variant of addAll() that knows how to copy large segments quickly using System.arraycopy() rather than looping through with an Iterator object. Change-Id: Icb50a8f87fe9180ea28b6920f473bb9e70c300f1 Signed-off-by: Shawn O. Pearce <spearce@spearce.org>
Diffstat (limited to 'org.eclipse.jgit/src/org/eclipse/jgit/util')
-rw-r--r--org.eclipse.jgit/src/org/eclipse/jgit/util/BlockList.java46
1 files changed, 46 insertions, 0 deletions
diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/util/BlockList.java b/org.eclipse.jgit/src/org/eclipse/jgit/util/BlockList.java
index ac29771d80..50715acb2c 100644
--- a/org.eclipse.jgit/src/org/eclipse/jgit/util/BlockList.java
+++ b/org.eclipse.jgit/src/org/eclipse/jgit/util/BlockList.java
@@ -141,6 +141,52 @@ public class BlockList<T> extends AbstractList<T> {
return old;
}
+ /**
+ * 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);
+ }
+
+ /**
+ * 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;
+ }
+ }
+
@Override
public boolean add(T element) {
int i = tailBlkIdx;