Skip to content

Commit

Permalink
Optimize lambda functions
Browse files Browse the repository at this point in the history
Currently, lambda functions are slow. (Almost same as normal user functions.)
If a lambda is used in map(), it is about 7x slower than a string expression,
and about 3x slower than a built-in function.

This makes lambda functions about 1.5x faster.
(Still slower than string expressions, though.)
  • Loading branch information
k-takata committed Mar 3, 2020
1 parent 5381c7a commit f8034a3
Showing 1 changed file with 7 additions and 0 deletions.
7 changes: 7 additions & 0 deletions src/userfunc.c
Original file line number Diff line number Diff line change
Expand Up @@ -1293,6 +1293,13 @@ call_user_func(

if (default_arg_err && (fp->uf_flags & FC_ABORT))
did_emsg = TRUE;
else if (islambda)
{
char_u *p = *(char_u**)fp->uf_lines.ga_data + 7; // Skip "return ".
++ex_nesting_level;
eval1(&p, rettv, TRUE);
--ex_nesting_level;
}
else
// call do_cmdline() to execute the lines
do_cmdline(NULL, get_func_line, (void *)fc,
Expand Down

0 comments on commit f8034a3

Please sign in to comment.