Introduce GA_APPEND()

This macro is used to append an element to a growable array. It replaces this
common idiom:

   ga_grow(&ga, 1);
   ((item_type *)ga.ga_data)[ga.ga_len] = item;
   ++ga.ga_len;
This commit is contained in:
Felipe Oliveira Carvalho
2014-06-25 22:03:58 -03:00
committed by Justin M. Keyes
parent be3a4b6ca8
commit 45e7814e6a
12 changed files with 25 additions and 53 deletions

View File

@@ -1525,8 +1525,7 @@ void get_arglist(garray_T *gap, char_u *str)
{
ga_init(gap, (int)sizeof(char_u *), 20);
while (*str != NUL) {
ga_grow(gap, 1);
((char_u **)gap->ga_data)[gap->ga_len++] = str;
GA_APPEND(char_u *, gap, str);
/* Isolate one argument, change it in-place, put a NUL after it. */
str = do_one_arg(str);
@@ -3332,13 +3331,12 @@ static char_u **find_locales(void)
loc = (char_u *)strtok((char *)locale_a, "\n");
while (loc != NULL) {
ga_grow(&locales_ga, 1);
loc = vim_strsave(loc);
((char_u **)locales_ga.ga_data)[locales_ga.ga_len++] = loc;
GA_APPEND(char_u *, &locales_ga, loc);
loc = (char_u *)strtok(NULL, "\n");
}
free(locale_a);
// Guarantee that .ga_data is NULL terminated
ga_grow(&locales_ga, 1);
((char_u **)locales_ga.ga_data)[locales_ga.ga_len] = NULL;
return (char_u **)locales_ga.ga_data;