]> git.ipfire.org Git - thirdparty/git.git/commitdiff
make object_directory.loose_objects_subdir_seen a bitmap
authorEric Wong <e@80x24.org>
Wed, 7 Jul 2021 23:10:17 +0000 (23:10 +0000)
committerJunio C Hamano <gitster@pobox.com>
Thu, 8 Jul 2021 04:27:58 +0000 (21:27 -0700)
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>
object-file.c
object-store.h

index 2dd70ddf3a49b8713427bbd0767d69ca717194c3..91ded8c22ae9fa15350290a496fac0bdb8cb817f 100644 (file)
@@ -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];
 }
index 6077065d9061c44bb850d2ad0962893387d3b312..ab6d469970e999af1d5951d3c871062918e81af9 100644 (file)
@@ -22,7 +22,7 @@ struct object_directory {
         *
         * Be sure to call odb_load_loose_cache() before using.
         */
-       char loose_objects_subdir_seen[256];
+       uint32_t loose_objects_subdir_seen[8]; /* 256 bits */
        struct oid_array loose_objects_cache[256];
 
        /*