reftable: use a pointer for pq_entry param

The speed of the merged_iter_pqueue_add() can be improved by using a
pointer to the pq_entry struct, which is 96 bytes. Since the pq_entry
param is worked directly on the stack and does not currently have a
pointer to it, the merged_iter_pqueue_add() function is slightly
slower.

References to pq_entry in reftable have typically included pointers,
such as both of the params for pq_less().

Since we are working with pointers in the pq_entry param, as keenly
pointed out, the pq_entry param has also been made into a const since
the contents of the pq_entry param are copied and not manipulated.

Signed-off-by: Elijah Conners <business@elijahpepe.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
This commit is contained in:
Elijah Conners 2022-09-14 20:37:34 -07:00 committed by Junio C Hamano
parent 36f8e7ed7d
commit c18eecbe5c
4 changed files with 6 additions and 6 deletions

View File

@ -36,7 +36,7 @@ static int merged_iter_init(struct merged_iter *mi)
.rec = rec,
.index = i,
};
merged_iter_pqueue_add(&mi->pq, e);
merged_iter_pqueue_add(&mi->pq, &e);
}
}
@ -71,7 +71,7 @@ static int merged_iter_advance_nonnull_subiter(struct merged_iter *mi,
return 0;
}
merged_iter_pqueue_add(&mi->pq, e);
merged_iter_pqueue_add(&mi->pq, &e);
return 0;
}

View File

@ -71,7 +71,7 @@ struct pq_entry merged_iter_pqueue_remove(struct merged_iter_pqueue *pq)
return e;
}
void merged_iter_pqueue_add(struct merged_iter_pqueue *pq, struct pq_entry e)
void merged_iter_pqueue_add(struct merged_iter_pqueue *pq, const struct pq_entry *e)
{
int i = 0;
@ -81,7 +81,7 @@ void merged_iter_pqueue_add(struct merged_iter_pqueue *pq, struct pq_entry e)
pq->cap * sizeof(struct pq_entry));
}
pq->heap[pq->len++] = e;
pq->heap[pq->len++] = *e;
i = pq->len - 1;
while (i > 0) {
int j = (i - 1) / 2;

View File

@ -26,7 +26,7 @@ struct pq_entry merged_iter_pqueue_top(struct merged_iter_pqueue pq);
int merged_iter_pqueue_is_empty(struct merged_iter_pqueue pq);
void merged_iter_pqueue_check(struct merged_iter_pqueue pq);
struct pq_entry merged_iter_pqueue_remove(struct merged_iter_pqueue *pq);
void merged_iter_pqueue_add(struct merged_iter_pqueue *pq, struct pq_entry e);
void merged_iter_pqueue_add(struct merged_iter_pqueue *pq, const struct pq_entry *e);
void merged_iter_pqueue_release(struct merged_iter_pqueue *pq);
int pq_less(struct pq_entry *a, struct pq_entry *b);

View File

@ -46,7 +46,7 @@ static void test_pq(void)
.u.ref = {
.refname = names[i],
} } };
merged_iter_pqueue_add(&pq, e);
merged_iter_pqueue_add(&pq, &e);
merged_iter_pqueue_check(pq);
i = (i * 7) % N;
} while (i != 1);