Skip to content

Commit 32b801a

Browse files
John Marriottchrisbra
authored andcommitted
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 <[email protected]> Signed-off-by: Christian Brabandt <[email protected]>
1 parent 1dd301a commit 32b801a

11 files changed

Lines changed: 21 additions & 16 deletions

File tree

src/cmdexpand.c

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4773,10 +4773,13 @@ copy_substring_from_pos(pos_T *start, pos_T *end, char_u **match,
47734773
{
47744774
for (lnum = start->lnum + 1; lnum < end->lnum; lnum++)
47754775
{
4776+
int linelen;
4777+
47764778
line = ml_get(lnum);
4777-
if (ga_grow(&ga, ml_get_len(lnum) + 2) != OK)
4779+
linelen = (int)ml_get_len(lnum);
4780+
if (ga_grow(&ga, linelen + 2) != OK)
47784781
return FAIL;
4779-
ga_concat(&ga, line);
4782+
ga_concat_len(&ga, line, linelen);
47804783
if (exacttext)
47814784
ga_concat_len(&ga, (char_u *)"\\n", 2);
47824785
else

src/dict.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -817,15 +817,15 @@ dict2string(typval_T *tv, int copyID, int restore_copyID)
817817
if (first)
818818
first = FALSE;
819819
else
820-
ga_concat(&ga, (char_u *)", ");
820+
ga_concat_len(&ga, (char_u *)", ", 2);
821821

822822
tofree = string_quote(hi->hi_key, FALSE);
823823
if (tofree != NULL)
824824
{
825825
ga_concat(&ga, tofree);
826826
vim_free(tofree);
827827
}
828-
ga_concat(&ga, (char_u *)": ");
828+
ga_concat_len(&ga, (char_u *)": ", 2);
829829
s = echo_string_core(&HI2DI(hi)->di_tv, &tofree, numbuf, copyID,
830830
FALSE, restore_copyID, TRUE);
831831
if (s != NULL)

src/getchar.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4288,7 +4288,7 @@ getcmdkeycmd(
42884288
}
42894289
else if (c1 == K_SNR)
42904290
{
4291-
ga_concat(&line_ga, (char_u *)"<SNR>");
4291+
ga_concat_len(&line_ga, (char_u *)"<SNR>", 5);
42924292
}
42934293
else
42944294
{

src/if_xcmdsrv.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -666,7 +666,7 @@ serverGetVimNames(Display *dpy)
666666
if (WindowValid(dpy, (Window)w))
667667
{
668668
ga_concat(&ga, p + 1);
669-
ga_concat(&ga, (char_u *)"\n");
669+
ga_concat_len(&ga, (char_u *)"\n", 1);
670670
}
671671
while (*p != 0)
672672
p++;
@@ -1343,7 +1343,7 @@ server_parse_message(
13431343
ga_concat(&reply,
13441344
(char_u *)_(e_invalid_expression_received));
13451345
ga_append(&reply, 0);
1346-
ga_concat(&reply, (char_u *)"-c 1");
1346+
ga_concat_len(&reply, (char_u *)"-c 1", 4);
13471347
}
13481348
ga_append(&reply, NUL);
13491349
(void)AppendPropCarefully(dpy, resWindow, commProperty,

src/job.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1452,7 +1452,7 @@ job_start(
14521452
for (i = 0; i < argc; ++i)
14531453
{
14541454
if (i > 0)
1455-
ga_concat(&ga, (char_u *)" ");
1455+
ga_concat_len(&ga, (char_u *)" ", 2);
14561456
ga_concat(&ga, (char_u *)argv[i]);
14571457
}
14581458
ga_append(&ga, NUL);

src/os_mswin.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2246,7 +2246,7 @@ enumWindowsGetNames(HWND hwnd, LPARAM lparam)
22462246

22472247
// Add the name to the list
22482248
ga_concat(ga, (char_u *)server);
2249-
ga_concat(ga, (char_u *)"\n");
2249+
ga_concat_len(ga, (char_u *)"\n", 1);
22502250
return TRUE;
22512251
}
22522252

src/regexp_nfa.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2891,16 +2891,16 @@ nfa_print_state2(FILE *debugf, nfa_state_T *state, garray_T *indent)
28912891
// grow indent for state->out
28922892
indent->ga_len -= 1;
28932893
if (state->out1)
2894-
ga_concat(indent, (char_u *)"| ");
2894+
ga_concat_len(indent, (char_u *)"| ", 2);
28952895
else
2896-
ga_concat(indent, (char_u *)" ");
2896+
ga_concat_len(indent, (char_u *)" ", 2);
28972897
ga_append(indent, NUL);
28982898

28992899
nfa_print_state2(debugf, state->out, indent);
29002900

29012901
// replace last part of indent for state->out1
29022902
indent->ga_len -= 3;
2903-
ga_concat(indent, (char_u *)" ");
2903+
ga_concat_len(indent, (char_u *)" ", 2);
29042904
ga_append(indent, NUL);
29052905

29062906
nfa_print_state2(debugf, state->out1, indent);

src/scriptfile.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2558,7 +2558,7 @@ getsourceline(
25582558
ga_concat(&ga, p + 1);
25592559
else if (*p == '|')
25602560
{
2561-
ga_concat(&ga, (char_u *)" ");
2561+
ga_concat_len(&ga, (char_u *)" ", 1);
25622562
ga_concat(&ga, p);
25632563
}
25642564
for (;;)
@@ -2583,7 +2583,7 @@ getsourceline(
25832583
ga_concat(&ga, p + 1);
25842584
else
25852585
{
2586-
ga_concat(&ga, (char_u *)" ");
2586+
ga_concat_len(&ga, (char_u *)" ", 1);
25872587
ga_concat(&ga, p);
25882588
}
25892589
}

src/userfunc.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1405,7 +1405,7 @@ get_function_body(
14051405
// For a :def function "python << EOF" concatenates all the lines,
14061406
// to be used for the instruction later.
14071407
ga_concat(&heredoc_ga, theline);
1408-
ga_concat(&heredoc_ga, (char_u *)"\n");
1408+
ga_concat_len(&heredoc_ga, (char_u *)"\n", 1);
14091409
p = vim_strnsave((char_u *)"", 0);
14101410
}
14111411
else

src/version.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -734,6 +734,8 @@ static char *(features[]) =
734734

735735
static int included_patches[] =
736736
{ /* Add new patch number below this line */
737+
/**/
738+
2030,
737739
/**/
738740
2029,
739741
/**/

0 commit comments

Comments
 (0)