diff options
author | Sean Dewar <seandewar@users.noreply.github.com> | 2021-10-14 00:40:46 +0100 |
---|---|---|
committer | Sean Dewar <seandewar@users.noreply.github.com> | 2021-10-14 12:50:04 +0100 |
commit | da9b0abc67a936021a4ecf7634395db860edcab1 (patch) | |
tree | f193d08a729743d2f165a81486df78dfd2b6acce /src/nvim/eval.c | |
parent | d4ed51eb4492d4358eb4ab0c939802f2a5fdc636 (diff) | |
download | rneovim-da9b0abc67a936021a4ecf7634395db860edcab1.tar.gz rneovim-da9b0abc67a936021a4ecf7634395db860edcab1.tar.bz2 rneovim-da9b0abc67a936021a4ecf7634395db860edcab1.zip |
feat(:source, nvim_exec): defer script item creation until s:var access
For anonymous scripts, defer the creation of script items until an attempt to access a script-local
variable is made. This dramatically reduces the number of script items created when using lots of
vim.cmd and nvim_exec especially.
This will mean <SID> usage fails until a script-local variable access is first made.
Diffstat (limited to 'src/nvim/eval.c')
-rw-r--r-- | src/nvim/eval.c | 6 |
1 files changed, 5 insertions, 1 deletions
diff --git a/src/nvim/eval.c b/src/nvim/eval.c index ac659fbda4..2709f24998 100644 --- a/src/nvim/eval.c +++ b/src/nvim/eval.c @@ -9191,8 +9191,12 @@ static hashtab_T *find_var_ht_dict(const char *name, const size_t name_len, cons } else if (*name == 'l' && funccal != NULL) { // local variable *d = &funccal->l_vars; } else if (*name == 's' // script variable - && current_sctx.sc_sid > 0 + && (current_sctx.sc_sid > 0 || current_sctx.sc_sid == SID_STR) && current_sctx.sc_sid <= ga_scripts.ga_len) { + // For anonymous scripts without a script item, create one now so script vars can be used + if (current_sctx.sc_sid == SID_STR) { + new_script_item(NULL, ¤t_sctx.sc_sid); + } *d = &SCRIPT_SV(current_sctx.sc_sid)->sv_dict; } |