prio-queue: factor out compare and swap operations
commit6d63baa47883315033474fc06196330e3a5ca4e0
authorJeff King <peff@peff.net>
Mon, 14 Jul 2014 05:42:50 +0000 (14 01:42 -0400)
committerJunio C Hamano <gitster@pobox.com>
Tue, 15 Jul 2014 18:02:53 +0000 (15 11:02 -0700)
tree24fc3be4034fa1398c6a16c59c78a371b3893e2f
parent66f467c3e6aa9c1e28eaf7b71cea5e452fc104e8
prio-queue: factor out compare and swap operations

When manipulating the priority queue's heap, we frequently
have to compare and swap heap entries. As we are storing
only void pointers right now, this is quite easy to do
inline in a few lines. However, when we start using a more
complicated heap entry in a future patch, that will get
longer. Factoring out these operations lets us make future
changes in one place. It also makes the code a little
shorter and more readable.

Note that we actually accept indices into the queue array
instead of pointers. This is slightly less flexible than
passing pointers-to-pointers (we could not swap items from
unrelated arrays, but we would not want to), but will make
further refactoring simpler (and lets us avoid repeating
"queue->array" at each callsite, which led to some long
lines).

And finally, note that we are cleaning up an accidental use
of a "struct commit" pointer to hold a temporary entry
during swap. Even though we currently only use this code for
commits, it is supposed to be type-agnostic. In practice
this didn't matter anyway because we never dereferenced the
commit pointer (and on most systems, the pointer values
themselves are interchangeable between types).

Signed-off-by: Jeff King <peff@peff.net>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
prio-queue.c