summaryrefslogtreecommitdiff
path: root/object-file.c
diff options
context:
space:
mode:
authorEric Wong <e@80x24.org>2021-07-07 23:10:17 (GMT)
committerJunio C Hamano <gitster@pobox.com>2021-07-08 04:27:58 (GMT)
commit33f379eee63a0529f85079857598ac6325d3aec5 (patch)
tree010f6c4d388fbdeabfc5ba2e29cb9c7996004bab /object-file.c
parent407532f82d3fdfd18d4ec276ddeb359e7c724aa6 (diff)
downloadgit-33f379eee63a0529f85079857598ac6325d3aec5.zip
git-33f379eee63a0529f85079857598ac6325d3aec5.tar.gz
git-33f379eee63a0529f85079857598ac6325d3aec5.tar.bz2
make object_directory.loose_objects_subdir_seen a bitmap
There's no point in using 8 bits per-directory when 1 bit will do. This saves us 224 bytes per object directory, which ends up being 22MB when dealing with 100K alternates. Signed-off-by: Eric Wong <e@80x24.org> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Diffstat (limited to 'object-file.c')
-rw-r--r--object-file.c11
1 files changed, 8 insertions, 3 deletions
diff --git a/object-file.c b/object-file.c
index 2dd70dd..91ded8c 100644
--- a/object-file.c
+++ b/object-file.c
@@ -2461,12 +2461,17 @@ struct oid_array *odb_loose_cache(struct object_directory *odb,
{
int subdir_nr = oid->hash[0];
struct strbuf buf = STRBUF_INIT;
+ size_t word_bits = bitsizeof(odb->loose_objects_subdir_seen[0]);
+ size_t word_index = subdir_nr / word_bits;
+ size_t mask = 1 << (subdir_nr % word_bits);
+ uint32_t *bitmap;
if (subdir_nr < 0 ||
- subdir_nr >= ARRAY_SIZE(odb->loose_objects_subdir_seen))
+ subdir_nr >= bitsizeof(odb->loose_objects_subdir_seen))
BUG("subdir_nr out of range");
- if (odb->loose_objects_subdir_seen[subdir_nr])
+ bitmap = &odb->loose_objects_subdir_seen[word_index];
+ if (*bitmap & mask)
return &odb->loose_objects_cache[subdir_nr];
strbuf_addstr(&buf, odb->path);
@@ -2474,7 +2479,7 @@ struct oid_array *odb_loose_cache(struct object_directory *odb,
append_loose_object,
NULL, NULL,
&odb->loose_objects_cache[subdir_nr]);
- odb->loose_objects_subdir_seen[subdir_nr] = 1;
+ *bitmap |= mask;
strbuf_release(&buf);
return &odb->loose_objects_cache[subdir_nr];
}