Mercurial > vim
comparison 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 |
comparison
equal
deleted
inserted
replaced
26728:71ae885c1426 | 26729:b969fdb8cd46 |
---|---|
395 STACK_TV_BOT(STACK_FRAME_IDX_OFF)->vval.v_number = ectx->ec_frame_idx; | 395 STACK_TV_BOT(STACK_FRAME_IDX_OFF)->vval.v_number = ectx->ec_frame_idx; |
396 ectx->ec_frame_idx = ectx->ec_stack.ga_len; | 396 ectx->ec_frame_idx = ectx->ec_stack.ga_len; |
397 | 397 |
398 // Initialize local variables | 398 // Initialize local variables |
399 for (idx = 0; idx < dfunc->df_varcount; ++idx) | 399 for (idx = 0; idx < dfunc->df_varcount; ++idx) |
400 STACK_TV_BOT(STACK_FRAME_SIZE + idx)->v_type = VAR_UNKNOWN; | 400 { |
401 typval_T *tv = STACK_TV_BOT(STACK_FRAME_SIZE + idx); | |
402 | |
403 tv->v_type = VAR_NUMBER; | |
404 tv->vval.v_number = 0; | |
405 } | |
401 if (dfunc->df_has_closure) | 406 if (dfunc->df_has_closure) |
402 { | 407 { |
403 typval_T *tv = STACK_TV_BOT(STACK_FRAME_SIZE + dfunc->df_varcount); | 408 typval_T *tv = STACK_TV_BOT(STACK_FRAME_SIZE + dfunc->df_varcount); |
404 | 409 |
405 tv->v_type = VAR_NUMBER; | 410 tv->v_type = VAR_NUMBER; |
5000 { | 5005 { |
5001 // Reserve space for local variables and any closure reference count. | 5006 // Reserve space for local variables and any closure reference count. |
5002 dfunc_T *dfunc = ((dfunc_T *)def_functions.ga_data) | 5007 dfunc_T *dfunc = ((dfunc_T *)def_functions.ga_data) |
5003 + ufunc->uf_dfunc_idx; | 5008 + ufunc->uf_dfunc_idx; |
5004 | 5009 |
5010 // Initialize variables to zero. That avoids having to generate | |
5011 // initializing instructions for "var nr: number", "var x: any", etc. | |
5005 for (idx = 0; idx < dfunc->df_varcount; ++idx) | 5012 for (idx = 0; idx < dfunc->df_varcount; ++idx) |
5006 STACK_TV_VAR(idx)->v_type = VAR_UNKNOWN; | 5013 { |
5014 STACK_TV_VAR(idx)->v_type = VAR_NUMBER; | |
5015 STACK_TV_VAR(idx)->vval.v_number = 0; | |
5016 } | |
5007 ectx.ec_stack.ga_len += dfunc->df_varcount; | 5017 ectx.ec_stack.ga_len += dfunc->df_varcount; |
5008 if (dfunc->df_has_closure) | 5018 if (dfunc->df_has_closure) |
5009 { | 5019 { |
5010 STACK_TV_VAR(idx)->v_type = VAR_NUMBER; | 5020 STACK_TV_VAR(idx)->v_type = VAR_NUMBER; |
5011 STACK_TV_VAR(idx)->vval.v_number = 0; | 5021 STACK_TV_VAR(idx)->vval.v_number = 0; |