dir: avoid allocation in fill_directory()
Pass the match member of the first pathspec item directly to read_directory() instead of using common_prefix() to duplicate it first, thus avoiding memory duplication, strlen(3) and free(3). Signed-off-by: Rene Scharfe <l.s.r@web.de> Signed-off-by: Junio C Hamano <gitster@pobox.com>
This commit is contained in:
parent
6e3a7b3398
commit
bec5ab8997
7
dir.c
7
dir.c
@ -174,20 +174,19 @@ char *common_prefix(const struct pathspec *pathspec)
|
|||||||
|
|
||||||
int fill_directory(struct dir_struct *dir, const struct pathspec *pathspec)
|
int fill_directory(struct dir_struct *dir, const struct pathspec *pathspec)
|
||||||
{
|
{
|
||||||
char *prefix;
|
const char *prefix;
|
||||||
size_t prefix_len;
|
size_t prefix_len;
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Calculate common prefix for the pathspec, and
|
* Calculate common prefix for the pathspec, and
|
||||||
* use that to optimize the directory walk
|
* use that to optimize the directory walk
|
||||||
*/
|
*/
|
||||||
prefix = common_prefix(pathspec);
|
prefix_len = common_prefix_len(pathspec);
|
||||||
prefix_len = prefix ? strlen(prefix) : 0;
|
prefix = prefix_len ? pathspec->items[0].match : "";
|
||||||
|
|
||||||
/* Read the directory and prune it */
|
/* Read the directory and prune it */
|
||||||
read_directory(dir, prefix, prefix_len, pathspec);
|
read_directory(dir, prefix, prefix_len, pathspec);
|
||||||
|
|
||||||
free(prefix);
|
|
||||||
return prefix_len;
|
return prefix_len;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user