Skip to content

Commit

Permalink
builtin-apply.c: get rid of an unnecessary use of temporary array
Browse files Browse the repository at this point in the history
Instead of allocating a temporary array imglen[], copying contents to it
from another array img->line[], and then using imglen[], use the value
from img->line[], whose value does not change during the whole process.

This incidentally removes a use of C99 variable length array, which some
older compilers apparently are not happy with.

Signed-off-by: Junio C Hamano <gitster@pobox.com>
Junio C Hamano committed Sep 1, 2009
1 parent dcda361 commit 0b1fac3
Showing 1 changed file with 6 additions and 8 deletions.
14 changes: 6 additions & 8 deletions builtin-apply.c
Original file line number Diff line number Diff line change
@@ -1875,18 +1875,16 @@ static int match_fragment(struct image *img,
size_t imgoff = 0;
size_t preoff = 0;
size_t postlen = postimage->len;
size_t imglen[preimage->nr];
for (i = 0; i < preimage->nr; i++) {
size_t prelen = preimage->line[i].len;
size_t imglen = img->line[try_lno+i].len;

imglen[i] = img->line[try_lno+i].len;
if (!fuzzy_matchlines(
img->buf + try + imgoff, imglen[i],
preimage->buf + preoff, prelen))
if (!fuzzy_matchlines(img->buf + try + imgoff, imglen,
preimage->buf + preoff, prelen))
return 0;
if (preimage->line[i].flag & LINE_COMMON)
postlen += imglen[i] - prelen;
imgoff += imglen[i];
postlen += imglen - prelen;
imgoff += imglen;
preoff += prelen;
}

@@ -1900,7 +1898,7 @@ static int match_fragment(struct image *img,
fixed_buf = xmalloc(imgoff);
memcpy(fixed_buf, img->buf + try, imgoff);
for (i = 0; i < preimage->nr; i++)
preimage->line[i].len = imglen[i];
preimage->line[i].len = img->line[try_lno+i].len;

/*
* Update the preimage buffer and the postimage context lines.

0 comments on commit 0b1fac3

Please sign in to comment.