Commit 44e40b02 authored by John Schmidt's avatar John Schmidt Committed by Thiago de Arruda

Move remove_duplicates to garray.c

parent f5154d74
......@@ -4207,7 +4207,7 @@ static int ExpandRTDir(char_u *pat, int *num_file, char_u ***file, char *dirname
/* Sort and remove duplicates which can happen when specifying multiple
* directories in dirnames. */
remove_duplicates(&ga);
ga_remove_duplicate_strings(&ga);
*file = ga.ga_data;
*num_file = ga.ga_len;
......
......@@ -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.
///
......
......@@ -20,6 +20,7 @@ void ga_init(garray_T *gap);
void ga_init2(garray_T *gap, int itemsize, int growsize);
int ga_grow(garray_T *gap, int n);
char_u *ga_concat_strings(garray_T *gap);
void ga_remove_duplicate_strings(garray_T *gap);
void ga_concat(garray_T *gap, char_u *s);
void ga_append(garray_T *gap, int c);
void append_ga_line(garray_T *gap);
......
......@@ -4,17 +4,17 @@
#include "eval.h"
#include "ex_getln.h"
#include "fileio.h"
#include "garray.h"
#include "memline.h"
#include "misc1.h"
#include "misc2.h"
#include "garray.h"
#include "types.h"
#include "os/os.h"
#include "os_unix.h"
#include "regexp.h"
#include "tag.h"
#include "types.h"
#include "ui.h"
#include "window.h"
#include "os/os.h"
/*
* Compare two file names and return:
......@@ -801,7 +801,7 @@ static void uniquefy_paths(garray_T *gap, char_u *pattern)
char_u **in_curdir = NULL;
char_u *short_name;
remove_duplicates(gap);
ga_remove_duplicate_strings(gap);
ga_init2(&path_ga, (int)sizeof(char_u *), 1);
/*
......@@ -930,7 +930,7 @@ theend:
vim_regfree(regmatch.regprog);
if (sort_again)
remove_duplicates(gap);
ga_remove_duplicate_strings(gap);
}
/*
......@@ -993,25 +993,6 @@ expand_in_path (
return gap->ga_len;
}
/*
* Sort "gap" and remove duplicate entries. "gap" is expected to contain a
* list of file names in allocated memory.
*/
void remove_duplicates(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;
}
}
static int has_env_var(char_u *p);
......
......@@ -10,7 +10,6 @@ int vim_fnamencmp(char_u *x, char_u *y, size_t len);
char_u *concat_fnames(char_u *fname1, char_u *fname2, int sep);
int unix_expandpath(garray_T *gap, char_u *path, int wildoff, int flags,
int didstar);
void remove_duplicates(garray_T *gap);
int gen_expand_wildcards(int num_pat, char_u **pat, int *num_file,
char_u ***file,
int flags);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment