aboutsummaryrefslogtreecommitdiff
path: root/src/garray.c
diff options
context:
space:
mode:
authorJohn Schmidt <john.schmidt.h@gmail.com>2014-03-27 18:53:20 +0100
committerThiago de Arruda <tpadilha84@gmail.com>2014-03-29 13:29:53 -0300
commit44e40b02cf53c95ab248b98df44ec3dd836bb4b5 (patch)
tree310e8a4957d70a1ba841e82cdb33d374c75028d6 /src/garray.c
parentf5154d7451c09b39ea6944795c59f86aaad393e0 (diff)
downloadrneovim-44e40b02cf53c95ab248b98df44ec3dd836bb4b5.tar.gz
rneovim-44e40b02cf53c95ab248b98df44ec3dd836bb4b5.tar.bz2
rneovim-44e40b02cf53c95ab248b98df44ec3dd836bb4b5.zip
Move remove_duplicates to garray.c
Diffstat (limited to 'src/garray.c')
-rw-r--r--src/garray.c21
1 files changed, 21 insertions, 0 deletions
diff --git a/src/garray.c b/src/garray.c
index aba4d5649f..8bf2b7477e 100644
--- a/src/garray.c
+++ b/src/garray.c
@@ -7,6 +7,7 @@
#include "vim.h"
#include "ascii.h"
#include "misc2.h"
+#include "path.h"
#include "garray.h"
// #include "globals.h"
@@ -86,6 +87,26 @@ int ga_grow(garray_T *gap, int n)
return OK;
}
+/// 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;
+
+ sort_strings(fnames, gap->ga_len);
+ for (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)
+ fnames[j - 1] = fnames[j];
+ --gap->ga_len;
+ }
+}
+
/// For a growing array that contains a list of strings: concatenate all the
/// strings with a separating comma.
///