Skip to content

Commit 25d1a1a

Browse files
committed
src: make the options structs smaller with packed bits
While the Options objects are not a significant overhead, they still waste a few hundred bytes due to sloppy definition and alignment issues. Tighten it up and shave off a couple hundred wasted bytes. Signed-off-by: James M Snell <jasnell@gmail.com>
1 parent 5f1ef0a commit 25d1a1a

3 files changed

Lines changed: 407 additions & 340 deletions

File tree

src/node_options-inl.h

Lines changed: 20 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -31,17 +31,19 @@ namespace options_parser {
3131
template <typename Options>
3232
void OptionsParser<Options>::AddOption(const char* name,
3333
const char* help_text,
34-
bool Options::*field,
34+
bool (*getter)(Options*),
35+
void (*setter)(Options*, bool),
3536
OptionEnvvarSettings env_setting,
3637
bool default_is_true,
3738
OptionNamespaces namespace_id) {
38-
options_.emplace(name,
39-
OptionInfo{kBoolean,
40-
std::make_shared<SimpleOptionField<bool>>(field),
41-
env_setting,
42-
help_text,
43-
default_is_true,
44-
NamespaceEnumToString(namespace_id)});
39+
options_.emplace(
40+
name,
41+
OptionInfo{kBoolean,
42+
std::make_shared<BitFieldOptionField>(getter, setter),
43+
env_setting,
44+
help_text,
45+
default_is_true,
46+
NamespaceEnumToString(namespace_id)});
4547
}
4648

4749
template <typename Options>
@@ -207,6 +209,13 @@ auto OptionsParser<Options>::Convert(
207209
return original->LookupImpl((options->*get_child)());
208210
}
209211

212+
bool GetBool(Options* options) const override {
213+
return original->GetBool((options->*get_child)());
214+
}
215+
void SetBool(Options* options, bool value) override {
216+
original->SetBool((options->*get_child)(), value);
217+
}
218+
210219
AdaptedField(
211220
std::shared_ptr<OriginalField> original,
212221
ChildOptions* (Options::* get_child)())
@@ -432,8 +441,8 @@ void OptionsParser<Options>::Parse(
432441
if (value.type == kV8Option) {
433442
v8_args->push_back(value.name);
434443
} else {
435-
*value.target_field->template Lookup<bool>(
436-
options) = value.target_value;
444+
value.target_field->SetBool(options,
445+
value.target_value);
437446
}
438447
});
439448
}
@@ -479,7 +488,7 @@ void OptionsParser<Options>::Parse(
479488

480489
switch (info.type) {
481490
case kBoolean:
482-
*Lookup<bool>(info.field, options) = !is_negation;
491+
info.field->SetBool(options, !is_negation);
483492
break;
484493
case kInteger: {
485494
// Special case to pass --stack-trace-limit down to V8.

0 commit comments

Comments
 (0)