From: John Marriott Date: Sun, 28 Dec 2025 14:14:41 +0000 (+0000) Subject: patch 9.1.2030: inefficient use of ga_concat() X-Git-Tag: v9.1.2030^0 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=32b801abc35b03e6f88021b29c24dd2411f7a065;p=thirdparty%2Fvim.git patch 9.1.2030: inefficient use of ga_concat() Problem: inefficient use of ga_concat() Solution: Use ga_concat_len() when length is known. (John Marriott) closes: #19027 Signed-off-by: John Marriott Signed-off-by: Christian Brabandt --- diff --git a/src/cmdexpand.c b/src/cmdexpand.c index 5cdc55b311..143f4c4917 100644 --- a/src/cmdexpand.c +++ b/src/cmdexpand.c @@ -4773,10 +4773,13 @@ copy_substring_from_pos(pos_T *start, pos_T *end, char_u **match, { for (lnum = start->lnum + 1; lnum < end->lnum; lnum++) { + int linelen; + line = ml_get(lnum); - if (ga_grow(&ga, ml_get_len(lnum) + 2) != OK) + linelen = (int)ml_get_len(lnum); + if (ga_grow(&ga, linelen + 2) != OK) return FAIL; - ga_concat(&ga, line); + ga_concat_len(&ga, line, linelen); if (exacttext) ga_concat_len(&ga, (char_u *)"\\n", 2); else diff --git a/src/dict.c b/src/dict.c index 4dadebc6be..f539250af9 100644 --- a/src/dict.c +++ b/src/dict.c @@ -817,7 +817,7 @@ dict2string(typval_T *tv, int copyID, int restore_copyID) if (first) first = FALSE; else - ga_concat(&ga, (char_u *)", "); + ga_concat_len(&ga, (char_u *)", ", 2); tofree = string_quote(hi->hi_key, FALSE); if (tofree != NULL) @@ -825,7 +825,7 @@ dict2string(typval_T *tv, int copyID, int restore_copyID) ga_concat(&ga, tofree); vim_free(tofree); } - ga_concat(&ga, (char_u *)": "); + ga_concat_len(&ga, (char_u *)": ", 2); s = echo_string_core(&HI2DI(hi)->di_tv, &tofree, numbuf, copyID, FALSE, restore_copyID, TRUE); if (s != NULL) diff --git a/src/getchar.c b/src/getchar.c index bc2bcfdb57..9bfa2b7598 100644 --- a/src/getchar.c +++ b/src/getchar.c @@ -4288,7 +4288,7 @@ getcmdkeycmd( } else if (c1 == K_SNR) { - ga_concat(&line_ga, (char_u *)""); + ga_concat_len(&line_ga, (char_u *)"", 5); } else { diff --git a/src/if_xcmdsrv.c b/src/if_xcmdsrv.c index 03358f3e99..2c12672a82 100644 --- a/src/if_xcmdsrv.c +++ b/src/if_xcmdsrv.c @@ -666,7 +666,7 @@ serverGetVimNames(Display *dpy) if (WindowValid(dpy, (Window)w)) { ga_concat(&ga, p + 1); - ga_concat(&ga, (char_u *)"\n"); + ga_concat_len(&ga, (char_u *)"\n", 1); } while (*p != 0) p++; @@ -1343,7 +1343,7 @@ server_parse_message( ga_concat(&reply, (char_u *)_(e_invalid_expression_received)); ga_append(&reply, 0); - ga_concat(&reply, (char_u *)"-c 1"); + ga_concat_len(&reply, (char_u *)"-c 1", 4); } ga_append(&reply, NUL); (void)AppendPropCarefully(dpy, resWindow, commProperty, diff --git a/src/job.c b/src/job.c index cfd36adf9c..37df1e89b1 100644 --- a/src/job.c +++ b/src/job.c @@ -1452,7 +1452,7 @@ job_start( for (i = 0; i < argc; ++i) { if (i > 0) - ga_concat(&ga, (char_u *)" "); + ga_concat_len(&ga, (char_u *)" ", 2); ga_concat(&ga, (char_u *)argv[i]); } ga_append(&ga, NUL); diff --git a/src/os_mswin.c b/src/os_mswin.c index 2cf1be9d79..0869772e7a 100644 --- a/src/os_mswin.c +++ b/src/os_mswin.c @@ -2246,7 +2246,7 @@ enumWindowsGetNames(HWND hwnd, LPARAM lparam) // Add the name to the list ga_concat(ga, (char_u *)server); - ga_concat(ga, (char_u *)"\n"); + ga_concat_len(ga, (char_u *)"\n", 1); return TRUE; } diff --git a/src/regexp_nfa.c b/src/regexp_nfa.c index 7c28ac070c..8e4b30f872 100644 --- a/src/regexp_nfa.c +++ b/src/regexp_nfa.c @@ -2891,16 +2891,16 @@ nfa_print_state2(FILE *debugf, nfa_state_T *state, garray_T *indent) // grow indent for state->out indent->ga_len -= 1; if (state->out1) - ga_concat(indent, (char_u *)"| "); + ga_concat_len(indent, (char_u *)"| ", 2); else - ga_concat(indent, (char_u *)" "); + ga_concat_len(indent, (char_u *)" ", 2); ga_append(indent, NUL); nfa_print_state2(debugf, state->out, indent); // replace last part of indent for state->out1 indent->ga_len -= 3; - ga_concat(indent, (char_u *)" "); + ga_concat_len(indent, (char_u *)" ", 2); ga_append(indent, NUL); nfa_print_state2(debugf, state->out1, indent); diff --git a/src/scriptfile.c b/src/scriptfile.c index 008818e023..74ca9e1ccd 100644 --- a/src/scriptfile.c +++ b/src/scriptfile.c @@ -2558,7 +2558,7 @@ getsourceline( ga_concat(&ga, p + 1); else if (*p == '|') { - ga_concat(&ga, (char_u *)" "); + ga_concat_len(&ga, (char_u *)" ", 1); ga_concat(&ga, p); } for (;;) @@ -2583,7 +2583,7 @@ getsourceline( ga_concat(&ga, p + 1); else { - ga_concat(&ga, (char_u *)" "); + ga_concat_len(&ga, (char_u *)" ", 1); ga_concat(&ga, p); } } diff --git a/src/userfunc.c b/src/userfunc.c index cb8fc231fb..479e220544 100644 --- a/src/userfunc.c +++ b/src/userfunc.c @@ -1405,7 +1405,7 @@ get_function_body( // For a :def function "python << EOF" concatenates all the lines, // to be used for the instruction later. ga_concat(&heredoc_ga, theline); - ga_concat(&heredoc_ga, (char_u *)"\n"); + ga_concat_len(&heredoc_ga, (char_u *)"\n", 1); p = vim_strnsave((char_u *)"", 0); } else diff --git a/src/version.c b/src/version.c index b98a84e0d3..14628eed34 100644 --- a/src/version.c +++ b/src/version.c @@ -734,6 +734,8 @@ static char *(features[]) = static int included_patches[] = { /* Add new patch number below this line */ +/**/ + 2030, /**/ 2029, /**/ diff --git a/src/vim9execute.c b/src/vim9execute.c index 3980125a7a..2fc6da8d75 100644 --- a/src/vim9execute.c +++ b/src/vim9execute.c @@ -1764,7 +1764,7 @@ do_2string(typval_T *tv, int is_2string_any, int tostring_flags) if (p != NULL) { ga_concat(&ga, p); - ga_concat(&ga, (char_u *)" "); + ga_concat_len(&ga, (char_u *)" ", 1); vim_free(p); } s = e + 1;