From: krw Date: Tue, 3 Jan 2023 23:27:03 +0000 (+0000) Subject: No need to call editor_countfree() when displaying all the free X-Git-Url: http://artulab.com/gitweb/?a=commitdiff_plain;h=d9355c7d00921db37f6647b28a1cb52451ed19fb;p=openbsd No need to call editor_countfree() when displaying all the free chunks in the 'r' editor command. Just add up chunks as they are displayed. Eliminates pointless second invocation of free_chunks(). Increment the chunk pointer rather than using iteration variable + indexing. No intentional functional change. --- diff --git a/sbin/disklabel/editor.c b/sbin/disklabel/editor.c index 00c838eb725..b8f254b002d 100644 --- a/sbin/disklabel/editor.c +++ b/sbin/disklabel/editor.c @@ -1,4 +1,4 @@ -/* $OpenBSD: editor.c,v 1.380 2022/11/10 15:26:38 krw Exp $ */ +/* $OpenBSD: editor.c,v 1.381 2023/01/03 23:27:03 krw Exp $ */ /* * Copyright (c) 1997-2000 Todd C. Miller @@ -407,18 +407,18 @@ editor(int f) break; case 'r': { - struct diskchunk *chunks; - int i; + const struct diskchunk *chunk; + uint64_t total = 0; /* Display free space. */ - chunks = free_chunks(&newlab); - for (i = 0; chunks[i].start != 0 || chunks[i].stop != 0; - i++) + chunk = free_chunks(&newlab); + for (; chunk->start != 0 || chunk->stop != 0; chunk++) { + total += chunk->stop - chunk->start; fprintf(stderr, "Free sectors: %16llu - %16llu " "(%16llu)\n", - chunks[i].start, chunks[i].stop - 1, - chunks[i].stop - chunks[i].start); - fprintf(stderr, "Total free sectors: %llu.\n", - editor_countfree(&newlab)); + chunk->start, chunk->stop - 1, + chunk->stop - chunk->start); + } + fprintf(stderr, "Total free sectors: %llu.\n", total); break; }