remove path_packfile from struct got_delta_cache; add a counter instead
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98
diff --git a/lib/got_pack_lib.h b/lib/got_pack_lib.h
index 61b5c9d..0cea059 100644
--- a/lib/got_pack_lib.h
+++ b/lib/got_pack_lib.h
@@ -23,7 +23,7 @@ struct got_delta_cache_entry {
#define GOT_DELTA_CACHE_SIZE 1024
struct got_delta_cache {
- char *path_packfile;
+ int nentries;
struct got_delta_cache_entry deltas[GOT_DELTA_CACHE_SIZE];
};
diff --git a/lib/pack.c b/lib/pack.c
index cdb8863..4975158 100644
--- a/lib/pack.c
+++ b/lib/pack.c
@@ -580,7 +580,6 @@ const struct got_error *
got_pack_close(struct got_pack *pack)
{
const struct got_error *err = NULL;
- struct got_delta_cache *cache = &pack->delta_cache;
int i;
while (!TAILQ_EMPTY(&pack->mappings)) {
@@ -600,17 +599,15 @@ got_pack_close(struct got_pack *pack)
pack->filesize = 0;
}
- free(cache->path_packfile);
- cache->path_packfile = NULL;
- for (i = 0; i < nitems(cache->deltas); i++) {
- struct got_delta_cache_entry *entry = &cache->deltas[i];
- if (entry->data_offset == 0)
- break;
+ for (i = 0; i < pack->delta_cache.nentries; i++) {
+ struct got_delta_cache_entry *entry;
+ entry = &pack->delta_cache.deltas[i];
entry->data_offset = 0;
free(entry->delta_buf);
entry->delta_buf = NULL;
entry->delta_len = 0;
}
+ pack->delta_cache.nentries = 0;
return err;
}
@@ -1149,41 +1146,31 @@ clear_delta_cache_entry(struct got_delta_cache_entry *entry)
}
const struct got_error *
-add_delta_cache_entry(struct got_delta_cache *cache, off_t data_offset,
- uint8_t *delta_buf, size_t delta_len)
+cache_delta(off_t data_offset, uint8_t *delta_buf, size_t delta_len,
+ struct got_pack *pack)
{
int i;
+ struct got_delta_cache *cache = &pack->delta_cache;
struct got_delta_cache_entry *entry;
- for (i = 0; i < nitems(cache->deltas); i++) {
- entry = &cache->deltas[i];
- if (entry->data_offset == 0)
- break;
- }
-
- if (i == nitems(cache->deltas)) {
- entry = &cache->deltas[i - 1];
+ if (cache->nentries == nitems(cache->deltas)) {
+ entry = &cache->deltas[cache->nentries - 1];
clear_delta_cache_entry(entry);
+ cache->nentries--;
memmove(&cache->deltas[1], &cache->deltas[0],
sizeof(cache->deltas) - sizeof(cache->deltas[0]));
i = 0;
- }
+ } else
+ i = cache->nentries;
entry = &cache->deltas[i];
entry->data_offset = data_offset;
entry->delta_buf = delta_buf;
entry->delta_len = delta_len;
+ cache->nentries++;
return NULL;
}
-const struct got_error *
-cache_delta(off_t data_offset, uint8_t *delta_buf, size_t delta_len,
- struct got_pack *pack)
-{
- return add_delta_cache_entry(&pack->delta_cache, data_offset,
- delta_buf, delta_len);
-}
-
void
get_cached_delta(uint8_t **delta_buf, size_t *delta_len, off_t data_offset,
struct got_pack *pack)