@@ -1756,32 +1756,51 @@ static unsigned long pack_entry_hash(struct packed_git *p, off_t base_offset)
1756
1756
return hash % MAX_DELTA_CACHE ;
1757
1757
}
1758
1758
1759
- static int in_delta_base_cache (struct packed_git * p , off_t base_offset )
1759
+ static struct delta_base_cache_entry *
1760
+ get_delta_base_cache_entry (struct packed_git * p , off_t base_offset )
1760
1761
{
1761
1762
unsigned long hash = pack_entry_hash (p , base_offset );
1762
- struct delta_base_cache_entry * ent = delta_base_cache + hash ;
1763
+ return delta_base_cache + hash ;
1764
+ }
1765
+
1766
+ static int eq_delta_base_cache_entry (struct delta_base_cache_entry * ent ,
1767
+ struct packed_git * p , off_t base_offset )
1768
+ {
1763
1769
return (ent -> data && ent -> p == p && ent -> base_offset == base_offset );
1764
1770
}
1765
1771
1772
+ static int in_delta_base_cache (struct packed_git * p , off_t base_offset )
1773
+ {
1774
+ struct delta_base_cache_entry * ent ;
1775
+ ent = get_delta_base_cache_entry (p , base_offset );
1776
+ return eq_delta_base_cache_entry (ent , p , base_offset );
1777
+ }
1778
+
1779
+ static void clear_delta_base_cache_entry (struct delta_base_cache_entry * ent )
1780
+ {
1781
+ ent -> data = NULL ;
1782
+ ent -> lru .next -> prev = ent -> lru .prev ;
1783
+ ent -> lru .prev -> next = ent -> lru .next ;
1784
+ delta_base_cached -= ent -> size ;
1785
+ }
1786
+
1766
1787
static void * cache_or_unpack_entry (struct packed_git * p , off_t base_offset ,
1767
1788
unsigned long * base_size , enum object_type * type , int keep_cache )
1768
1789
{
1790
+ struct delta_base_cache_entry * ent ;
1769
1791
void * ret ;
1770
- unsigned long hash = pack_entry_hash (p , base_offset );
1771
- struct delta_base_cache_entry * ent = delta_base_cache + hash ;
1772
1792
1773
- ret = ent -> data ;
1774
- if (!ret || ent -> p != p || ent -> base_offset != base_offset )
1793
+ ent = get_delta_base_cache_entry (p , base_offset );
1794
+
1795
+ if (!eq_delta_base_cache_entry (ent , p , base_offset ))
1775
1796
return unpack_entry (p , base_offset , type , base_size );
1776
1797
1777
- if (!keep_cache ) {
1778
- ent -> data = NULL ;
1779
- ent -> lru .next -> prev = ent -> lru .prev ;
1780
- ent -> lru .prev -> next = ent -> lru .next ;
1781
- delta_base_cached -= ent -> size ;
1782
- } else {
1798
+ ret = ent -> data ;
1799
+
1800
+ if (!keep_cache )
1801
+ clear_delta_base_cache_entry (ent );
1802
+ else
1783
1803
ret = xmemdupz (ent -> data , ent -> size );
1784
- }
1785
1804
* type = ent -> type ;
1786
1805
* base_size = ent -> size ;
1787
1806
return ret ;
0 commit comments