avoid loop over the ID set which removes objects IDs with reused deltas ok op@
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
diff --git a/lib/pack_create.c b/lib/pack_create.c
index fb1e354..ca90c20 100644
--- a/lib/pack_create.c
+++ b/lib/pack_create.c
@@ -1870,23 +1870,14 @@ remove_unused_object(struct got_object_id *id, void *data, void *arg)
}
static const struct got_error *
-remove_reused_object(struct got_object_id *id, void *data, void *arg)
-{
- struct got_object_idset *idset = arg;
- struct got_pack_meta *m = data;
-
- if (m->have_reused_delta)
- got_object_idset_remove(NULL, idset, id);
-
- return NULL;
-}
-
-static const struct got_error *
add_meta_idset_cb(struct got_object_id *id, void *data, void *arg)
{
struct got_pack_meta *m = data;
struct got_pack_metavec *v = arg;
+ if (m->have_reused_delta)
+ return NULL;
+
return add_meta(m, v);
}
@@ -1905,6 +1896,7 @@ got_pack_create(uint8_t *packsha1, FILE *packfile,
struct got_ratelimit rl;
struct got_pack_metavec deltify, reuse;
int ncolored = 0, nfound = 0, ntrees = 0;
+ size_t ndeltify;
memset(&deltify, 0, sizeof(deltify));
memset(&reuse, 0, sizeof(reuse));
@@ -1956,12 +1948,6 @@ got_pack_create(uint8_t *packsha1, FILE *packfile,
cancel_cb, cancel_arg);
if (err)
goto done;
- if (reuse.nmeta > 0) {
- err = got_object_idset_for_each(idset,
- remove_reused_object, idset);
- if (err)
- goto done;
- }
delta_cache = fdopen(delta_cache_fd, "a+");
if (delta_cache == NULL) {
@@ -1975,23 +1961,27 @@ got_pack_create(uint8_t *packsha1, FILE *packfile,
goto done;
}
- deltify.meta = calloc(got_object_idset_num_elements(idset),
- sizeof(struct got_pack_meta *));
- if (deltify.meta == NULL) {
- err = got_error_from_errno("calloc");
- goto done;
- }
- deltify.metasz = got_object_idset_num_elements(idset);
+ ndeltify = got_object_idset_num_elements(idset) - reuse.nmeta;
+ if (ndeltify > 0) {
+ deltify.meta = calloc(ndeltify, sizeof(struct got_pack_meta *));
+ if (deltify.meta == NULL) {
+ err = got_error_from_errno("calloc");
+ goto done;
+ }
+ deltify.metasz = ndeltify;
- err = got_object_idset_for_each(idset, add_meta_idset_cb, &deltify);
- if (err)
- goto done;
- if (deltify.nmeta > 0) {
- err = pick_deltas(deltify.meta, deltify.nmeta, ncolored,
- nfound, ntrees, nours, reuse.nmeta, delta_cache, repo,
- progress_cb, progress_arg, &rl, cancel_cb, cancel_arg);
+ err = got_object_idset_for_each(idset, add_meta_idset_cb,
+ &deltify);
if (err)
goto done;
+ if (deltify.nmeta > 0) {
+ err = pick_deltas(deltify.meta, deltify.nmeta,
+ ncolored, nfound, ntrees, nours, reuse.nmeta,
+ delta_cache, repo, progress_cb, progress_arg, &rl,
+ cancel_cb, cancel_arg);
+ if (err)
+ goto done;
+ }
}
if (fflush(delta_cache) == EOF) {