summaryrefslogtreecommitdiff
path: root/tree-walk.c
diff options
context:
space:
mode:
authorDavid Turner <dturner@twopensource.com>2015-12-21 17:34:20 -0500
committerJunio C Hamano <gitster@pobox.com>2016-01-05 13:39:46 -0800
commitd9c2bd560e1e7a3d4654fb6ef3f9037ad337eb01 (patch)
tree04df29e0820e079bf4c90570b6e1adf39af5a1ac /tree-walk.c
parentf3adf457e046f92f039353762a78dcb3afb2cb13 (diff)
downloadgit-d9c2bd560e1e7a3d4654fb6ef3f9037ad337eb01.tar.gz
do_compare_entry: use already-computed path
In traverse_trees, we generate the complete traverse path for a traverse_info. Later, in do_compare_entry, we used to go do a bunch of work to compare the traverse_info to a cache_entry's name without computing that path. But since we already have that path, we don't need to do all that work. Instead, we can just put the generated path into the traverse_info, and do the comparison more directly. We copy the path because prune_traversal might mutate `base`. This doesn't happen in any codepaths where do_compare_entry is called, but it's better to be safe. This makes git checkout much faster -- about 25% on Twitter's monorepo. Deeper directory trees are likely to benefit more than shallower ones. Signed-off-by: David Turner <dturner@twopensource.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Diffstat (limited to 'tree-walk.c')
-rw-r--r--tree-walk.c7
1 files changed, 7 insertions, 0 deletions
diff --git a/tree-walk.c b/tree-walk.c
index 6dccd2d5dd..cd4bb2c38b 100644
--- a/tree-walk.c
+++ b/tree-walk.c
@@ -320,6 +320,7 @@ int traverse_trees(int n, struct tree_desc *t, struct traverse_info *info)
struct tree_desc_x *tx = xcalloc(n, sizeof(*tx));
struct strbuf base = STRBUF_INIT;
int interesting = 1;
+ char *traverse_path;
for (i = 0; i < n; i++)
tx[i].d = t[i];
@@ -329,7 +330,11 @@ int traverse_trees(int n, struct tree_desc *t, struct traverse_info *info)
make_traverse_path(base.buf, info->prev, &info->name);
base.buf[info->pathlen-1] = '/';
strbuf_setlen(&base, info->pathlen);
+ traverse_path = xstrndup(base.buf, info->pathlen);
+ } else {
+ traverse_path = xstrndup(info->name.path, info->pathlen);
}
+ info->traverse_path = traverse_path;
for (;;) {
int trees_used;
unsigned long mask, dirmask;
@@ -411,6 +416,8 @@ int traverse_trees(int n, struct tree_desc *t, struct traverse_info *info)
for (i = 0; i < n; i++)
free_extended_entry(tx + i);
free(tx);
+ free(traverse_path);
+ info->traverse_path = NULL;
strbuf_release(&base);
return error;
}