[PATCH 02/11] pack-bitmap.c: avoid unnecessary `offset_to_pack_pos()`
- From
Taylor Blau <me@ttaylorr.com>
- Date
- Oct 9, 2024, 20:31 UTC
- Message-ID
- <010316f1eb49b46db1ed0b8df10402d3a49013f8.1728505840.git.me@ttaylorr.com>
- In-Reply-To
- <cover.1728505840.git.me@ttaylorr.com>
In `try_partial_reuse()`, for any object which is either an OFS_DELTA or REF_DELTA, we need to determine the bitmap position for its base.
We handle the case of single- and multi-pack bitmaps separately:
- For multi-pack bitmaps, we look to see if the MIDX selected the
base we're looking at to represent that object. If the base object
was selected from a different pack in the MIDX, we won't reuse the
delta. - For single-pack bitmaps, we convert the base object's offset into
a pack-relative position (identified here as 'base_pos') by
calling `offset_to_pack_pos()`.But we also call `offset_to_pack_pos()` before handling each case above separately. For the MIDX case, this is unnecessary, since we don't need to lookup the base object's pack-relative position; instead, we just care whether the selected copy of that base is from the same pack we're currently operating on.
For the non-MIDX case, we end up calling offset_to_pack_pos() again, yielding the same result, making the earlier call wasteful. This behavior dates back to 519e17ff75 (pack-bitmap: prepare to mark objects from multiple packs for reuse, 2023-12-14).
Let's correct that by avoiding the unconditional call to 'offset_to_pack_pos()'.
Signed-off-by: Taylor Blau <me@ttaylorr.com> --- pack-bitmap.c | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-)
diff --git a/pack-bitmap.c b/pack-bitmap.c index 706ff26a7b1..5c5c26efe0d 100644 --- a/pack-bitmap.c +++ b/pack-bitmap.c @@ -2069,7 +2069,6 @@ static int try_partial_reuse(struct bitmap_index *bitmap_git, if (type == OBJ_REF_DELTA || type == OBJ_OFS_DELTA) { off_t base_offset; - uint32_t base_pos; uint32_t base_bitmap_pos; /* @@ -2085,8 +2084,6 @@ static int try_partial_reuse(struct bitmap_index *bitmap_git, if (!base_offset) return 0; - offset_to_pack_pos(pack->p, base_offset, &base_pos); - if (bitmap_is_midx(bitmap_git)) { /* * Cross-pack deltas are rejected for now, but could @@ -2105,6 +2102,8 @@ static int try_partial_reuse(struct bitmap_index *bitmap_git, return 0; } } else { + uint32_t base_pos; + if (offset_to_pack_pos(pack->p, base_offset, &base_pos) < 0) return 0;
-- 2.47.0.11.g487258bca34