summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRené Scharfe <l.s.r@web.de>2017-02-07 23:04:25 +0100
committerJunio C Hamano <gitster@pobox.com>2017-02-08 13:38:41 -0800
commitbec5ab8997c2391fa2241520f52f301397ebd538 (patch)
tree2c1f914fd26d48deaaf5be42bd5fea5bb1ee96aa
parent6e3a7b3398559305c7a239a42e447c21a8f39ff8 (diff)
downloadgit-rs/fill-directory-optim.tar.gz
dir: avoid allocation in fill_directory()rs/fill-directory-optim
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>
-rw-r--r--dir.c7
1 files changed, 3 insertions, 4 deletions
diff --git a/dir.c b/dir.c
index 65c3e681b8..4541f9e146 100644
--- a/dir.c
+++ b/dir.c
@@ -174,20 +174,19 @@ char *common_prefix(const struct pathspec *pathspec)
int fill_directory(struct dir_struct *dir, const struct pathspec *pathspec)
{
- char *prefix;
+ const char *prefix;
size_t prefix_len;
/*
* Calculate common prefix for the pathspec, and
* use that to optimize the directory walk
*/
- prefix = common_prefix(pathspec);
- prefix_len = prefix ? strlen(prefix) : 0;
+ prefix_len = common_prefix_len(pathspec);
+ prefix = prefix_len ? pathspec->items[0].match : "";
/* Read the directory and prune it */
read_directory(dir, prefix, prefix_len, pathspec);
- free(prefix);
return prefix_len;
}