summaryrefslogtreecommitdiff
path: root/unpack-trees.c
diff options
context:
space:
mode:
Diffstat (limited to 'unpack-trees.c')
-rw-r--r--unpack-trees.c51
1 files changed, 48 insertions, 3 deletions
diff --git a/unpack-trees.c b/unpack-trees.c
index 8e2032f..9f55cc2 100644
--- a/unpack-trees.c
+++ b/unpack-trees.c
@@ -498,13 +498,14 @@ static int traverse_trees_recursive(int n, unsigned long dirmask,
* itself - the caller needs to do the final check for the cache
* entry having more data at the end!
*/
-static int do_compare_entry(const struct cache_entry *ce, const struct traverse_info *info, const struct name_entry *n)
+static int do_compare_entry_piecewise(const struct cache_entry *ce, const struct traverse_info *info, const struct name_entry *n)
{
int len, pathlen, ce_len;
const char *ce_name;
if (info->prev) {
- int cmp = do_compare_entry(ce, info->prev, &info->name);
+ int cmp = do_compare_entry_piecewise(ce, info->prev,
+ &info->name);
if (cmp)
return cmp;
}
@@ -522,6 +523,39 @@ static int do_compare_entry(const struct cache_entry *ce, const struct traverse_
return df_name_compare(ce_name, ce_len, S_IFREG, n->path, len, n->mode);
}
+static int do_compare_entry(const struct cache_entry *ce,
+ const struct traverse_info *info,
+ const struct name_entry *n)
+{
+ int len, pathlen, ce_len;
+ const char *ce_name;
+ int cmp;
+
+ /*
+ * If we have not precomputed the traverse path, it is quicker
+ * to avoid doing so. But if we have precomputed it,
+ * it is quicker to use the precomputed version.
+ */
+ if (!info->traverse_path)
+ return do_compare_entry_piecewise(ce, info, n);
+
+ cmp = strncmp(ce->name, info->traverse_path, info->pathlen);
+ if (cmp)
+ return cmp;
+
+ pathlen = info->pathlen;
+ ce_len = ce_namelen(ce);
+
+ if (ce_len < pathlen)
+ return -1;
+
+ ce_len -= pathlen;
+ ce_name = ce->name + pathlen;
+
+ len = tree_entry_len(n);
+ return df_name_compare(ce_name, ce_len, S_IFREG, n->path, len, n->mode);
+}
+
static int compare_entry(const struct cache_entry *ce, const struct traverse_info *info, const struct name_entry *n)
{
int cmp = do_compare_entry(ce, info, n);
@@ -661,8 +695,19 @@ static int find_cache_pos(struct traverse_info *info,
++o->cache_bottom;
continue;
}
- if (!ce_in_traverse_path(ce, info))
+ if (!ce_in_traverse_path(ce, info)) {
+ /*
+ * Check if we can skip future cache checks
+ * (because we're already past all possible
+ * entries in the traverse path).
+ */
+ if (info->traverse_path) {
+ if (strncmp(ce->name, info->traverse_path,
+ info->pathlen) > 0)
+ break;
+ }
continue;
+ }
ce_name = ce->name + pfxlen;
ce_slash = strchr(ce_name, '/');
if (ce_slash)