Skip to content

Commit 33f379e

Browse files
Eric Wonggitster
Eric Wong
authored andcommitted
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 <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 407532f commit 33f379e

File tree

2 files changed

+9
-4
lines changed

2 files changed

+9
-4
lines changed

object-file.c

+8-3
Original file line numberDiff line numberDiff line change
@@ -2461,20 +2461,25 @@ struct oid_array *odb_loose_cache(struct object_directory *odb,
24612461
{
24622462
int subdir_nr = oid->hash[0];
24632463
struct strbuf buf = STRBUF_INIT;
2464+
size_t word_bits = bitsizeof(odb->loose_objects_subdir_seen[0]);
2465+
size_t word_index = subdir_nr / word_bits;
2466+
size_t mask = 1 << (subdir_nr % word_bits);
2467+
uint32_t *bitmap;
24642468

24652469
if (subdir_nr < 0 ||
2466-
subdir_nr >= ARRAY_SIZE(odb->loose_objects_subdir_seen))
2470+
subdir_nr >= bitsizeof(odb->loose_objects_subdir_seen))
24672471
BUG("subdir_nr out of range");
24682472

2469-
if (odb->loose_objects_subdir_seen[subdir_nr])
2473+
bitmap = &odb->loose_objects_subdir_seen[word_index];
2474+
if (*bitmap & mask)
24702475
return &odb->loose_objects_cache[subdir_nr];
24712476

24722477
strbuf_addstr(&buf, odb->path);
24732478
for_each_file_in_obj_subdir(subdir_nr, &buf,
24742479
append_loose_object,
24752480
NULL, NULL,
24762481
&odb->loose_objects_cache[subdir_nr]);
2477-
odb->loose_objects_subdir_seen[subdir_nr] = 1;
2482+
*bitmap |= mask;
24782483
strbuf_release(&buf);
24792484
return &odb->loose_objects_cache[subdir_nr];
24802485
}

object-store.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ struct object_directory {
2222
*
2323
* Be sure to call odb_load_loose_cache() before using.
2424
*/
25-
char loose_objects_subdir_seen[256];
25+
uint32_t loose_objects_subdir_seen[8]; /* 256 bits */
2626
struct oid_array loose_objects_cache[256];
2727

2828
/*

0 commit comments

Comments
 (0)