@@ -665,17 +665,24 @@ static void mark_ce_used_same_name(struct cache_entry *ce,
665
665
}
666
666
}
667
667
668
- static struct cache_entry * next_cache_entry (struct unpack_trees_options * o )
668
+ static struct cache_entry * next_cache_entry (struct unpack_trees_options * o , int * hint )
669
669
{
670
670
const struct index_state * index = o -> src_index ;
671
671
int pos = o -> cache_bottom ;
672
672
673
+ if (* hint > pos )
674
+ pos = * hint ;
675
+
673
676
while (pos < index -> cache_nr ) {
674
677
struct cache_entry * ce = index -> cache [pos ];
675
- if (!(ce -> ce_flags & CE_UNPACKED ))
678
+ if (!(ce -> ce_flags & CE_UNPACKED )) {
679
+ * hint = pos + 1 ;
676
680
return ce ;
681
+ }
677
682
pos ++ ;
678
683
}
684
+
685
+ * hint = pos ;
679
686
return NULL ;
680
687
}
681
688
@@ -1386,12 +1393,13 @@ static int unpack_callback(int n, unsigned long mask, unsigned long dirmask, str
1386
1393
1387
1394
/* Are we supposed to look at the index too? */
1388
1395
if (o -> merge ) {
1396
+ int hint = -1 ;
1389
1397
while (1 ) {
1390
1398
int cmp ;
1391
1399
struct cache_entry * ce ;
1392
1400
1393
1401
if (o -> diff_index_cached )
1394
- ce = next_cache_entry (o );
1402
+ ce = next_cache_entry (o , & hint );
1395
1403
else
1396
1404
ce = find_cache_entry (info , p );
1397
1405
@@ -1720,7 +1728,7 @@ static int verify_absent(const struct cache_entry *,
1720
1728
int unpack_trees (unsigned len , struct tree_desc * t , struct unpack_trees_options * o )
1721
1729
{
1722
1730
struct repository * repo = the_repository ;
1723
- int i , ret ;
1731
+ int i , hint , ret ;
1724
1732
static struct cache_entry * dfc ;
1725
1733
struct pattern_list pl ;
1726
1734
int free_pattern_list = 0 ;
@@ -1852,13 +1860,15 @@ int unpack_trees(unsigned len, struct tree_desc *t, struct unpack_trees_options
1852
1860
info .pathspec = o -> pathspec ;
1853
1861
1854
1862
if (o -> prefix ) {
1863
+ hint = -1 ;
1864
+
1855
1865
/*
1856
1866
* Unpack existing index entries that sort before the
1857
1867
* prefix the tree is spliced into. Note that o->merge
1858
1868
* is always true in this case.
1859
1869
*/
1860
1870
while (1 ) {
1861
- struct cache_entry * ce = next_cache_entry (o );
1871
+ struct cache_entry * ce = next_cache_entry (o , & hint );
1862
1872
if (!ce )
1863
1873
break ;
1864
1874
if (ce_in_traverse_path (ce , & info ))
@@ -1879,8 +1889,9 @@ int unpack_trees(unsigned len, struct tree_desc *t, struct unpack_trees_options
1879
1889
1880
1890
/* Any left-over entries in the index? */
1881
1891
if (o -> merge ) {
1892
+ hint = -1 ;
1882
1893
while (1 ) {
1883
- struct cache_entry * ce = next_cache_entry (o );
1894
+ struct cache_entry * ce = next_cache_entry (o , & hint );
1884
1895
if (!ce )
1885
1896
break ;
1886
1897
if (unpack_index_entry (ce , o ) < 0 )
0 commit comments