Skip to content

Commit 31216ee

Browse files
Chandra Pratapgitster
authored andcommitted
t-reftable-block: use block_iter_reset() instead of block_iter_close()
block_iter_reset() restores a block iterator to its state at the time of initialization without freeing any memory while block_iter_close() deallocates the memory for the iterator. In the current testing setup, a block iterator is allocated and deallocated for every iteration of a loop, which hurts performance. Improve upon this by using block_iter_reset() at the start of each iteration instead. This has the added benifit of testing block_iter_reset(), which currently remains untested. Similarly, remove reftable_record_release() for a reftable record that is still in use. Mentored-by: Patrick Steinhardt <[email protected]> Mentored-by: Christian Couder <[email protected]> Signed-off-by: Chandra Pratap <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent c25cbcd commit 31216ee

File tree

1 file changed

+2
-6
lines changed

1 file changed

+2
-6
lines changed

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

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -78,11 +78,8 @@ static void t_block_read_write(void)
7878
j++;
7979
}
8080

81-
reftable_record_release(&rec);
82-
block_iter_close(&it);
83-
8481
for (i = 0; i < N; i++) {
85-
struct block_iter it = BLOCK_ITER_INIT;
82+
block_iter_reset(&it);
8683
reftable_record_key(&recs[i], &want);
8784

8885
ret = block_iter_seek_key(&it, &br, &want);
@@ -100,11 +97,10 @@ static void t_block_read_write(void)
10097
ret = block_iter_next(&it, &rec);
10198
check_int(ret, ==, 0);
10299
check(reftable_record_equal(&recs[10 * (i / 10)], &rec, GIT_SHA1_RAWSZ));
103-
104-
block_iter_close(&it);
105100
}
106101

107102
block_reader_release(&br);
103+
block_iter_close(&it);
108104
reftable_record_release(&rec);
109105
reftable_block_done(&br.block);
110106
strbuf_release(&want);

0 commit comments

Comments
 (0)