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 <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>
Chandra Pratap committed
Aug 13, 2024 at 20:04 UTC
12f9ea473f00384147e334ff1f05c8f3b2fe1a78
1 file changed
+3
-9
t/unit-tests/t-reftable-readwrite.c
+3
-9
@@ -269,15 +269,13 @@ static void t_log_write_read(void)
269
err = reftable_iterator_seek_log(&it, "");
270
check(!err);
271
272
- i = 0;
273
- while (1) {
272
+ for (i = 0; ; i++) {
273
int err = reftable_iterator_next_log(&it, &log);
274
if (err > 0)
275
break;
276
check(!err);
277
check_str(names[i], log.refname);
278
check_int(i, ==, log.update_index);
280
- i++;
279
reftable_log_record_release(&log);
280
}
281
@@ -375,7 +373,7 @@ static void t_table_read_write_sequential(void)
373
err = reftable_iterator_seek_ref(&it, "");
374
check(!err);
375
378
- while (1) {
376
+ for (j = 0; ; j++) {
377
struct reftable_ref_record ref = { 0 };
378
int r = reftable_iterator_next_ref(&it, &ref);
379
check_int(r, >=, 0);
@@ -383,8 +381,6 @@ static void t_table_read_write_sequential(void)
381
break;
382
check_str(names[j], ref.refname);
383
check_int(update_index, ==, ref.update_index);
386
-
387
- j++;
384
reftable_ref_record_release(&ref);
385
}
386
check_int(j, ==, N);
@@ -590,15 +586,13 @@ static void t_table_refs_for(int indexed)
586
err = reftable_reader_refs_for(&rd, &it, want_hash);
587
check(!err);
588
593
- j = 0;
594
- while (1) {
589
+ for (j = 0; ; j++) {
590
int err = reftable_iterator_next_ref(&it, &ref);
591
check_int(err, >=, 0);
592
if (err > 0)
593
break;
594
check_int(j, <, want_names_len);
595
check_str(ref.refname, want_names[j]);
601
- j++;
596
reftable_ref_record_release(&ref);
597
}
598
check_int(j, ==, want_names_len);