Skip to content

Commit 84d0c0c

Browse files
committed
Optimize global variable lists
Reduce binary size by storing global variable lists as one long string instead of as an array of pointers to strings. This might also reduce load times (due to fewer relocations and less pointer chasing), but I haven't measured. platform | before | after ----------------+--------+------ darwin-x64.node | 826K | 826K linux-x64.node | 818K | 782K win32-ia32.node | 486K | 479K win32-x64.node | 670K | 656K
1 parent 5e5dd75 commit 84d0c0c

File tree

5 files changed

+1141
-1145
lines changed

5 files changed

+1141
-1145
lines changed

src/configuration.cpp

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -30,18 +30,19 @@ const global_declared_variable_set& configuration::globals() noexcept {
3030
return this->globals_;
3131
}
3232

33-
auto add_globals = [&](const char8* const* group_globals, bool shadowable,
33+
auto add_globals = [&](const char8* group_globals, bool shadowable,
3434
bool writable) -> void {
3535
if (!group_globals) {
3636
return;
3737
}
38-
for (const char8* const* it = group_globals; *it; ++it) {
39-
string8_view global(*it);
38+
for (const char8* it = group_globals; *it != '\0';) {
39+
string8_view global(it);
4040
if (!this->should_remove_global_variable(global)) {
4141
global_declared_variable* var = this->globals_.add_variable(global);
4242
var->is_shadowable = shadowable;
4343
var->is_writable = writable;
4444
}
45+
it += global.size() + 1;
4546
}
4647
};
4748
for (std::size_t i = 0; i < this->enabled_global_groups_.size(); ++i) {

0 commit comments

Comments
 (0)