Skip to content

Commit 63cdcfa

Browse files
committed
pack-objects: shrink struct object_entry
Turn some boolean fields into bitfields and use uint32_t for name hash. This shrinks the size of the structure from 128 bytes to 120 bytes. Signed-off-by: Junio C Hamano <[email protected]>
1 parent f51a757 commit 63cdcfa

File tree

1 file changed

+12
-11
lines changed

1 file changed

+12
-11
lines changed

builtin/pack-objects.c

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -38,17 +38,18 @@ struct object_entry {
3838
void *delta_data; /* cached delta (uncompressed) */
3939
unsigned long delta_size; /* delta data size (uncompressed) */
4040
unsigned long z_delta_size; /* delta data size (compressed) */
41-
unsigned int hash; /* name hint hash */
4241
enum object_type type;
4342
enum object_type in_pack_type; /* could be delta */
43+
uint32_t hash; /* name hint hash */
4444
unsigned char in_pack_header_size;
45-
unsigned char preferred_base; /* we do not pack this, but is available
46-
* to be used as the base object to delta
47-
* objects against.
48-
*/
49-
unsigned char no_try_delta;
50-
unsigned char tagged; /* near the very tip of refs */
51-
unsigned char filled; /* assigned write-order */
45+
unsigned preferred_base:1; /*
46+
* we do not pack this, but is available
47+
* to be used as the base object to delta
48+
* objects against.
49+
*/
50+
unsigned no_try_delta:1;
51+
unsigned tagged:1; /* near the very tip of refs */
52+
unsigned filled:1; /* assigned write-order */
5253
};
5354

5455
/*
@@ -859,9 +860,9 @@ static void rehash_objects(void)
859860
}
860861
}
861862

862-
static unsigned name_hash(const char *name)
863+
static uint32_t name_hash(const char *name)
863864
{
864-
unsigned c, hash = 0;
865+
uint32_t c, hash = 0;
865866

866867
if (!name)
867868
return 0;
@@ -908,7 +909,7 @@ static int add_object_entry(const unsigned char *sha1, enum object_type type,
908909
struct packed_git *p, *found_pack = NULL;
909910
off_t found_offset = 0;
910911
int ix;
911-
unsigned hash = name_hash(name);
912+
uint32_t hash = name_hash(name);
912913

913914
ix = nr_objects ? locate_object_entry_hash(sha1) : -1;
914915
if (ix >= 0) {

0 commit comments

Comments
 (0)