diff options
author | Junio C Hamano <gitster@pobox.com> | 2010-11-24 12:46:26 -0800 |
---|---|---|
committer | Junio C Hamano <gitster@pobox.com> | 2010-11-24 12:46:26 -0800 |
commit | 9cffe2018a8c400cbd50a8aec4eddea97c4ede2f (patch) | |
tree | 2611de762d5c014f6e386b284002b2a8006832fe /xdiff | |
parent | 78bce6c7e93f4c8797da06cf93f59b7ac8e84ec0 (diff) | |
parent | c099789bb01b810e40f9cfaa5c842ed568110fc8 (diff) | |
download | git-9cffe2018a8c400cbd50a8aec4eddea97c4ede2f.tar.gz git-9cffe2018a8c400cbd50a8aec4eddea97c4ede2f.tar.xz |
Merge branch 'cb/diff-fname-optim' into maint
* cb/diff-fname-optim:
diff: avoid repeated scanning while looking for funcname
do not search functions for patch ID
add rebase patch id tests
Diffstat (limited to 'xdiff')
-rw-r--r-- | xdiff/xemit.c | 38 |
1 files changed, 14 insertions, 24 deletions
diff --git a/xdiff/xemit.c b/xdiff/xemit.c index c4bedf0d1..277e2eec5 100644 --- a/xdiff/xemit.c +++ b/xdiff/xemit.c @@ -85,27 +85,6 @@ static long def_ff(const char *rec, long len, char *buf, long sz, void *priv) return -1; } -static void xdl_find_func(xdfile_t *xf, long i, char *buf, long sz, long *ll, - find_func_t ff, void *ff_priv) { - - /* - * Be quite stupid about this for now. Find a line in the old file - * before the start of the hunk (and context) which starts with a - * plausible character. - */ - - const char *rec; - long len; - - while (i-- > 0) { - len = xdl_get_rec(xf, i, &rec); - if ((*ll = ff(rec, len, buf, sz, ff_priv)) >= 0) - return; - } - *ll = 0; -} - - static int xdl_emit_common(xdfenv_t *xe, xdchange_t *xscr, xdemitcb_t *ecb, xdemitconf_t const *xecfg) { xdfile_t *xdf = &xe->xdf1; @@ -127,6 +106,7 @@ int xdl_emit_diff(xdfenv_t *xe, xdchange_t *xscr, xdemitcb_t *ecb, xdchange_t *xch, *xche; char funcbuf[80]; long funclen = 0; + long funclineprev = -1; find_func_t ff = xecfg->find_func ? xecfg->find_func : def_ff; if (xecfg->flags & XDL_EMIT_COMMON) @@ -150,9 +130,19 @@ int xdl_emit_diff(xdfenv_t *xe, xdchange_t *xscr, xdemitcb_t *ecb, */ if (xecfg->flags & XDL_EMIT_FUNCNAMES) { - xdl_find_func(&xe->xdf1, s1, funcbuf, - sizeof(funcbuf), &funclen, - ff, xecfg->find_func_priv); + long l; + for (l = s1 - 1; l >= 0 && l > funclineprev; l--) { + const char *rec; + long reclen = xdl_get_rec(&xe->xdf1, l, &rec); + long newfunclen = ff(rec, reclen, funcbuf, + sizeof(funcbuf), + xecfg->find_func_priv); + if (newfunclen >= 0) { + funclen = newfunclen; + break; + } + } + funclineprev = s1 - 1; } if (xdl_emit_hunk_hdr(s1 + 1, e1 - s1, s2 + 1, e2 - s2, funcbuf, funclen, ecb) < 0) |