From 44e40b02cf53c95ab248b98df44ec3dd836bb4b5 Mon Sep 17 00:00:00 2001 From: John Schmidt Date: Thu, 27 Mar 2014 18:53:20 +0100 Subject: Move remove_duplicates to garray.c --- src/garray.c | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) (limited to 'src/garray.c') 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. /// -- cgit