Re: [PATCH] blame.c: prepare_lines should not call xrealloc for every line
- From
Junio C Hamano <gitster@pobox.com>
- Date
- Feb 4, 2014, 21:44 UTC
- Message-ID
- <xmqqr47i7dt4.fsf@gitster.dls.corp.google.com>
- In-Reply-To
- <874n4ewouz.fsf@fencepost.gnu.org>
David Kastrup <dak@gnu.org> writes:
Show 7 quoted lines
> Ok, I now wrote
>
> for (p = buf;; num++, p++) {
> p = memchr(p, '\n', end - p);
> if (!p)
> break;
> }Looks still wrong (perhaps this is a taste issue).
num++ is not "loop control", but the real action of this loop to count lines. It is better left inside.
p++ is "loop control", and belongs to the third part of for(;;).
Isn't the normal continuation condition "p < end"?
so something like
for (p = buf; p < end; p++) {
p = find the end of this line
if (!p)
break;
num++;
}perhaps?