Skip to content

Commit 88132e0

Browse files
Update previous mistake of using _Bool to bool while still using the bit-field space optimization
1 parent 12d265d commit 88132e0

File tree

1 file changed

+59
-61
lines changed

1 file changed

+59
-61
lines changed

quickjs.c

Lines changed: 59 additions & 61 deletions
Original file line numberDiff line numberDiff line change
@@ -283,11 +283,11 @@ struct JSRuntime {
283283

284284
JSValue current_exception;
285285
/* true if inside an out of memory error, to avoid recursing */
286-
_Bool in_out_of_memory : 1;
286+
bool in_out_of_memory : 1;
287287
/* true if inside build_backtrace, to avoid recursing */
288-
_Bool in_build_stack_trace : 1;
288+
bool in_build_stack_trace : 1;
289289
/* true if inside JS_FreeRuntime */
290-
_Bool in_free : 1;
290+
bool in_free : 1;
291291

292292
struct JSStackFrame *current_stack_frame;
293293

@@ -314,7 +314,7 @@ struct JSRuntime {
314314
/* used to allocate, free and clone SharedArrayBuffers */
315315
JSSharedArrayBufferFunctions sab_funcs;
316316

317-
_Bool can_block : 1; /* true if Atomics.wait can block */
317+
bool can_block : 1; /* true if Atomics.wait can block */
318318
uint32_t dump_flags : 24;
319319

320320
/* Shape hash table */
@@ -512,7 +512,7 @@ typedef struct JSWeakRefRecord {
512512

513513
typedef struct JSMapRecord {
514514
int ref_count; /* used during enumeration to avoid freeing the record */
515-
_Bool empty : 1; /* true if the record is deleted */
515+
bool empty : 1; /* true if the record is deleted */
516516
struct JSMapState *map;
517517
struct list_head link;
518518
struct list_head hash_link;
@@ -521,7 +521,7 @@ typedef struct JSMapRecord {
521521
} JSMapRecord;
522522

523523
typedef struct JSMapState {
524-
_Bool is_weak : 1; /* true if WeakSet/WeakMap */
524+
bool is_weak : 1; /* true if WeakSet/WeakMap */
525525
struct list_head records; /* list of JSMapRecord.link */
526526
uint32_t record_count;
527527
struct list_head *hash_table;
@@ -751,7 +751,7 @@ typedef enum JSIteratorHelperKindEnum {
751751

752752
typedef struct JSForInIterator {
753753
JSValue obj;
754-
_Bool is_array : 1;
754+
bool is_array : 1;
755755
uint32_t array_length;
756756
uint32_t idx;
757757
} JSForInIterator;
@@ -785,13 +785,13 @@ typedef struct JSTypedArray {
785785
JSObject *buffer; /* based array buffer */
786786
uint32_t offset; /* byte offset in the array buffer */
787787
uint32_t length; /* byte length in the array buffer */
788-
_Bool track_rab : 1; /* auto-track length of backing array buffer */
788+
bool track_rab : 1; /* auto-track length of backing array buffer */
789789
} JSTypedArray;
790790

791791
typedef struct JSAsyncFunctionState {
792792
JSValue this_val; /* 'this' generator argument */
793793
int argc; /* number of function arguments */
794-
_Bool throw_flag : 1; /* used to throw an exception in JS_CallInternal() */
794+
bool throw_flag : 1; /* used to throw an exception in JS_CallInternal() */
795795
JSStackFrame frame;
796796
} JSAsyncFunctionState;
797797

@@ -800,7 +800,7 @@ typedef struct JSAsyncFunctionState {
800800
typedef struct JSAsyncFunctionData {
801801
JSGCObjectHeader header; /* must come first */
802802
JSValue resolving_funcs[2];
803-
_Bool is_active : 1; /* true if the async function state is valid */
803+
bool is_active : 1; /* true if the async function state is valid */
804804
JSAsyncFunctionState func_state;
805805
} JSAsyncFunctionData;
806806

@@ -871,9 +871,9 @@ struct JSModuleDef {
871871
JSValue module_ns;
872872
JSValue func_obj; /* only used for JS modules */
873873
JSModuleInitFunc *init_func; /* only used for C modules */
874-
_Bool has_tla : 1; /* true if func_obj contains await */
875-
_Bool resolved : 1;
876-
_Bool func_created : 1;
874+
bool has_tla : 1; /* true if func_obj contains await */
875+
bool resolved : 1;
876+
bool func_created : 1;
877877
JSModuleStatus status : 8;
878878
/* temp use during js_module_link() & js_module_evaluate() */
879879
int dfs_index, dfs_ancestor_index;
@@ -883,14 +883,14 @@ struct JSModuleDef {
883883
int async_parent_modules_count;
884884
int async_parent_modules_size;
885885
int pending_async_dependencies;
886-
_Bool async_evaluation : 1;
886+
bool async_evaluation : 1;
887887
int64_t async_evaluation_timestamp;
888888
JSModuleDef *cycle_root;
889889
JSValue promise; /* corresponds to spec field: capability */
890890
JSValue resolving_funcs[2]; /* corresponds to spec field: capability */
891891
/* true if evaluation yielded an exception. It is saved in
892892
eval_exception */
893-
_Bool eval_has_exception : 1;
893+
bool eval_has_exception : 1;
894894
JSValue eval_exception;
895895
JSValue meta_obj; /* for import.meta */
896896
};
@@ -1043,7 +1043,7 @@ typedef struct JSCallSiteData {
10431043
JSValue filename;
10441044
JSValue func;
10451045
JSValue func_name;
1046-
_Bool native : 1;
1046+
bool native : 1;
10471047
int line_num;
10481048
int col_num;
10491049
} JSCallSiteData;
@@ -20018,31 +20018,29 @@ typedef struct JSFunctionDef {
2001820018
struct list_head child_list; /* list of JSFunctionDef.link */
2001920019
struct list_head link;
2002020020

20021-
/* change from `bool` to `_Bool flag : 1` which can reduce3 around 20 bytes per instance */
20022-
/* while still maintaining readablity comapared to `unsigned flag : 1`*/
20023-
_Bool is_eval : 1; /* true if eval code */
20021+
bool is_eval : 1; /* true if eval code */
2002420022
int eval_type; /* only valid if is_eval = true */
20025-
_Bool is_global_var : 1; /* true if variables are not defined locally:
20023+
bool is_global_var : 1; /* true if variables are not defined locally:
2002620024
eval global, eval module or non strict eval */
20027-
_Bool is_func_expr : 1; /* true if function expression */
20028-
_Bool has_home_object : 1; /* true if the home object is available */
20029-
_Bool has_prototype : 1; /* true if a prototype field is necessary */
20030-
_Bool has_simple_parameter_list : 1;
20031-
_Bool has_parameter_expressions : 1; /* if true, an argument scope is created */
20032-
_Bool has_use_strict : 1; /* to reject directive in special cases */
20033-
_Bool has_eval_call : 1; /* true if the function contains a call to eval() */
20034-
_Bool has_arguments_binding : 1; /* true if the 'arguments' binding is
20025+
bool is_func_expr : 1; /* true if function expression */
20026+
bool has_home_object : 1; /* true if the home object is available */
20027+
bool has_prototype : 1; /* true if a prototype field is necessary */
20028+
bool has_simple_parameter_list : 1;
20029+
bool has_parameter_expressions : 1; /* if true, an argument scope is created */
20030+
bool has_use_strict : 1; /* to reject directive in special cases */
20031+
bool has_eval_call : 1; /* true if the function contains a call to eval() */
20032+
bool has_arguments_binding : 1; /* true if the 'arguments' binding is
2003520033
available in the function */
20036-
_Bool has_this_binding : 1; /* true if the 'this' and new.target binding are
20034+
bool has_this_binding : 1; /* true if the 'this' and new.target binding are
2003720035
available in the function */
20038-
_Bool new_target_allowed : 1; /* true if the 'new.target' does not
20036+
bool new_target_allowed : 1; /* true if the 'new.target' does not
2003920037
throw a syntax error */
20040-
_Bool super_call_allowed : 1; /* true if super() is allowed */
20041-
_Bool super_allowed : 1; /* true if super. or super[] is allowed */
20042-
_Bool arguments_allowed : 1; /* true if the 'arguments' identifier is allowed */
20043-
_Bool is_derived_class_constructor : 1;
20044-
_Bool in_function_body : 1;
20045-
_Bool backtrace_barrier : 1;
20038+
bool super_call_allowed : 1; /* true if super() is allowed */
20039+
bool super_allowed : 1; /* true if super. or super[] is allowed */
20040+
bool arguments_allowed : 1; /* true if the 'arguments' identifier is allowed */
20041+
bool is_derived_class_constructor : 1;
20042+
bool in_function_body : 1;
20043+
bool backtrace_barrier : 1;
2004620044
JSFunctionKindEnum func_kind : 8;
2004720045
JSParseFunctionEnum func_type : 7;
2004820046
uint8_t is_strict_mode : 1;
@@ -20068,7 +20066,7 @@ typedef struct JSFunctionDef {
2006820066
int new_target_var_idx; /* variable containg the 'new.target' value, -1 if none */
2006920067
int this_active_func_var_idx; /* variable containg the 'this.active_func' value, -1 if none */
2007020068
int home_object_var_idx;
20071-
_Bool need_home_object : 1;
20069+
bool need_home_object : 1;
2007220070

2007320071
int scope_level; /* index into fd->scopes if the current lexical scope */
2007420072
int scope_first; /* index into vd->vars of first lexically scoped variable */
@@ -20084,7 +20082,7 @@ typedef struct JSFunctionDef {
2008420082

2008520083
DynBuf byte_code;
2008620084
int last_opcode_pos; /* -1 if no last opcode */
20087-
_Bool use_short_opcodes : 1; /* true if short opcodes are used in byte_code */
20085+
bool use_short_opcodes : 1; /* true if short opcodes are used in byte_code */
2008820086

2008920087
LabelSlot *label_slots;
2009020088
int label_size; /* allocated size for label_slots[] */
@@ -20122,7 +20120,7 @@ typedef struct JSFunctionDef {
2012220120
int source_len;
2012320121

2012420122
JSModuleDef *module; /* != NULL when parsing a module */
20125-
_Bool has_await : 1; /* true if await is used (used in module eval) */
20123+
bool has_await : 1; /* true if await is used (used in module eval) */
2012620124
} JSFunctionDef;
2012720125

2012820126
typedef struct JSToken {
@@ -20140,8 +20138,8 @@ typedef struct JSToken {
2014020138
} num;
2014120139
struct {
2014220140
JSAtom atom;
20143-
_Bool has_escape : 1;
20144-
_Bool is_reserved : 1;
20141+
bool has_escape : 1;
20142+
bool is_reserved : 1;
2014520143
} ident;
2014620144
struct {
2014720145
JSValue body;
@@ -20158,7 +20156,7 @@ typedef struct JSParseState {
2015820156
int col_num; /* column number of current offset */
2015920157
const char *filename;
2016020158
JSToken token;
20161-
_Bool got_lf : 1; /* true if got line feed before the current token */
20159+
bool got_lf : 1; /* true if got line feed before the current token */
2016220160
const uint8_t *last_ptr;
2016320161
const uint8_t *buf_start;
2016420162
const uint8_t *buf_ptr;
@@ -20168,8 +20166,8 @@ typedef struct JSParseState {
2016820166

2016920167
/* current function code */
2017020168
JSFunctionDef *cur_func;
20171-
_Bool is_module : 1; /* parsing a module */
20172-
_Bool allow_html_comments : 1;
20169+
bool is_module : 1; /* parsing a module */
20170+
bool allow_html_comments : 1;
2017320171
} JSParseState;
2017420172

2017520173
typedef struct JSOpCode {
@@ -22703,7 +22701,7 @@ typedef struct JSParsePos {
2270322701
int last_col_num;
2270422702
int line_num;
2270522703
int col_num;
22706-
_Bool got_lf : 1;
22704+
bool got_lf : 1;
2270722705
const uint8_t *ptr;
2270822706
const uint8_t *eol;
2270922707
const uint8_t *mark;
@@ -23116,9 +23114,9 @@ static JSAtom get_private_setter_name(JSContext *ctx, JSAtom name)
2311623114
typedef struct {
2311723115
JSFunctionDef *fields_init_fd;
2311823116
int computed_fields_count;
23119-
_Bool need_brand : 1;
23117+
bool need_brand : 1;
2312023118
int brand_push_pos;
23121-
_Bool is_static : 1;
23119+
bool is_static : 1;
2312223120
} ClassFieldsDef;
2312323121

2312423122
static __exception int emit_class_init_start(JSParseState *s,
@@ -35137,11 +35135,11 @@ typedef enum BCTagEnum {
3513735135
typedef struct BCWriterState {
3513835136
JSContext *ctx;
3513935137
DynBuf dbuf;
35140-
_Bool allow_bytecode : 1;
35141-
_Bool allow_sab : 1;
35142-
_Bool allow_reference : 1;
35143-
_Bool allow_source : 1;
35144-
_Bool allow_debug : 1;
35138+
bool allow_bytecode : 1;
35139+
bool allow_sab : 1;
35140+
bool allow_reference : 1;
35141+
bool allow_source : 1;
35142+
bool allow_debug : 1;
3514535143
uint32_t first_atom;
3514635144
uint32_t *atom_to_idx;
3514735145
int atom_to_idx_size;
@@ -36004,9 +36002,9 @@ typedef struct BCReaderState {
3600436002
uint32_t idx_to_atom_count;
3600536003
JSAtom *idx_to_atom;
3600636004
int error_state;
36007-
_Bool allow_sab : 1;
36008-
_Bool allow_bytecode : 1;
36009-
_Bool allow_reference : 1;
36005+
bool allow_sab : 1;
36006+
bool allow_bytecode : 1;
36007+
bool allow_reference : 1;
3601036008
/* object references */
3601136009
JSObject **objects;
3601236010
int objects_count;
@@ -41618,7 +41616,7 @@ static JSValue js_iterator_constructor(JSContext *ctx, JSValueConst new_target,
4161841616
// |index|, |count| and |running| because tcc miscompiles them
4161941617
typedef struct JSIteratorConcatData {
4162041618
int index, count; // elements (not pairs!) in values[] array
41621-
_Bool running : 1;
41619+
bool running : 1;
4162241620
JSValue iter, next, values[]; // array of (object, method) pairs
4162341621
} JSIteratorConcatData;
4162441622

@@ -46225,8 +46223,8 @@ static JSValue js_regexp_Symbol_match(JSContext *ctx, JSValueConst this_val,
4622546223
typedef struct JSRegExpStringIteratorData {
4622646224
JSValue iterating_regexp;
4622746225
JSValue iterated_string;
46228-
_Bool global : 1;
46229-
_Bool unicode : 1;
46226+
bool global : 1;
46227+
bool unicode : 1;
4623046228
int done;
4623146229
} JSRegExpStringIteratorData;
4623246230

@@ -50421,13 +50419,13 @@ typedef struct JSPromiseData {
5042150419
JSPromiseStateEnum promise_state;
5042250420
/* 0=fulfill, 1=reject, list of JSPromiseReactionData.link */
5042350421
struct list_head promise_reactions[2];
50424-
_Bool is_handled : 1; /* Note: only useful to debug */
50422+
bool is_handled : 1; /* Note: only useful to debug */
5042550423
JSValue promise_result;
5042650424
} JSPromiseData;
5042750425

5042850426
typedef struct JSPromiseFunctionDataResolved {
5042950427
int ref_count;
50430-
_Bool already_resolved : 1;
50428+
bool already_resolved : 1;
5043150429
} JSPromiseFunctionDataResolved;
5043250430

5043350431
typedef struct JSPromiseFunctionData {
@@ -57092,7 +57090,7 @@ static JSValue js_atomics_isLockFree(JSContext *ctx,
5709257090

5709357091
typedef struct JSAtomicsWaiter {
5709457092
struct list_head link;
57095-
_Bool linked : 1;
57093+
bool linked : 1;
5709657094
js_cond_t cond;
5709757095
int32_t *ptr;
5709857096
} JSAtomicsWaiter;

0 commit comments

Comments
 (0)