Skip to content

Commit 84dd81c

Browse files
trastgitster
authored andcommitted
Refactor parts of in_delta_base_cache/cache_or_unpack_entry
The delta base cache lookup and test were shared. Refactor them; we'll need both parts again. Also, we'll use the clearing routine later. Signed-off-by: Thomas Rast <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 790d96c commit 84dd81c

File tree

1 file changed

+32
-13
lines changed

1 file changed

+32
-13
lines changed

sha1_file.c

Lines changed: 32 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1756,32 +1756,51 @@ static unsigned long pack_entry_hash(struct packed_git *p, off_t base_offset)
17561756
return hash % MAX_DELTA_CACHE;
17571757
}
17581758

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)
17601761
{
17611762
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+
{
17631769
return (ent->data && ent->p == p && ent->base_offset == base_offset);
17641770
}
17651771

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+
17661787
static void *cache_or_unpack_entry(struct packed_git *p, off_t base_offset,
17671788
unsigned long *base_size, enum object_type *type, int keep_cache)
17681789
{
1790+
struct delta_base_cache_entry *ent;
17691791
void *ret;
1770-
unsigned long hash = pack_entry_hash(p, base_offset);
1771-
struct delta_base_cache_entry *ent = delta_base_cache + hash;
17721792

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))
17751796
return unpack_entry(p, base_offset, type, base_size);
17761797

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
17831803
ret = xmemdupz(ent->data, ent->size);
1784-
}
17851804
*type = ent->type;
17861805
*base_size = ent->size;
17871806
return ret;

0 commit comments

Comments
 (0)