Mercurial > vim
comparison src/main.c @ 18991:847cc7932c42 v8.2.0056
patch 8.2.0056: execution stack is incomplete and inefficient
Commit: https://github.com/vim/vim/commit/1a47ae32cdc19b0fd5a82e19fe5fddf45db1a506
Author: Bram Moolenaar <Bram@vim.org>
Date: Sun Dec 29 23:04:25 2019 +0100
patch 8.2.0056: execution stack is incomplete and inefficient
Problem: Execution stack is incomplete and inefficient.
Solution: Introduce a proper execution stack and use it instead of
sourcing_name/sourcing_lnum. Create a string only when used.
author | Bram Moolenaar <Bram@vim.org> |
---|---|
date | Sun, 29 Dec 2019 23:15:04 +0100 |
parents | 5c405689da3e |
children | af1eca322b9e |
comparison
equal
deleted
inserted
replaced
18990:1219ae40b086 | 18991:847cc7932c42 |
---|---|
909 * Initialisation shared by main() and some tests. | 909 * Initialisation shared by main() and some tests. |
910 */ | 910 */ |
911 void | 911 void |
912 common_init(mparm_T *paramp) | 912 common_init(mparm_T *paramp) |
913 { | 913 { |
914 estack_init(); | |
914 cmdline_init(); | 915 cmdline_init(); |
915 | 916 |
916 (void)mb_init(); // init mb_bytelen_tab[] to ones | 917 (void)mb_init(); // init mb_bytelen_tab[] to ones |
917 #ifdef FEAT_EVAL | 918 #ifdef FEAT_EVAL |
918 eval_init(); // init global variables | 919 eval_init(); // init global variables |
3087 int i; | 3088 int i; |
3088 | 3089 |
3089 if (cnt > 0) | 3090 if (cnt > 0) |
3090 { | 3091 { |
3091 curwin->w_cursor.lnum = 0; // just in case.. | 3092 curwin->w_cursor.lnum = 0; // just in case.. |
3092 sourcing_name = (char_u *)_("pre-vimrc command line"); | 3093 estack_push(ETYPE_ARGS, (char_u *)_("pre-vimrc command line"), 0); |
3093 # ifdef FEAT_EVAL | 3094 # ifdef FEAT_EVAL |
3094 current_sctx.sc_sid = SID_CMDARG; | 3095 current_sctx.sc_sid = SID_CMDARG; |
3095 # endif | 3096 # endif |
3096 for (i = 0; i < cnt; ++i) | 3097 for (i = 0; i < cnt; ++i) |
3097 do_cmdline_cmd(cmds[i]); | 3098 do_cmdline_cmd(cmds[i]); |
3098 sourcing_name = NULL; | 3099 estack_pop(); |
3099 # ifdef FEAT_EVAL | 3100 # ifdef FEAT_EVAL |
3100 current_sctx.sc_sid = 0; | 3101 current_sctx.sc_sid = 0; |
3101 # endif | 3102 # endif |
3102 TIME_MSG("--cmd commands"); | 3103 TIME_MSG("--cmd commands"); |
3103 } | 3104 } |
3117 * with g`" was used. | 3118 * with g`" was used. |
3118 */ | 3119 */ |
3119 msg_scroll = TRUE; | 3120 msg_scroll = TRUE; |
3120 if (parmp->tagname == NULL && curwin->w_cursor.lnum <= 1) | 3121 if (parmp->tagname == NULL && curwin->w_cursor.lnum <= 1) |
3121 curwin->w_cursor.lnum = 0; | 3122 curwin->w_cursor.lnum = 0; |
3122 sourcing_name = (char_u *)"command line"; | 3123 estack_push(ETYPE_ARGS, (char_u *)"command line", 0); |
3123 #ifdef FEAT_EVAL | 3124 #ifdef FEAT_EVAL |
3124 current_sctx.sc_sid = SID_CARG; | 3125 current_sctx.sc_sid = SID_CARG; |
3125 current_sctx.sc_seq = 0; | 3126 current_sctx.sc_seq = 0; |
3126 #endif | 3127 #endif |
3127 for (i = 0; i < parmp->n_commands; ++i) | 3128 for (i = 0; i < parmp->n_commands; ++i) |
3128 { | 3129 { |
3129 do_cmdline_cmd(parmp->commands[i]); | 3130 do_cmdline_cmd(parmp->commands[i]); |
3130 if (parmp->cmds_tofree[i]) | 3131 if (parmp->cmds_tofree[i]) |
3131 vim_free(parmp->commands[i]); | 3132 vim_free(parmp->commands[i]); |
3132 } | 3133 } |
3133 sourcing_name = NULL; | 3134 estack_pop(); |
3134 #ifdef FEAT_EVAL | 3135 #ifdef FEAT_EVAL |
3135 current_sctx.sc_sid = 0; | 3136 current_sctx.sc_sid = 0; |
3136 #endif | 3137 #endif |
3137 if (curwin->w_cursor.lnum == 0) | 3138 if (curwin->w_cursor.lnum == 0) |
3138 curwin->w_cursor.lnum = 1; | 3139 curwin->w_cursor.lnum = 1; |
3334 process_env( | 3335 process_env( |
3335 char_u *env, | 3336 char_u *env, |
3336 int is_viminit) // when TRUE, called for VIMINIT | 3337 int is_viminit) // when TRUE, called for VIMINIT |
3337 { | 3338 { |
3338 char_u *initstr; | 3339 char_u *initstr; |
3339 char_u *save_sourcing_name; | |
3340 linenr_T save_sourcing_lnum; | |
3341 #ifdef FEAT_EVAL | 3340 #ifdef FEAT_EVAL |
3342 sctx_T save_current_sctx; | 3341 sctx_T save_current_sctx; |
3343 #endif | 3342 #endif |
3344 | 3343 |
3345 if ((initstr = mch_getenv(env)) != NULL && *initstr != NUL) | 3344 if ((initstr = mch_getenv(env)) != NULL && *initstr != NUL) |
3346 { | 3345 { |
3347 if (is_viminit) | 3346 if (is_viminit) |
3348 vimrc_found(NULL, NULL); | 3347 vimrc_found(NULL, NULL); |
3349 save_sourcing_name = sourcing_name; | 3348 estack_push(ETYPE_ENV, env, 0); |
3350 save_sourcing_lnum = sourcing_lnum; | |
3351 sourcing_name = env; | |
3352 sourcing_lnum = 0; | |
3353 #ifdef FEAT_EVAL | 3349 #ifdef FEAT_EVAL |
3354 save_current_sctx = current_sctx; | 3350 save_current_sctx = current_sctx; |
3355 current_sctx.sc_sid = SID_ENV; | 3351 current_sctx.sc_sid = SID_ENV; |
3356 current_sctx.sc_seq = 0; | 3352 current_sctx.sc_seq = 0; |
3357 current_sctx.sc_lnum = 0; | 3353 current_sctx.sc_lnum = 0; |
3358 current_sctx.sc_version = 1; | 3354 current_sctx.sc_version = 1; |
3359 #endif | 3355 #endif |
3360 do_cmdline_cmd(initstr); | 3356 do_cmdline_cmd(initstr); |
3361 sourcing_name = save_sourcing_name; | 3357 |
3362 sourcing_lnum = save_sourcing_lnum; | 3358 estack_pop(); |
3363 #ifdef FEAT_EVAL | 3359 #ifdef FEAT_EVAL |
3364 current_sctx = save_current_sctx; | 3360 current_sctx = save_current_sctx; |
3365 #endif | 3361 #endif |
3366 return OK; | 3362 return OK; |
3367 } | 3363 } |