mirror of
https://github.com/neovim/neovim.git
synced 2025-09-24 12:08:33 +00:00
vim-patch:9.0.0548: reduce() with a compiled lambda could be faster
Problem: reduce() with a compiled lambda could be faster.
Solution: Call eval_expr_typval() instead of call_func() directly.
f1c60d4bf1
Co-authored-by: Bram Moolenaar <Bram@vim.org>
This commit is contained in:
@@ -6167,9 +6167,10 @@ static void f_reverse(typval_T *argvars, typval_T *rettv, EvalFuncData fptr)
|
||||
}
|
||||
}
|
||||
|
||||
/// reduce() on a List
|
||||
static void reduce_list(typval_T *argvars, const char *func_name, funcexe_T *funcexe,
|
||||
typval_T *rettv)
|
||||
/// Implementation of reduce() for list "argvars[0]", using the function "expr"
|
||||
/// starting with the optional initial value argvars[2] and return the result in
|
||||
/// "rettv".
|
||||
static void reduce_list(typval_T *argvars, typval_T *expr, typval_T *rettv)
|
||||
{
|
||||
list_T *const l = argvars[0].vval.v_list;
|
||||
const int called_emsg_start = called_emsg;
|
||||
@@ -6203,7 +6204,9 @@ static void reduce_list(typval_T *argvars, const char *func_name, funcexe_T *fun
|
||||
argv[0] = *rettv;
|
||||
argv[1] = *TV_LIST_ITEM_TV(li);
|
||||
rettv->v_type = VAR_UNKNOWN;
|
||||
const int r = call_func(func_name, -1, rettv, 2, argv, funcexe);
|
||||
|
||||
const int r = eval_expr_typval(expr, argv, 2, rettv);
|
||||
|
||||
tv_clear(&argv[0]);
|
||||
if (r == FAIL || called_emsg != called_emsg_start) {
|
||||
break;
|
||||
@@ -6212,9 +6215,10 @@ static void reduce_list(typval_T *argvars, const char *func_name, funcexe_T *fun
|
||||
tv_list_set_lock(l, prev_locked);
|
||||
}
|
||||
|
||||
/// reduce() on a String
|
||||
static void reduce_string(typval_T *argvars, const char *func_name, funcexe_T *funcexe,
|
||||
typval_T *rettv)
|
||||
/// Implementation of reduce() for String "argvars[0]" using the function "expr"
|
||||
/// starting with the optional initial value "argvars[2]" and return the result
|
||||
/// in "rettv".
|
||||
static void reduce_string(typval_T *argvars, typval_T *expr, typval_T *rettv)
|
||||
{
|
||||
const char *p = tv_get_string(&argvars[0]);
|
||||
int len;
|
||||
@@ -6247,7 +6251,9 @@ static void reduce_string(typval_T *argvars, const char *func_name, funcexe_T *f
|
||||
.v_lock = VAR_UNLOCKED,
|
||||
.vval.v_string = xstrnsave(p, (size_t)len),
|
||||
};
|
||||
const int r = call_func(func_name, -1, rettv, 2, argv, funcexe);
|
||||
|
||||
const int r = eval_expr_typval(expr, argv, 2, rettv);
|
||||
|
||||
tv_clear(&argv[0]);
|
||||
tv_clear(&argv[1]);
|
||||
if (r == FAIL || called_emsg != called_emsg_start) {
|
||||
@@ -6256,9 +6262,10 @@ static void reduce_string(typval_T *argvars, const char *func_name, funcexe_T *f
|
||||
}
|
||||
}
|
||||
|
||||
/// reduce() on a Blob
|
||||
static void reduce_blob(typval_T *argvars, const char *func_name, funcexe_T *funcexe,
|
||||
typval_T *rettv)
|
||||
/// Implementaion of reduce() for Blob "argvars[0]" using the function "expr"
|
||||
/// starting with the optional initial value "argvars[2]" and return the result
|
||||
/// in "rettv".
|
||||
static void reduce_blob(typval_T *argvars, typval_T *expr, typval_T *rettv)
|
||||
{
|
||||
const blob_T *const b = argvars[0].vval.v_blob;
|
||||
const int called_emsg_start = called_emsg;
|
||||
@@ -6292,7 +6299,9 @@ static void reduce_blob(typval_T *argvars, const char *func_name, funcexe_T *fun
|
||||
.v_lock = VAR_UNLOCKED,
|
||||
.vval.v_number = tv_blob_get(b, i),
|
||||
};
|
||||
const int r = call_func(func_name, -1, rettv, 2, argv, funcexe);
|
||||
|
||||
const int r = eval_expr_typval(expr, argv, 2, rettv);
|
||||
|
||||
if (r == FAIL || called_emsg != called_emsg_start) {
|
||||
return;
|
||||
}
|
||||
@@ -6312,12 +6321,10 @@ static void f_reduce(typval_T *argvars, typval_T *rettv, EvalFuncData fptr)
|
||||
}
|
||||
|
||||
const char *func_name;
|
||||
partial_T *partial = NULL;
|
||||
if (argvars[1].v_type == VAR_FUNC) {
|
||||
func_name = argvars[1].vval.v_string;
|
||||
} else if (argvars[1].v_type == VAR_PARTIAL) {
|
||||
partial = argvars[1].vval.v_partial;
|
||||
func_name = partial_name(partial);
|
||||
func_name = partial_name(argvars[1].vval.v_partial);
|
||||
} else {
|
||||
func_name = tv_get_string(&argvars[1]);
|
||||
}
|
||||
@@ -6326,16 +6333,12 @@ static void f_reduce(typval_T *argvars, typval_T *rettv, EvalFuncData fptr)
|
||||
return;
|
||||
}
|
||||
|
||||
funcexe_T funcexe = FUNCEXE_INIT;
|
||||
funcexe.fe_evaluate = true;
|
||||
funcexe.fe_partial = partial;
|
||||
|
||||
if (argvars[0].v_type == VAR_LIST) {
|
||||
reduce_list(argvars, func_name, &funcexe, rettv);
|
||||
reduce_list(argvars, &argvars[1], rettv);
|
||||
} else if (argvars[0].v_type == VAR_STRING) {
|
||||
reduce_string(argvars, func_name, &funcexe, rettv);
|
||||
reduce_string(argvars, &argvars[1], rettv);
|
||||
} else {
|
||||
reduce_blob(argvars, func_name, &funcexe, rettv);
|
||||
reduce_blob(argvars, &argvars[1], rettv);
|
||||
}
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user