summaryrefslogtreecommitdiff
path: root/src/vim9expr.c
diff options
context:
space:
mode:
authorLemonBoy <thatlemon@gmail.com>2022-04-02 21:59:06 +0100
committerBram Moolenaar <Bram@vim.org>2022-04-02 21:59:06 +0100
commit58f331a05f5b7bdddf04e68b6e51a827fd0c43f0 (patch)
tree349de5cab822dc0ccaea9c127fc960f6ab335d2f /src/vim9expr.c
parent0dac1ab5791819ee9a496273eea38f69a217ac45 (diff)
downloadvim-git-58f331a05f5b7bdddf04e68b6e51a827fd0c43f0.tar.gz
patch 8.2.4669: in compiled code len('string') is not inlinedv8.2.4669
Problem: In compiled code len('string') is not inlined. Solution: Compute the length at compile time if possible. (closes #10065)
Diffstat (limited to 'src/vim9expr.c')
-rw-r--r--src/vim9expr.c9
1 files changed, 7 insertions, 2 deletions
diff --git a/src/vim9expr.c b/src/vim9expr.c
index 1b4c7b806..69f670b24 100644
--- a/src/vim9expr.c
+++ b/src/vim9expr.c
@@ -724,13 +724,16 @@ compile_call(
}
// We can evaluate "has('name')" at compile time.
+ // We can evaluate "len('string')" at compile time.
// We always evaluate "exists_compiled()" at compile time.
- if ((varlen == 3 && STRNCMP(*arg, "has", 3) == 0)
+ if ((varlen == 3
+ && (STRNCMP(*arg, "has", 3) == 0 || STRNCMP(*arg, "len", 3) == 0))
|| (varlen == 15 && STRNCMP(*arg, "exists_compiled", 6) == 0))
{
char_u *s = skipwhite(*arg + varlen + 1);
typval_T argvars[2];
int is_has = **arg == 'h';
+ int is_len = **arg == 'l';
argvars[0].v_type = VAR_UNKNOWN;
if (*s == '"')
@@ -750,6 +753,8 @@ compile_call(
tv->vval.v_number = 0;
if (is_has)
f_has(argvars, tv);
+ else if (is_len)
+ f_len(argvars, tv);
else
f_exists(argvars, tv);
clear_tv(&argvars[0]);
@@ -757,7 +762,7 @@ compile_call(
return OK;
}
clear_tv(&argvars[0]);
- if (!is_has)
+ if (!is_has && !is_len)
{
emsg(_(e_argument_of_exists_compiled_must_be_literal_string));
return FAIL;