diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/nvim/eval.c | 6 | ||||
-rw-r--r-- | src/nvim/ex_cmds.c | 8 | ||||
-rw-r--r-- | src/nvim/ex_cmds2.c | 8 | ||||
-rw-r--r-- | src/nvim/ex_getln.c | 11 | ||||
-rw-r--r-- | src/nvim/garray.c | 5 | ||||
-rw-r--r-- | src/nvim/garray.h | 6 | ||||
-rw-r--r-- | src/nvim/os/users.c | 5 | ||||
-rw-r--r-- | src/nvim/path.c | 16 | ||||
-rw-r--r-- | src/nvim/spell.c | 3 | ||||
-rw-r--r-- | src/nvim/syntax.c | 4 | ||||
-rw-r--r-- | src/nvim/tag.c | 3 | ||||
-rw-r--r-- | src/nvim/undo.c | 3 |
12 files changed, 25 insertions, 53 deletions
diff --git a/src/nvim/eval.c b/src/nvim/eval.c index 3abc148e8f..4e0f5c9137 100644 --- a/src/nvim/eval.c +++ b/src/nvim/eval.c @@ -14420,8 +14420,7 @@ error: } } - /* add a terminating NUL */ - ga_grow(&ga, 1); + // add a terminating NUL ga_append(&ga, NUL); rettv->vval.v_string = ga.ga_data; @@ -17640,8 +17639,7 @@ script_autoload ( else { /* Remember the name if it wasn't loaded already. */ if (i == ga_loaded.ga_len) { - ga_grow(&ga_loaded, 1); - ((char_u **)ga_loaded.ga_data)[ga_loaded.ga_len++] = scriptname; + GA_APPEND(char_u *, &ga_loaded, scriptname); tofree = NULL; } diff --git a/src/nvim/ex_cmds.c b/src/nvim/ex_cmds.c index fb6ec70f57..a04f93a851 100644 --- a/src/nvim/ex_cmds.c +++ b/src/nvim/ex_cmds.c @@ -5446,11 +5446,9 @@ helptags_one ( ga_init(&ga, (int)sizeof(char_u *), 100); if (add_help_tags || path_full_compare((char_u *)"$VIMRUNTIME/doc", dir, FALSE) == kEqualFiles) { - ga_grow(&ga, 1); s = xmalloc(18 + STRLEN(tagfname)); sprintf((char *)s, "help-tags\t%s\t1\n", tagfname); - ((char_u **)ga.ga_data)[ga.ga_len] = s; - ++ga.ga_len; + GA_APPEND(char_u *, &ga, s); } /* @@ -5517,10 +5515,8 @@ helptags_one ( || s[1] == '\0')) { *p2 = '\0'; ++p1; - ga_grow(&ga, 1); s = xmalloc((p2 - p1) + STRLEN(fname) + 2); - ((char_u **)ga.ga_data)[ga.ga_len] = s; - ++ga.ga_len; + GA_APPEND(char_u *, &ga, s); sprintf((char *)s, "%s\t%s", p1, fname); /* find next '*' */ diff --git a/src/nvim/ex_cmds2.c b/src/nvim/ex_cmds2.c index af6227d965..0b0026829f 100644 --- a/src/nvim/ex_cmds2.c +++ b/src/nvim/ex_cmds2.c @@ -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; diff --git a/src/nvim/ex_getln.c b/src/nvim/ex_getln.c index 9b09abb1b7..90430b3f6b 100644 --- a/src/nvim/ex_getln.c +++ b/src/nvim/ex_getln.c @@ -4000,10 +4000,7 @@ static int ExpandUserDefined(expand_T *xp, regmatch_T *regmatch, int *num_file, continue; } - ga_grow(&ga, 1); - - ((char_u **)ga.ga_data)[ga.ga_len] = vim_strnsave(s, (int)(e - s)); - ++ga.ga_len; + GA_APPEND(char_u *, &ga, vim_strnsave(s, (int)(e - s))); *e = keep; if (*e != NUL) @@ -4034,11 +4031,7 @@ static int ExpandUserList(expand_T *xp, int *num_file, char_u ***file) if (li->li_tv.v_type != VAR_STRING || li->li_tv.vval.v_string == NULL) continue; /* Skip non-string items and empty strings */ - ga_grow(&ga, 1); - - ((char_u **)ga.ga_data)[ga.ga_len] = - vim_strsave(li->li_tv.vval.v_string); - ++ga.ga_len; + GA_APPEND(char_u *, &ga, vim_strsave(li->li_tv.vval.v_string)); } list_unref(retlist); diff --git a/src/nvim/garray.c b/src/nvim/garray.c index aaf1b3bd2b..2cef08ef5f 100644 --- a/src/nvim/garray.c +++ b/src/nvim/garray.c @@ -197,10 +197,7 @@ void ga_concat(garray_T *gap, const char_u *restrict s) /// @param c void ga_append(garray_T *gap, char c) { - ga_grow(gap, 1); - char *str = gap->ga_data; - str[gap->ga_len] = c; - gap->ga_len++; + GA_APPEND(char, gap, c); } #if defined(UNIX) || defined(WIN3264) || defined(PROTO) diff --git a/src/nvim/garray.h b/src/nvim/garray.h index df5740c553..ed5e2dbada 100644 --- a/src/nvim/garray.h +++ b/src/nvim/garray.h @@ -16,6 +16,12 @@ typedef struct growarray { #define GA_EMPTY(ga_ptr) ((ga_ptr)->ga_len <= 0) +#define GA_APPEND(item_type, gap, item) \ + do { \ + ga_grow(gap, 1); \ + ((item_type *)(gap)->ga_data)[(gap)->ga_len++] = (item); \ + } while (0) + #ifdef INCLUDE_GENERATED_DECLARATIONS # include "garray.h.generated.h" #endif diff --git a/src/nvim/os/users.c b/src/nvim/os/users.c index e687ff3546..b6c013fa59 100644 --- a/src/nvim/os/users.c +++ b/src/nvim/os/users.c @@ -21,16 +21,13 @@ int os_get_usernames(garray_T *users) ga_init(users, sizeof(char *), 20); # if defined(HAVE_GETPWENT) && defined(HAVE_PWD_H) - char *user; struct passwd *pw; setpwent(); while ((pw = getpwent()) != NULL) { // pw->pw_name shouldn't be NULL but just in case... if (pw->pw_name != NULL) { - ga_grow(users, 1); - user = xstrdup(pw->pw_name); - ((char **)(users->ga_data))[users->ga_len++] = user; + GA_APPEND(char *, users, xstrdup(pw->pw_name)); } } endpwent(); diff --git a/src/nvim/path.c b/src/nvim/path.c index 093a13db7b..1231d16ed8 100644 --- a/src/nvim/path.c +++ b/src/nvim/path.c @@ -625,7 +625,6 @@ static void expand_path_option(char_u *curdir, garray_T *gap) char_u *path_option = *curbuf->b_p_path == NUL ? p_path : curbuf->b_p_path; char_u *buf; - char_u *p; int len; buf = xmalloc(MAXPATHL); @@ -639,7 +638,7 @@ static void expand_path_option(char_u *curdir, garray_T *gap) * "/path/file" + "./subdir" -> "/path/subdir" */ if (curbuf->b_ffname == NULL) continue; - p = path_tail(curbuf->b_ffname); + char_u *p = path_tail(curbuf->b_ffname); len = (int)(p - curbuf->b_ffname); if (len + (int)STRLEN(buf) >= MAXPATHL) continue; @@ -666,10 +665,7 @@ static void expand_path_option(char_u *curdir, garray_T *gap) simplify_filename(buf); } - ga_grow(gap, 1); - - p = vim_strsave(buf); - ((char_u **)gap->ga_data)[gap->ga_len++] = p; + GA_APPEND(char_u *, gap, vim_strsave(buf)); } free(buf); @@ -1194,7 +1190,6 @@ addfile ( int flags ) { - char_u *p; bool isdir; /* if the file/dir doesn't exist, may not add it */ @@ -1215,10 +1210,7 @@ addfile ( if (!isdir && (flags & EW_EXEC) && !os_can_exe(f)) return; - /* Make room for another item in the file list. */ - ga_grow(gap, 1); - - p = xmalloc(STRLEN(f) + 1 + isdir); + char_u *p = xmalloc(STRLEN(f) + 1 + isdir); STRCPY(p, f); #ifdef BACKSLASH_IN_FILENAME @@ -1231,7 +1223,7 @@ addfile ( if (isdir && (flags & EW_ADDSLASH)) add_pathsep(p); #endif - ((char_u **)gap->ga_data)[gap->ga_len++] = p; + GA_APPEND(char_u *, gap, p); } #endif /* !NO_EXPANDPATH */ diff --git a/src/nvim/spell.c b/src/nvim/spell.c index ca522191b9..711f892d16 100644 --- a/src/nvim/spell.c +++ b/src/nvim/spell.c @@ -9138,8 +9138,7 @@ someerror: if (c < 0) { goto someerror; } - ga_grow(&ga, 1); - ((char_u *)ga.ga_data)[ga.ga_len++] = c; + GA_APPEND(char_u, &ga, c); if (c == NUL) break; } diff --git a/src/nvim/syntax.c b/src/nvim/syntax.c index cb83bf650c..945172564b 100644 --- a/src/nvim/syntax.c +++ b/src/nvim/syntax.c @@ -1963,9 +1963,7 @@ syn_current_attr ( /* Add the index to a list, so that we can check * later that we don't match it again (and cause an * endless loop). */ - ga_grow(&zero_width_next_ga, 1); - ((int *)(zero_width_next_ga.ga_data)) - [zero_width_next_ga.ga_len++] = next_match_idx; + GA_APPEND(int, &zero_width_next_ga, next_match_idx); next_match_idx = -1; } else cur_si = push_next_match(cur_si); diff --git a/src/nvim/tag.c b/src/nvim/tag.c index c9a065391b..8c873283f0 100644 --- a/src/nvim/tag.c +++ b/src/nvim/tag.c @@ -1995,8 +1995,7 @@ static garray_T tag_fnames = GA_EMPTY_INIT_VALUE; */ static void found_tagfile_cb(char_u *fname, void *cookie) { - ga_grow(&tag_fnames, 1); - ((char_u **)(tag_fnames.ga_data))[tag_fnames.ga_len++] = vim_strsave(fname); + GA_APPEND(char_u *, &tag_fnames, vim_strsave(fname)); } #if defined(EXITFREE) || defined(PROTO) diff --git a/src/nvim/undo.c b/src/nvim/undo.c index 37fa150aee..8fe05290c2 100644 --- a/src/nvim/undo.c +++ b/src/nvim/undo.c @@ -2249,7 +2249,6 @@ void ex_undolist(exarg_T *eap) while (uhp != NULL) { if (uhp->uh_prev.ptr == NULL && uhp->uh_walk != nomark && uhp->uh_walk != mark) { - ga_grow(&ga, 1); vim_snprintf((char *)IObuff, IOSIZE, "%6ld %7ld ", uhp->uh_seq, changes); u_add_time(IObuff + STRLEN(IObuff), IOSIZE - STRLEN(IObuff), @@ -2260,7 +2259,7 @@ void ex_undolist(exarg_T *eap) vim_snprintf_add((char *)IObuff, IOSIZE, " %3ld", uhp->uh_save_nr); } - ((char_u **)(ga.ga_data))[ga.ga_len++] = vim_strsave(IObuff); + GA_APPEND(char_u *, &ga, vim_strsave(IObuff)); } uhp->uh_walk = mark; |