Mercurial > vim
diff src/vim9execute.c @ 26729:b969fdb8cd46 v8.2.3893
patch 8.2.3893: Vim9: many local variables are initialized with an instruction
Commit: https://github.com/vim/vim/commit/5cd647935d0834b3064aa36384b8f6730fadadd6
Author: Bram Moolenaar <Bram@vim.org>
Date: Sat Dec 25 18:23:24 2021 +0000
patch 8.2.3893: Vim9: many local variables are initialized with an instruction
Problem: Vim9: many local variables are initialized with an instruction.
Solution: Initialize local variables to zero to avoid the instructions.
author | Bram Moolenaar <Bram@vim.org> |
---|---|
date | Sat, 25 Dec 2021 19:30:03 +0100 |
parents | 254fffd11fda |
children | a8a4e1e7b111 |
line wrap: on
line diff
--- a/src/vim9execute.c +++ b/src/vim9execute.c @@ -397,7 +397,12 @@ call_dfunc( // Initialize local variables for (idx = 0; idx < dfunc->df_varcount; ++idx) - STACK_TV_BOT(STACK_FRAME_SIZE + idx)->v_type = VAR_UNKNOWN; + { + typval_T *tv = STACK_TV_BOT(STACK_FRAME_SIZE + idx); + + tv->v_type = VAR_NUMBER; + tv->vval.v_number = 0; + } if (dfunc->df_has_closure) { typval_T *tv = STACK_TV_BOT(STACK_FRAME_SIZE + dfunc->df_varcount); @@ -5002,8 +5007,13 @@ call_def_function( dfunc_T *dfunc = ((dfunc_T *)def_functions.ga_data) + ufunc->uf_dfunc_idx; + // Initialize variables to zero. That avoids having to generate + // initializing instructions for "var nr: number", "var x: any", etc. for (idx = 0; idx < dfunc->df_varcount; ++idx) - STACK_TV_VAR(idx)->v_type = VAR_UNKNOWN; + { + STACK_TV_VAR(idx)->v_type = VAR_NUMBER; + STACK_TV_VAR(idx)->vval.v_number = 0; + } ectx.ec_stack.ga_len += dfunc->df_varcount; if (dfunc->df_has_closure) {