]> git.ipfire.org Git - thirdparty/vim.git/commitdiff
patch 9.1.2030: inefficient use of ga_concat() v9.1.2030
authorJohn Marriott <basilisk@internode.on.net>
Sun, 28 Dec 2025 14:14:41 +0000 (14:14 +0000)
committerChristian Brabandt <cb@256bit.org>
Sun, 28 Dec 2025 14:14:41 +0000 (14:14 +0000)
Problem:  inefficient use of ga_concat()
Solution: Use ga_concat_len() when length is known.
          (John Marriott)

closes: #19027

Signed-off-by: John Marriott <basilisk@internode.on.net>
Signed-off-by: Christian Brabandt <cb@256bit.org>
src/cmdexpand.c
src/dict.c
src/getchar.c
src/if_xcmdsrv.c
src/job.c
src/os_mswin.c
src/regexp_nfa.c
src/scriptfile.c
src/userfunc.c
src/version.c
src/vim9execute.c

index 5cdc55b3119012ee7595d1293b18c9fd93f41f45..143f4c4917ca14cd97432020b579f25be812eb52 100644 (file)
@@ -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
index 4dadebc6be5dba40b556d6ca0aa0f8f02a38f4c2..f539250af9b3d29e9bb3e26de39f94b985fa8d0b 100644 (file)
@@ -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)
index bc2bcfdb57d5840353f351add990efb682412d7d..9bfa2b7598f3d62a9b43663d3aba994d6cbdfb1d 100644 (file)
@@ -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
        {
index 03358f3e99094a902ee6a05a254e1bc37a2531f3..2c12672a82bb4607c5dffbd0ffcd7dee04293b85 100644 (file)
@@ -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,
index cfd36adf9cf0eec1682990c1010051b228f235cb..37df1e89b1ef996d185079b14b9e7d3a1473a7dd 100644 (file)
--- 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);
index 2cf1be9d79adff6123d5a46428f564fa1bafb4ff..0869772e7af76617a3df6e912c0439bf8de8ea75 100644 (file)
@@ -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;
 }
 
index 7c28ac070c193e46a60e4580019b3678e6822c2a..8e4b30f87238a2004966f859f370c7485501aa9c 100644 (file)
@@ -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);
index 008818e0236412cc7c5fee908fe6785cbd4742d3..74ca9e1ccd9cd1bdb29b61a997dbb70c5ddeb09b 100644 (file)
@@ -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);
                    }
                }
index cb8fc231fb0bdd0f803da768162c99ec79b8e1cc..479e220544454db8a0905afc756b4ccb10fbe1db 100644 (file)
@@ -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
index b98a84e0d3b312180abb86388487f5a0fe889a73..14628eed34b592d214b087f05654be5593981361 100644 (file)
@@ -734,6 +734,8 @@ static char *(features[]) =
 
 static int included_patches[] =
 {   /* Add new patch number below this line */
+/**/
+    2030,
 /**/
     2029,
 /**/
index 3980125a7a44d2309e8b28adb64c8be919cc8081..2fc6da8d7574883cfbcf2c98b2653ecfb41d4350 100644 (file)
@@ -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;