Skip to content

Commit 500e4f2

Browse files
peffgitster
authored andcommitted
pack-bitmap: use object_id when loading on-disk bitmaps
A pack bitmap file contains the index position of the commit for each bitmap, which we then translate into an object id via nth_packed_object_sha1(). In preparation for that function going away, we can switch to the more type-safe nth_packed_object_id(). Note that even though the result ends up in an object_id this does incur an extra copy of the hash (into our temporary object_id, and then into the final malloc'd stored_bitmap struct). This shouldn't make any measurable difference. If it did, we could avoid this copy _and_ the copy of the rest of the items by allocating the stored_bitmap struct beforehand and reading directly into it from the bitmap file. Or better still, if this is a bottleneck, we could introduce an on-disk index to the bitmap file so we don't have to read every single entry to use just one of them. So it's not worth worrying about micro-optimizing out this one hash copy. Signed-off-by: Jeff King <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent f66d4e0 commit 500e4f2

File tree

1 file changed

+6
-6
lines changed

1 file changed

+6
-6
lines changed

pack-bitmap.c

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -169,7 +169,7 @@ static int load_bitmap_header(struct bitmap_index *index)
169169

170170
static struct stored_bitmap *store_bitmap(struct bitmap_index *index,
171171
struct ewah_bitmap *root,
172-
const unsigned char *hash,
172+
const struct object_id *oid,
173173
struct stored_bitmap *xor_with,
174174
int flags)
175175
{
@@ -181,15 +181,15 @@ static struct stored_bitmap *store_bitmap(struct bitmap_index *index,
181181
stored->root = root;
182182
stored->xor = xor_with;
183183
stored->flags = flags;
184-
oidread(&stored->oid, hash);
184+
oidcpy(&stored->oid, oid);
185185

186186
hash_pos = kh_put_oid_map(index->bitmaps, stored->oid, &ret);
187187

188188
/* a 0 return code means the insertion succeeded with no changes,
189189
* because the SHA1 already existed on the map. this is bad, there
190190
* shouldn't be duplicated commits in the index */
191191
if (ret == 0) {
192-
error("Duplicate entry in bitmap index: %s", hash_to_hex(hash));
192+
error("Duplicate entry in bitmap index: %s", oid_to_hex(oid));
193193
return NULL;
194194
}
195195

@@ -221,13 +221,13 @@ static int load_bitmap_entries_v1(struct bitmap_index *index)
221221
struct ewah_bitmap *bitmap = NULL;
222222
struct stored_bitmap *xor_bitmap = NULL;
223223
uint32_t commit_idx_pos;
224-
const unsigned char *sha1;
224+
struct object_id oid;
225225

226226
commit_idx_pos = read_be32(index->map, &index->map_pos);
227227
xor_offset = read_u8(index->map, &index->map_pos);
228228
flags = read_u8(index->map, &index->map_pos);
229229

230-
sha1 = nth_packed_object_sha1(index->pack, commit_idx_pos);
230+
nth_packed_object_id(&oid, index->pack, commit_idx_pos);
231231

232232
bitmap = read_bitmap_1(index);
233233
if (!bitmap)
@@ -244,7 +244,7 @@ static int load_bitmap_entries_v1(struct bitmap_index *index)
244244
}
245245

246246
recent_bitmaps[i % MAX_XOR_OFFSET] = store_bitmap(
247-
index, bitmap, sha1, xor_bitmap, flags);
247+
index, bitmap, &oid, xor_bitmap, flags);
248248
}
249249

250250
return 0;

0 commit comments

Comments
 (0)