Mercurial > vim
diff src/vim9compile.c @ 28598:d550054e1328 v8.2.4823
patch 8.2.4823: concat more than 2 strings in :def function is inefficient
Commit: https://github.com/vim/vim/commit/372bcceeee8012ef3fb2f3dbc8132c3a33cb84fc
Author: LemonBoy <thatlemon@gmail.com>
Date: Mon Apr 25 12:43:20 2022 +0100
patch 8.2.4823: concat more than 2 strings in :def function is inefficient
Problem: Concatenating more than 2 strings in a :def function is
inefficient.
Solution: Add a count to the CONCAT instruction. (closes #10276)
author | Bram Moolenaar <Bram@vim.org> |
---|---|
date | Mon, 25 Apr 2022 13:45:04 +0200 |
parents | 060fc3b69697 |
children | a16dae0be398 |
line wrap: on
line diff
--- a/src/vim9compile.c +++ b/src/vim9compile.c @@ -988,14 +988,12 @@ compile_heredoc_string(char_u *str, int if (evalstr && (p = (char_u *)strstr((char *)str, "`=")) != NULL) { char_u *start = str; + int count = 0; // Need to evaluate expressions of the form `=<expr>` in the string. // Split the string into literal strings and Vim expressions and // generate instructions to concatenate the literal strings and the // result of evaluating the Vim expressions. - val = vim_strsave((char_u *)""); - generate_PUSHS(cctx, &val); - for (;;) { if (p > start) @@ -1003,7 +1001,7 @@ compile_heredoc_string(char_u *str, int // literal string before the expression val = vim_strnsave(start, p - start); generate_PUSHS(cctx, &val); - generate_instr_drop(cctx, ISN_CONCAT, 1); + count++; } p += 2; @@ -1011,7 +1009,7 @@ compile_heredoc_string(char_u *str, int if (compile_expr0(&p, cctx) == FAIL) return FAIL; may_generate_2STRING(-1, TRUE, cctx); - generate_instr_drop(cctx, ISN_CONCAT, 1); + count++; p = skipwhite(p); if (*p != '`') @@ -1029,11 +1027,14 @@ compile_heredoc_string(char_u *str, int { val = vim_strsave(start); generate_PUSHS(cctx, &val); - generate_instr_drop(cctx, ISN_CONCAT, 1); + count++; } break; } } + + if (count > 1) + generate_CONCAT(cctx, count); } else { @@ -2382,7 +2383,7 @@ compile_assignment(char_u *arg, exarg_T if (*op == '.') { - if (generate_instr_drop(cctx, ISN_CONCAT, 1) == NULL) + if (generate_CONCAT(cctx, 2) == FAIL) goto theend; } else if (*op == '+')