diff options
author | Shawn Pearce <sop@google.com> | 2013-02-25 11:50:21 -0500 |
---|---|---|
committer | Gerrit Code Review @ Eclipse.org <gerrit@eclipse.org> | 2013-02-25 11:50:21 -0500 |
commit | 9613b04d8143c74e729acda414e6392078297d33 (patch) | |
tree | 86bad6992e999f8ed8f10a9147f77f53ee52f71c | |
parent | 912e19a8d6e95c1ceec5eaa5facd65559ac0d6bd (diff) | |
parent | 84afea9179932995d1e59f8fda4e6b11217382ad (diff) | |
download | jgit-9613b04d8143c74e729acda414e6392078297d33.tar.gz jgit-9613b04d8143c74e729acda414e6392078297d33.zip |
Merge "Performance fixes in DateRevQueue"
-rw-r--r-- | org.eclipse.jgit/src/org/eclipse/jgit/revwalk/DateRevQueue.java | 64 |
1 files changed, 62 insertions, 2 deletions
diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/revwalk/DateRevQueue.java b/org.eclipse.jgit/src/org/eclipse/jgit/revwalk/DateRevQueue.java index 35460a7c41..2c46f8eb47 100644 --- a/org.eclipse.jgit/src/org/eclipse/jgit/revwalk/DateRevQueue.java +++ b/org.eclipse.jgit/src/org/eclipse/jgit/revwalk/DateRevQueue.java @@ -1,5 +1,6 @@ /* - * Copyright (C) 2008, Shawn O. Pearce <spearce@spearce.org> + * Copyright (C) 2008, Shawn O. Pearce <spearce@spearce.org>, + * Copyright (C) 2013, Gustaf Lundh <gustaf.lundh@sonymobile.com> * and other copyright owners as documented in the project's IP log. * * This program and the accompanying materials are made available @@ -50,10 +51,22 @@ import org.eclipse.jgit.errors.MissingObjectException; /** A queue of commits sorted by commit time order. */ public class DateRevQueue extends AbstractRevQueue { + private static final int REBUILD_INDEX_COUNT = 1000; + private Entry head; private Entry free; + private int inQueue; + + private int sinceLastIndex; + + private Entry[] index; + + private int first; + + private int last = -1; + /** Create an empty date queue. */ public DateRevQueue() { super(); @@ -70,10 +83,36 @@ public class DateRevQueue extends AbstractRevQueue { } public void add(final RevCommit c) { + sinceLastIndex++; + if (++inQueue > REBUILD_INDEX_COUNT + && sinceLastIndex > REBUILD_INDEX_COUNT) + buildIndex(); + Entry q = head; final long when = c.commitTime; + + if (first <= last && index[first].commit.commitTime > when) { + int low = first, high = last; + while (low <= high) { + int mid = (low + high) >>> 1; + int t = index[mid].commit.commitTime; + if (t < when) + high = mid - 1; + else if (t > when) + low = mid + 1; + else { + low = mid - 1; + break; + } + } + low = Math.min(low, high); + while (low >= first && when == index[low].commit.commitTime) + --low; + q = index[low]; + } + final Entry n = newEntry(c); - if (q == null || when > q.commit.commitTime) { + if (q == null || (q == head && when > q.commit.commitTime)) { n.next = q; head = n; } else { @@ -91,11 +130,28 @@ public class DateRevQueue extends AbstractRevQueue { final Entry q = head; if (q == null) return null; + + if (index != null && q == index[first]) + index[first++] = null; + inQueue--; + head = q.next; freeEntry(q); return q.commit; } + private void buildIndex() { + sinceLastIndex = 0; + first = 0; + index = new Entry[inQueue / 100 + 1]; + int qi = 0, ii = 0; + for (Entry q = head; q != null; q = q.next) { + if (++qi % 100 == 0) + index[ii++] = q; + } + last = ii - 1; + } + /** * Peek at the next commit, without removing it. * @@ -108,6 +164,10 @@ public class DateRevQueue extends AbstractRevQueue { public void clear() { head = null; free = null; + index = null; + inQueue = 0; + sinceLastIndex = 0; + last = -1; } boolean everbodyHasFlag(final int f) { |