Browse Source

Merge "Performance fixes in DateRevQueue"

stable-3.0
Shawn Pearce 12 years ago committed by Gerrit Code Review @ Eclipse.org
parent
commit
9613b04d81
  1. 64
      org.eclipse.jgit/src/org/eclipse/jgit/revwalk/DateRevQueue.java

64
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) {

Loading…
Cancel
Save