Use a FIFO queue of RevCommit during reset rather than sorting by date
commite69281835d0845161426ff57040f6db0ec646671
authorShawn O. Pearce <spearce@spearce.org>
Thu, 13 Mar 2008 00:04:12 +0000 (12 20:04 -0400)
committerShawn O. Pearce <spearce@spearce.org>
Mon, 7 Apr 2008 03:40:49 +0000 (6 23:40 -0400)
tree7c449b7b9f54b2e98d8bd05a02291167936a00fd
parent42db43ad18a64463cb6b502e0ff2e3a487aa3a68
Use a FIFO queue of RevCommit during reset rather than sorting by date

We really don't care about preserving commit time order during the
walk from the roots backwards to execute a reset.  Performing a sort
during insertion into the queue only wastes CPU time.  Using a FIFO
queue (or even a LIFO queue) makes this process faster.

I'm making the FIFO queue public as there are many algorithms that
we need to implement which will benefit from having a FIFO queue.

The FIFO queue uses a linked list of blocks, to make it cheap to add
additional memory as necessary but yet ammortize the cost of the
recording overheads imposed by the queue to almost 0.  With a block
size of 256 we get an overhead of ~4.125 bytes per commit, with the
bulk of that 4 bytes going to the commit reference itself in the
block's commit array.

We don't bother to clear references after we pop them from the queue.
This is because a queue is meant to be used with a single RevWalk
instance and the RevCommits are pooled by strong references inside of
the RevWalk.  Until the RevWalk goes away those commits will be
strongly held anyway, so clearing our arrays is a waste of CPU time
and memory bandwidth.

We allow blocks to be moved between two FIFORevQueues as some
uses will be doing exactly that; shuffling commits from one queue
into another queue.  Sharing a single free list between them will
allow emptied blocks to migrate from the one queue to the other,
with only one additional block necessary as temporary working space.

Signed-off-by: Shawn O. Pearce <spearce@spearce.org>
org.spearce.jgit/src/org/spearce/jgit/revwalk/FIFORevQueue.java [new file with mode: 0644]
org.spearce.jgit/src/org/spearce/jgit/revwalk/RevWalk.java