xdiff: factor out match_func_rec()
Add match_func_rec(), a helper that wraps accessing a record and calling the appropriate function for checking if it contains a function line. Signed-off-by: Rene Scharfe <l.s.r@web.de> Signed-off-by: Junio C Hamano <gitster@pobox.com>
René Scharfe committed
May 28, 2016 at 16:58 UTC
ff2981f724c617d377229666e6deae257de5e239
1 file changed
+11
-4
xdiff/xemit.c
+11
-4
@@ -120,6 +120,16 @@ static long def_ff(const char *rec, long len, char *buf, long sz, void *priv)
120
return -1;
121
}
122
123
+static long match_func_rec(xdfile_t *xdf, xdemitconf_t const *xecfg, long ri,
124
+ char *buf, long sz)
125
+{
126
+ const char *rec;
127
+ long len = xdl_get_rec(xdf, ri, &rec);
128
+ if (!xecfg->find_func)
129
+ return def_ff(rec, len, buf, sz, xecfg->find_func_priv);
130
+ return xecfg->find_func(rec, len, buf, sz, xecfg->find_func_priv);
131
+}
132
+
133
struct func_line {
134
long len;
135
char buf[80];
@@ -128,7 +138,6 @@ struct func_line {
138
static long get_func_line(xdfenv_t *xe, xdemitconf_t const *xecfg,
139
struct func_line *func_line, long start, long limit)
140
{
131
- find_func_t ff = xecfg->find_func ? xecfg->find_func : def_ff;
141
long l, size, step = (start > limit) ? -1 : 1;
142
char *buf, dummy[1];
143
@@ -136,9 +145,7 @@ static long get_func_line(xdfenv_t *xe, xdemitconf_t const *xecfg,
145
size = func_line ? sizeof(func_line->buf) : sizeof(dummy);
146
147
for (l = start; l != limit && 0 <= l && l < xe->xdf1.nrec; l += step) {
139
- const char *rec;
140
- long reclen = xdl_get_rec(&xe->xdf1, l, &rec);
141
- long len = ff(rec, reclen, buf, size, xecfg->find_func_priv);
148
+ long len = match_func_rec(&xe->xdf1, xecfg, l, buf, size);
149
if (len >= 0) {
150
if (func_line)
151
func_line->len = len;