Skip to content

armgit / godot

Public Imported from GitHub
0

Godot Engine – Multi-platform 2D and 3D game engine

Move `StringName::Table` data into zero-fill sections to save 512kb.

Lukas Tenbrink4e073f9e1c8e
diff --git a/core/string/string_name.cpp b/core/string/string_name.cpp
index 0892ad00b6b..b5be87e90cb 100644
--- a/core/string/string_name.cpp
+++ b/core/string/string_name.cpp
@@ -40,11 +40,19 @@ struct StringName::Table {
constexpr static uint32_t TABLE_LEN = 1 << TABLE_BITS;
constexpr static uint32_t TABLE_MASK = TABLE_LEN - 1;
- static inline _Data *table[TABLE_LEN];
- static inline BinaryMutex mutex;
- static inline PagedAllocator<_Data> allocator;
+ static _Data *table[TABLE_LEN];
+ static BinaryMutex mutex;
+ static PagedAllocator<_Data> allocator;
};
+// Defined out-of-class instead of using static inline so the compiler can
+// place the table in the zero-fill region (.bss) instead of the initialized
+// data section (.data). Because the zero-fill region is allocated at runtime,
+// this shrinks the binary size on disk.
+StringName::_Data *StringName::Table::table[TABLE_LEN];
+BinaryMutex StringName::Table::mutex;
+PagedAllocator<StringName::_Data> StringName::Table::allocator;
+
void StringName::setup() {
ERR_FAIL_COND(configured);
for (uint32_t i = 0; i < Table::TABLE_LEN; i++) {