builtin-apply.c: get rid of an unnecessary use of temporary array
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 at 02:18 UTC
0b1fac320c10b83133f824805055ff428b331e19
1 file changed
+6
-8
builtin-apply.c
+6
-8
@@ -1875,18 +1875,16 @@ static int match_fragment(struct image *img,
1875
size_t imgoff = 0;
1876
size_t preoff = 0;
1877
size_t postlen = postimage->len;
1878
- size_t imglen[preimage->nr];
1878
for (i = 0; i < preimage->nr; i++) {
1879
size_t prelen = preimage->line[i].len;
1880
+ size_t imglen = img->line[try_lno+i].len;
1881
1882
- imglen[i] = img->line[try_lno+i].len;
1883
- if (!fuzzy_matchlines(
1884
- img->buf + try + imgoff, imglen[i],
1885
- preimage->buf + preoff, prelen))
1882
+ if (!fuzzy_matchlines(img->buf + try + imgoff, imglen,
1883
+ preimage->buf + preoff, prelen))
1884
return 0;
1885
if (preimage->line[i].flag & LINE_COMMON)
1888
- postlen += imglen[i] - prelen;
1889
- imgoff += imglen[i];
1886
+ postlen += imglen - prelen;
1887
+ imgoff += imglen;
1888
preoff += prelen;
1889
}
1890
@@ -1900,7 +1898,7 @@ static int match_fragment(struct image *img,
1898
fixed_buf = xmalloc(imgoff);
1899
memcpy(fixed_buf, img->buf + try, imgoff);
1900
for (i = 0; i < preimage->nr; i++)
1903
- preimage->line[i].len = imglen[i];
1901
+ preimage->line[i].len = img->line[try_lno+i].len;
1902
1903
/*
1904
* Update the preimage buffer and the postimage context lines.