Skip to content

Commit 12f9ea4

Browse files
Chandra Pratapgitster
authored andcommitted
t-reftable-readwrite: use 'for' in place of infinite 'while' loops
Using a for loop with an empty conditional statement is more concise and easier to read than an infinite 'while' loop in instances where we need a loop variable. Hence, replace such instances of a 'while' loop with the equivalent 'for' loop. 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 3dd4fb1 commit 12f9ea4

File tree

1 file changed

+3
-9
lines changed

1 file changed

+3
-9
lines changed

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

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -269,15 +269,13 @@ static void t_log_write_read(void)
269269
err = reftable_iterator_seek_log(&it, "");
270270
check(!err);
271271

272-
i = 0;
273-
while (1) {
272+
for (i = 0; ; i++) {
274273
int err = reftable_iterator_next_log(&it, &log);
275274
if (err > 0)
276275
break;
277276
check(!err);
278277
check_str(names[i], log.refname);
279278
check_int(i, ==, log.update_index);
280-
i++;
281279
reftable_log_record_release(&log);
282280
}
283281

@@ -375,16 +373,14 @@ static void t_table_read_write_sequential(void)
375373
err = reftable_iterator_seek_ref(&it, "");
376374
check(!err);
377375

378-
while (1) {
376+
for (j = 0; ; j++) {
379377
struct reftable_ref_record ref = { 0 };
380378
int r = reftable_iterator_next_ref(&it, &ref);
381379
check_int(r, >=, 0);
382380
if (r > 0)
383381
break;
384382
check_str(names[j], ref.refname);
385383
check_int(update_index, ==, ref.update_index);
386-
387-
j++;
388384
reftable_ref_record_release(&ref);
389385
}
390386
check_int(j, ==, N);
@@ -590,15 +586,13 @@ static void t_table_refs_for(int indexed)
590586
err = reftable_reader_refs_for(&rd, &it, want_hash);
591587
check(!err);
592588

593-
j = 0;
594-
while (1) {
589+
for (j = 0; ; j++) {
595590
int err = reftable_iterator_next_ref(&it, &ref);
596591
check_int(err, >=, 0);
597592
if (err > 0)
598593
break;
599594
check_int(j, <, want_names_len);
600595
check_str(ref.refname, want_names[j]);
601-
j++;
602596
reftable_ref_record_release(&ref);
603597
}
604598
check_int(j, ==, want_names_len);

0 commit comments

Comments
 (0)