Commit: patch 9.1.2030: inefficient use of ga_concat()

3 views
Skip to first unread message

Christian Brabandt

unread,
Dec 28, 2025, 9:31:00 AM (yesterday) Dec 28
to vim...@googlegroups.com
patch 9.1.2030: inefficient use of ga_concat()

Commit: https://github.com/vim/vim/commit/32b801abc35b03e6f88021b29c24dd2411f7a065
Author: John Marriott <basi...@internode.on.net>
Date: Sun Dec 28 14:14:41 2025 +0000

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 <basi...@internode.on.net>
Signed-off-by: Christian Brabandt <c...@256bit.org>

diff --git a/src/cmdexpand.c b/src/cmdexpand.c
index 5cdc55b31..143f4c491 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 4dadebc6b..f539250af 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 bc2bcfdb5..9bfa2b759 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 *)"<SNR>");
+ ga_concat_len(&line_ga, (char_u *)"<SNR>", 5);
}
else
{
diff --git a/src/if_xcmdsrv.c b/src/if_xcmdsrv.c
index 03358f3e9..2c12672a8 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 *)"
");
+ ga_concat_len(&ga, (char_u *)"
", 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 cfd36adf9..37df1e89b 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 2cf1be9d7..0869772e7 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 *)"
");
+ ga_concat_len(ga, (char_u *)"
", 1);
return TRUE;
}

diff --git a/src/regexp_nfa.c b/src/regexp_nfa.c
index 7c28ac070..8e4b30f87 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 008818e02..74ca9e1cc 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 cb8fc231f..479e22054 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 *)"
");
+ ga_concat_len(&heredoc_ga, (char_u *)"
", 1);
p = vim_strnsave((char_u *)"", 0);
}
else
diff --git a/src/version.c b/src/version.c
index b98a84e0d..14628eed3 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 3980125a7..2fc6da8d7 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;
Reply all
Reply to author
Forward
0 new messages