Skip to content

Commit

Permalink
Merge branch 'jk/prio-queue-sign-compare-fix' into next
Browse files Browse the repository at this point in the history
Type clean-up.

* jk/prio-queue-sign-compare-fix:
  prio-queue: use size_t rather than int for size
  • Loading branch information
gitster committed Dec 21, 2024
2 parents f775554 + 62e745c commit 11a5c3d
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 10 deletions.
5 changes: 2 additions & 3 deletions negotiator/skipping.c
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,6 @@ static int push_parent(struct data *data, struct entry *entry,
struct entry *parent_entry;

if (to_push->object.flags & SEEN) {
int i;
if (to_push->object.flags & POPPED)
/*
* The entry for this commit has already been popped,
Expand All @@ -145,7 +144,7 @@ static int push_parent(struct data *data, struct entry *entry,
/*
* Find the existing entry and use it.
*/
for (i = 0; i < data->rev_list.nr; i++) {
for (size_t i = 0; i < data->rev_list.nr; i++) {
parent_entry = data->rev_list.array[i].data;
if (parent_entry->commit == to_push)
goto parent_found;
Expand Down Expand Up @@ -248,7 +247,7 @@ static int ack(struct fetch_negotiator *n, struct commit *c)
static void release(struct fetch_negotiator *n)
{
struct data *data = n->data;
for (int i = 0; i < data->rev_list.nr; i++)
for (size_t i = 0; i < data->rev_list.nr; i++)
free(data->rev_list.array[i].data);
clear_prio_queue(&data->rev_list);
FREE_AND_NULL(data);
Expand Down
15 changes: 9 additions & 6 deletions prio-queue.c
Original file line number Diff line number Diff line change
@@ -1,26 +1,29 @@
#include "git-compat-util.h"
#include "prio-queue.h"

static inline int compare(struct prio_queue *queue, int i, int j)
static inline int compare(struct prio_queue *queue, size_t i, size_t j)
{
int cmp = queue->compare(queue->array[i].data, queue->array[j].data,
queue->cb_data);
if (!cmp)
cmp = queue->array[i].ctr - queue->array[j].ctr;
cmp = (queue->array[i].ctr > queue->array[j].ctr) -
(queue->array[i].ctr < queue->array[j].ctr);
return cmp;
}

static inline void swap(struct prio_queue *queue, int i, int j)
static inline void swap(struct prio_queue *queue, size_t i, size_t j)
{
SWAP(queue->array[i], queue->array[j]);
}

void prio_queue_reverse(struct prio_queue *queue)
{
int i, j;
size_t i, j;

if (queue->compare)
BUG("prio_queue_reverse() on non-LIFO queue");
if (!queue->nr)
return;
for (i = 0; i < (j = (queue->nr - 1) - i); i++)
swap(queue, i, j);
}
Expand All @@ -35,7 +38,7 @@ void clear_prio_queue(struct prio_queue *queue)

void prio_queue_put(struct prio_queue *queue, void *thing)
{
int ix, parent;
size_t ix, parent;

/* Append at the end */
ALLOC_GROW(queue->array, queue->nr + 1, queue->alloc);
Expand All @@ -58,7 +61,7 @@ void prio_queue_put(struct prio_queue *queue, void *thing)
void *prio_queue_get(struct prio_queue *queue)
{
void *result;
int ix, child;
size_t ix, child;

if (!queue->nr)
return NULL;
Expand Down
2 changes: 1 addition & 1 deletion prio-queue.h
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ struct prio_queue {
prio_queue_compare_fn compare;
unsigned insertion_ctr;
void *cb_data;
int alloc, nr;
size_t alloc, nr;
struct prio_queue_entry *array;
};

Expand Down

0 comments on commit 11a5c3d

Please sign in to comment.