diff options
author | Bram Moolenaar <Bram@vim.org> | 2022-10-01 15:32:46 +0100 |
---|---|---|
committer | Bram Moolenaar <Bram@vim.org> | 2022-10-01 15:32:46 +0100 |
commit | 87b4e5c5db9d1cfd6f2e79656e1a6cff3c69d15f (patch) | |
tree | a437917654ad79edd9764b4f67af33ce01228d6a /src/eval.c | |
parent | 145d1fd91041bd2a22a11eef0357702e420796e2 (diff) |
patch 9.0.0632: calling a function from an "expr" option has overheadv9.0.0632
Problem: Calling a function from an "expr" option has too much overhead.
Solution: Add call_simple_func() and use it for 'foldexpr'
Diffstat (limited to 'src/eval.c')
-rw-r--r-- | src/eval.c | 19 |
1 files changed, 17 insertions, 2 deletions
diff --git a/src/eval.c b/src/eval.c index 2330bd6a10..aeb8fee7ad 100644 --- a/src/eval.c +++ b/src/eval.c @@ -899,13 +899,14 @@ eval_foldexpr(win_T *wp, int *cp) { char_u *arg; typval_T tv; + int r = NOTDONE; varnumber_T retval; char_u *s; sctx_T saved_sctx = current_sctx; int use_sandbox = was_set_insecurely((char_u *)"foldexpr", OPT_LOCAL); - arg = wp->w_p_fde; + arg = skipwhite(wp->w_p_fde); current_sctx = wp->w_p_script_ctx[WV_FDE]; ++emsg_off; @@ -913,7 +914,21 @@ eval_foldexpr(win_T *wp, int *cp) ++sandbox; ++textlock; *cp = NUL; - if (eval0(arg, &tv, NULL, &EVALARG_EVALUATE) == FAIL) + + // If the expression is "FuncName()" then we can skip a lot of overhead. + char_u *parens = (char_u *)strstr((char *)arg, "()"); + if (parens != NULL && *skipwhite(parens + 2) == NUL) + { + char_u *p = STRNCMP(arg, "<SNR>", 5) == 0 ? skipdigits(arg + 5) : arg; + + if (to_name_end(p, TRUE) == parens) + r = call_simple_func(arg, (int)(parens - arg), &tv); + } + + if (r == NOTDONE) + r = eval0(arg, &tv, NULL, &EVALARG_EVALUATE); + + if (r == FAIL) retval = 0; else { |