]> git.ipfire.org Git - thirdparty/git.git/commitdiff
t-reftable-pq: make merged_iter_pqueue_check() callable by reference
authorChandra Pratap <chandrapratap3519@gmail.com>
Thu, 1 Aug 2024 10:59:46 +0000 (16:29 +0530)
committerJunio C Hamano <gitster@pobox.com>
Thu, 1 Aug 2024 16:07:29 +0000 (09:07 -0700)
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>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
t/unit-tests/t-reftable-pq.c

index 220e82be19dcbf257352203558f48fabc79870ec..9230dd9b9e605446162366184dfcd42d6e8b759e 100644 (file)
@@ -10,11 +10,11 @@ https://developers.google.com/open-source/licenses/bsd
 #include "reftable/constants.h"
 #include "reftable/pq.h"
 
-static void merged_iter_pqueue_check(struct merged_iter_pqueue pq)
+static void merged_iter_pqueue_check(const struct merged_iter_pqueue *pq)
 {
-       for (size_t i = 1; i < pq.len; i++) {
+       for (size_t i = 1; i < pq->len; i++) {
                size_t parent = (i - 1) / 2;
-               check(pq_less(&pq.heap[parent], &pq.heap[i]));
+               check(pq_less(&pq->heap[parent], &pq->heap[i]));
        }
 }
 
@@ -40,13 +40,13 @@ static void t_pq(void)
                };
 
                merged_iter_pqueue_add(&pq, &e);
-               merged_iter_pqueue_check(pq);
+               merged_iter_pqueue_check(&pq);
                i = (i * 7) % N;
        } while (i != 1);
 
        while (!merged_iter_pqueue_is_empty(pq)) {
                struct pq_entry e = merged_iter_pqueue_remove(&pq);
-               merged_iter_pqueue_check(pq);
+               merged_iter_pqueue_check(&pq);
 
                check(reftable_record_type(e.rec) == BLOCK_TYPE_REF);
                if (last)