Skip to content

Commit 9d8c33d

Browse files
author
Chandra Pratap
committed
t-reftable-pq: make merged_iter_pqueue_check() callable by reference
merged_iter_pqueue_check() checks the validity of a priority queue represented by a merged_iter_pqueue struct by asserting the parent-child relation in the struct's heap. Explicity passing a struct to this function means a copy of the entire struct is created, which is inefficient. Make the function accept a pointer to the struct instead. This is safe to do since the function doesn't modify the struct in any way. Make the function parameter 'const' to assert immutability. Mentored-by: Patrick Steinhardt <ps@pks.im> Mentored-by: Christian Couder <chriscool@tuxfamily.org> Signed-off-by: Chandra Pratap <chandrapratap3519@gmail.com>
1 parent 9334b1f commit 9d8c33d

File tree

1 file changed

+5
-5
lines changed

1 file changed

+5
-5
lines changed

t/unit-tests/t-reftable-pq.c

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,11 +10,11 @@ license that can be found in the LICENSE file or at
1010
#include "reftable/constants.h"
1111
#include "reftable/pq.h"
1212

13-
static void merged_iter_pqueue_check(struct merged_iter_pqueue pq)
13+
static void merged_iter_pqueue_check(const struct merged_iter_pqueue *pq)
1414
{
15-
for (size_t i = 1; i < pq.len; i++) {
15+
for (size_t i = 1; i < pq->len; i++) {
1616
size_t parent = (i - 1) / 2;
17-
check(pq_less(&pq.heap[parent], &pq.heap[i]));
17+
check(pq_less(&pq->heap[parent], &pq->heap[i]));
1818
}
1919
}
2020

@@ -40,13 +40,13 @@ static void t_pq(void)
4040
};
4141

4242
merged_iter_pqueue_add(&pq, &e);
43-
merged_iter_pqueue_check(pq);
43+
merged_iter_pqueue_check(&pq);
4444
i = (i * 7) % N;
4545
} while (i != 1);
4646

4747
while (!merged_iter_pqueue_is_empty(pq)) {
4848
struct pq_entry e = merged_iter_pqueue_remove(&pq);
49-
merged_iter_pqueue_check(pq);
49+
merged_iter_pqueue_check(&pq);
5050

5151
check(reftable_record_type(e.rec) == BLOCK_TYPE_REF);
5252
if (last)

0 commit comments

Comments
 (0)