Don't inline certain functions for smaller binary size.

Co-authored-by: Thaddeus Crews <repiteo@outlook.com>
This commit is contained in:
Yyf2333 2025-01-25 13:58:50 +08:00 committed by Yufeng Ying
parent fc827bbe25
commit b28d6d1fa3
4 changed files with 20 additions and 6 deletions

View File

@ -167,7 +167,7 @@ opts.Add(
"optimize",
"Optimization level (by default inferred from 'target' and 'dev_build')",
"auto",
("auto", "none", "custom", "debug", "speed", "speed_trace", "size"),
("auto", "none", "custom", "debug", "speed", "speed_trace", "size", "size_extra"),
)
)
opts.Add(BoolVariable("debug_symbols", "Build with debugging symbols", False))
@ -725,9 +725,11 @@ if env.msvc:
env.Append(LINKFLAGS=["/OPT:REF"])
if env["optimize"] == "speed_trace":
env.Append(LINKFLAGS=["/OPT:NOICF"])
elif env["optimize"] == "size":
elif env["optimize"].startswith("size"):
env.Append(CCFLAGS=["/O1"])
env.Append(LINKFLAGS=["/OPT:REF"])
if env["optimize"] == "size_extra":
env.Append(CPPDEFINES=["SIZE_EXTRA"])
elif env["optimize"] == "debug" or env["optimize"] == "none":
env.Append(CCFLAGS=["/Od"])
else:
@ -772,9 +774,11 @@ else:
elif env["optimize"] == "speed_trace":
env.Append(CCFLAGS=["-O2"])
env.Append(LINKFLAGS=["-O2"])
elif env["optimize"] == "size":
elif env["optimize"].startswith("size"):
env.Append(CCFLAGS=["-Os"])
env.Append(LINKFLAGS=["-Os"])
if env["optimize"] == "size_extra":
env.Append(CPPDEFINES=["SIZE_EXTRA"])
elif env["optimize"] == "debug":
env.Append(CCFLAGS=["-Og"])
env.Append(LINKFLAGS=["-Og"])

View File

@ -208,7 +208,13 @@ public:
StringName() {}
static void assign_static_unique_class_name(StringName *ptr, const char *p_name);
_FORCE_INLINE_ ~StringName() {
#ifdef SIZE_EXTRA
_NO_INLINE_
#else
_FORCE_INLINE_
#endif
~StringName() {
if (likely(configured) && _data) { //only free if configured
unref();
}

View File

@ -617,6 +617,9 @@ public:
_FORCE_INLINE_ String(const String &p_str) { _cowdata._ref(p_str._cowdata); }
_FORCE_INLINE_ String(String &&p_str) :
_cowdata(std::move(p_str._cowdata)) {}
#ifdef SIZE_EXTRA
_NO_INLINE_ ~String() {}
#endif
_FORCE_INLINE_ void operator=(const String &p_str) { _cowdata._ref(p_str._cowdata); }
_FORCE_INLINE_ void operator=(String &&p_str) { _cowdata = std::move(p_str._cowdata); }

View File

@ -65,9 +65,10 @@ static_assert(__cplusplus >= 201703L);
#endif
#endif
// Should always inline, except in dev builds because it makes debugging harder.
// Should always inline, except in dev builds because it makes debugging harder,
// or `size_enabled` builds where inlining is actively avoided.
#ifndef _FORCE_INLINE_
#ifdef DEV_ENABLED
#if defined(DEV_ENABLED) || defined(SIZE_EXTRA)
#define _FORCE_INLINE_ inline
#else
#define _FORCE_INLINE_ _ALWAYS_INLINE_