Revert "unpack-trees: improve performance of next_cache_entry"

This reverts commit f2a454e0a5 (unpack-trees: improve performance of next_cache_entry, 2021-11-29). The "hint" value was originally needed to improve performance in 'git reset -- <pathspec>' caused by 'cache_bottom' lagging behind its correct value when using a sparse index. The 'cache_bottom' tracking has since been corrected, removing the need for an additional "pseudo-cache_bottom" tracking variable. Signed-off-by: Victoria Dye <vdye@github.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Victoria Dye committed Mar 17, 2022 at 15:55 UTC 99430aa12cddf0af85d24316cea4a02dc4a711b6
1 file changed +6 -17
unpack-trees.c
+6 -17
@@ -644,24 +644,17 @@ static void mark_ce_used_same_name(struct cache_entry *ce,
644 }
645 }
646
647 -static struct cache_entry *next_cache_entry(struct unpack_trees_options *o, int *hint)
647 +static struct cache_entry *next_cache_entry(struct unpack_trees_options *o)
648 {
649 const struct index_state *index = o->src_index;
650 int pos = o->cache_bottom;
651
652 - if (*hint > pos)
653 - pos = *hint;
654 -
652 while (pos < index->cache_nr) {
653 struct cache_entry *ce = index->cache[pos];
657 - if (!(ce->ce_flags & CE_UNPACKED)) {
658 - *hint = pos + 1;
654 + if (!(ce->ce_flags & CE_UNPACKED))
655 return ce;
660 - }
656 pos++;
657 }
663 -
664 - *hint = pos;
658 return NULL;
659 }
660
@@ -1409,13 +1402,12 @@ static int unpack_callback(int n, unsigned long mask, unsigned long dirmask, str
1402
1403 /* Are we supposed to look at the index too? */
1404 if (o->merge) {
1412 - int hint = -1;
1405 while (1) {
1406 int cmp;
1407 struct cache_entry *ce;
1408
1409 if (o->diff_index_cached)
1418 - ce = next_cache_entry(o, &hint);
1410 + ce = next_cache_entry(o);
1411 else
1412 ce = find_cache_entry(info, p);
1413
@@ -1777,7 +1769,7 @@ static int verify_absent(const struct cache_entry *,
1769 int unpack_trees(unsigned len, struct tree_desc *t, struct unpack_trees_options *o)
1770 {
1771 struct repository *repo = the_repository;
1780 - int i, hint, ret;
1772 + int i, ret;
1773 static struct cache_entry *dfc;
1774 struct pattern_list pl;
1775 int free_pattern_list = 0;
@@ -1869,15 +1861,13 @@ int unpack_trees(unsigned len, struct tree_desc *t, struct unpack_trees_options
1861 info.pathspec = o->pathspec;
1862
1863 if (o->prefix) {
1872 - hint = -1;
1873 -
1864 /*
1865 * Unpack existing index entries that sort before the
1866 * prefix the tree is spliced into. Note that o->merge
1867 * is always true in this case.
1868 */
1869 while (1) {
1880 - struct cache_entry *ce = next_cache_entry(o, &hint);
1870 + struct cache_entry *ce = next_cache_entry(o);
1871 if (!ce)
1872 break;
1873 if (ce_in_traverse_path(ce, &info))
@@ -1898,9 +1888,8 @@ int unpack_trees(unsigned len, struct tree_desc *t, struct unpack_trees_options
1888
1889 /* Any left-over entries in the index? */
1890 if (o->merge) {
1901 - hint = -1;
1891 while (1) {
1903 - struct cache_entry *ce = next_cache_entry(o, &hint);
1892 + struct cache_entry *ce = next_cache_entry(o);
1893 if (!ce)
1894 break;
1895 if (unpack_index_entry(ce, o) < 0)