aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNicolas Hillegeer <nicolas@hillegeer.com>2014-04-27 10:50:56 +0200
committerThiago de Arruda <tpadilha84@gmail.com>2014-04-29 09:29:10 -0300
commit852f0aaae8c82ed879df8bbe9cb1914002dad954 (patch)
treeb31774f3662b3b8b4d489ca0d0217d62fbdf5f74
parenteea98c4d3b695b9ca95db7ac33231e62cdf88ceb (diff)
downloadrneovim-852f0aaae8c82ed879df8bbe9cb1914002dad954.tar.gz
rneovim-852f0aaae8c82ed879df8bbe9cb1914002dad954.tar.bz2
rneovim-852f0aaae8c82ed879df8bbe9cb1914002dad954.zip
garray: comment and refactor a bit more
The following functions are affected: - ga_remove_duplicate_strings - ga_append
-rw-r--r--src/garray.c23
1 files changed, 15 insertions, 8 deletions
diff --git a/src/garray.c b/src/garray.c
index 1d9195d7ab..bb035935a8 100644
--- a/src/garray.c
+++ b/src/garray.c
@@ -76,24 +76,30 @@ void ga_grow(garray_T *gap, int n)
gap->ga_data = pp;
}
-/// Sort "gap" and remove duplicate entries. "gap" is expected to contain a
+/// Sort "gap" and remove duplicate entries. "gap" is expected to contain a
/// list of file names in allocated memory.
///
/// @param gap
void ga_remove_duplicate_strings(garray_T *gap)
{
- int i;
- int j;
- char_u **fnames = (char_u **)gap->ga_data;
+ char_u **fnames = gap->ga_data;
+ // sort the growing array, which puts duplicates next to each other
sort_strings(fnames, gap->ga_len);
- for (i = gap->ga_len - 1; i > 0; --i)
+
+ // loop over the growing array in reverse
+ for (int i = gap->ga_len - 1; i > 0; i--) {
if (fnamecmp(fnames[i - 1], fnames[i]) == 0) {
vim_free(fnames[i]);
- for (j = i + 1; j < gap->ga_len; ++j)
+
+ // close the gap (move all strings one slot lower)
+ for (int j = i + 1; j < gap->ga_len; j++) {
fnames[j - 1] = fnames[j];
+ }
+
--gap->ga_len;
}
+ }
}
/// For a growing array that contains a list of strings: concatenate all the
@@ -165,8 +171,9 @@ void ga_concat(garray_T *gap, const char_u *restrict s)
void ga_append(garray_T *gap, char c)
{
ga_grow(gap, 1);
- *((char *)gap->ga_data + gap->ga_len) = c;
- ++gap->ga_len;
+ char *str = gap->ga_data;
+ str[gap->ga_len] = c;
+ gap->ga_len++;
}
#if defined(UNIX) || defined(WIN3264)