aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJunio C Hamano <gitster@pobox.com>2017-02-10 12:52:27 -0800
committerJunio C Hamano <gitster@pobox.com>2017-02-10 12:52:27 -0800
commitc1462b840517ec0d572b11848fefbd35e65a4f98 (patch)
tree486b7624629386655a368327a253f7637a7b5749
parente53c7f8731f7fa66864397d3d1ec1ad7c035c23a (diff)
parentbec5ab8997c2391fa2241520f52f301397ebd538 (diff)
downloadgit-c1462b840517ec0d572b11848fefbd35e65a4f98.tar.gz
git-c1462b840517ec0d572b11848fefbd35e65a4f98.tar.xz
Merge branch 'rs/fill-directory-optim'
Code clean-up. * rs/fill-directory-optim: dir: avoid allocation in fill_directory()
-rw-r--r--dir.c7
1 files changed, 3 insertions, 4 deletions
diff --git a/dir.c b/dir.c
index 65c3e681b..4541f9e14 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;
}