Skip to content

Commit 1f5f591

Browse files
authored
Make JSString smaller (#1252)
MSVC apparently doesn't merge adjacent bit fields if they don't have the same type. Change the uint8_t fields to uint32_t. It was reported that `sizeof(JSString)` was 48 bytes on Windows but it should be 40 bytes now, like it is on x86_64 Linux. Fixes: #1250
1 parent dc5e7bd commit 1f5f591

File tree

1 file changed

+3
-3
lines changed

1 file changed

+3
-3
lines changed

quickjs.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -565,13 +565,13 @@ typedef enum {
565565
struct JSString {
566566
JSRefCountHeader header; /* must come first, 32-bit */
567567
uint32_t len : 31;
568-
uint8_t is_wide_char : 1; /* 0 = 8 bits, 1 = 16 bits characters */
568+
uint32_t is_wide_char : 1; /* 0 = 8 bits, 1 = 16 bits characters */
569569
/* for JS_ATOM_TYPE_SYMBOL: hash = 0, atom_type = 3,
570570
for JS_ATOM_TYPE_PRIVATE: hash = 1, atom_type = 3
571571
XXX: could change encoding to have one more bit in hash */
572572
uint32_t hash : 29;
573-
uint8_t kind : 1;
574-
uint8_t atom_type : 2; /* != 0 if atom, JS_ATOM_TYPE_x */
573+
uint32_t kind : 1;
574+
uint32_t atom_type : 2; /* != 0 if atom, JS_ATOM_TYPE_x */
575575
uint32_t hash_next; /* atom_index for JS_ATOM_TYPE_SYMBOL */
576576
JSWeakRefRecord *first_weak_ref;
577577
#ifdef ENABLE_DUMPS // JS_DUMP_LEAKS

0 commit comments

Comments
 (0)