diff options
author | Felipe Oliveira Carvalho <felipekde@gmail.com> | 2014-06-25 22:03:58 -0300 |
---|---|---|
committer | Justin M. Keyes <justinkz@gmail.com> | 2014-06-30 03:57:50 -0400 |
commit | 45e7814e6aa8aacd8772056863d13770d4e30b48 (patch) | |
tree | 4a5f6f66176393da31454756af9f375cab804f6c /src/nvim/path.c | |
parent | be3a4b6ca81c4e9dd3faa81dc01f53468ceed3ad (diff) | |
download | rneovim-45e7814e6aa8aacd8772056863d13770d4e30b48.tar.gz rneovim-45e7814e6aa8aacd8772056863d13770d4e30b48.tar.bz2 rneovim-45e7814e6aa8aacd8772056863d13770d4e30b48.zip |
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;
Diffstat (limited to 'src/nvim/path.c')
-rw-r--r-- | src/nvim/path.c | 16 |
1 files changed, 4 insertions, 12 deletions
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 */ |