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.
diff --git a/src/vim9execute.c b/src/vim9execute.c
index 72cbb90..49336c0 100644
--- a/src/vim9execute.c
+++ b/src/vim9execute.c
@@ -397,7 +397,12 @@
// 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 @@
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)
{