From 44cb8a5f769c722356ef57551aa9198f38e311f1 Mon Sep 17 00:00:00 2001 From: HalidOdat Date: Sat, 19 Jun 2021 13:27:45 +0200 Subject: [PATCH] Shrink `Jim_Scope` size from 12 to 1 byte We store the `Jim_Scope` as a bit field. We keep 6 bits for the kind (enough to store 64 different kinds), 1 bit for the tail and another 1 bit for key. --- jim.h | 6 +++--- test.c | 3 +++ 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/jim.h b/jim.h index 12f38f0..e0a227a 100644 --- a/jim.h +++ b/jim.h @@ -25,9 +25,9 @@ typedef enum { } Jim_Scope_Kind; typedef struct { - Jim_Scope_Kind kind; - int tail; - int key; + unsigned char kind : 6; + unsigned char tail : 1; + unsigned char key : 1; } Jim_Scope; typedef struct { diff --git a/test.c b/test.c index f25fe59..16f782d 100644 --- a/test.c +++ b/test.c @@ -1,6 +1,7 @@ #include #include #include +#include #define JIM_IMPLEMENTATION #include "./jim.h" @@ -202,6 +203,8 @@ void test(void) int main(int argc, char **argv) { + assert(sizeof(Jim_Scope) == 1); + if (argc >= 2) { if (strcmp(argv[1], "record") == 0) { record("test_expected.h");