498
* itself - the caller needs to do the final check for the cache
499
* entry having more data at the end!
500
*/
501
-static int do_compare_entry(const struct cache_entry *ce, const struct traverse_info *info, const struct name_entry *n)
501
+static int do_compare_entry_piecewise(const struct cache_entry *ce, const struct traverse_info *info, const struct name_entry *n)
502
{
503
int len, pathlen, ce_len;
504
const char *ce_name;
505
506
if (info->prev) {
507
- int cmp = do_compare_entry(ce, info->prev, &info->name);
507
+ int cmp = do_compare_entry_piecewise(ce, info->prev,
508
+ &info->name);
509
if (cmp)
510
return cmp;
511
}
523
return df_name_compare(ce_name, ce_len, S_IFREG, n->path, len, n->mode);
524
}
525
526
+static int do_compare_entry(const struct cache_entry *ce,
527
+ const struct traverse_info *info,
528
+ const struct name_entry *n)
529
+{
530
+ int len, pathlen, ce_len;
531
+ const char *ce_name;
532
+ int cmp;
533
+
534
+ /*
535
+ * If we have not precomputed the traverse path, it is quicker
536
+ * to avoid doing so. But if we have precomputed it,
537
+ * it is quicker to use the precomputed version.
538
+ */
539
+ if (!info->traverse_path)
540
+ return do_compare_entry_piecewise(ce, info, n);
541
+
542
+ cmp = strncmp(ce->name, info->traverse_path, info->pathlen);
543
+ if (cmp)
544
+ return cmp;
545
+
546
+ pathlen = info->pathlen;
547
+ ce_len = ce_namelen(ce);
548
+
549
+ if (ce_len < pathlen)
550
+ return -1;
551
+
552
+ ce_len -= pathlen;
553
+ ce_name = ce->name + pathlen;
554
+
555
+ len = tree_entry_len(n);
556
+ return df_name_compare(ce_name, ce_len, S_IFREG, n->path, len, n->mode);
557
+}
558
+
559
static int compare_entry(const struct cache_entry *ce, const struct traverse_info *info, const struct name_entry *n)
560
{
561
int cmp = do_compare_entry(ce, info, n);