Skip to content

Commit ff2981f

Browse files
rscharfegitster
authored andcommitted
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 <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent d3621de commit ff2981f

File tree

1 file changed

+11
-4
lines changed

1 file changed

+11
-4
lines changed

xdiff/xemit.c

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -120,6 +120,16 @@ static long def_ff(const char *rec, long len, char *buf, long sz, void *priv)
120120
return -1;
121121
}
122122

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+
123133
struct func_line {
124134
long len;
125135
char buf[80];
@@ -128,17 +138,14 @@ struct func_line {
128138
static long get_func_line(xdfenv_t *xe, xdemitconf_t const *xecfg,
129139
struct func_line *func_line, long start, long limit)
130140
{
131-
find_func_t ff = xecfg->find_func ? xecfg->find_func : def_ff;
132141
long l, size, step = (start > limit) ? -1 : 1;
133142
char *buf, dummy[1];
134143

135144
buf = func_line ? func_line->buf : dummy;
136145
size = func_line ? sizeof(func_line->buf) : sizeof(dummy);
137146

138147
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);
142149
if (len >= 0) {
143150
if (func_line)
144151
func_line->len = len;

0 commit comments

Comments
 (0)