diff --git a/SConstruct b/SConstruct index cfe472467b8..b73d91791de 100644 --- a/SConstruct +++ b/SConstruct @@ -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"]) diff --git a/core/string/string_name.h b/core/string/string_name.h index 2be64de8c8a..66c7854fabb 100644 --- a/core/string/string_name.h +++ b/core/string/string_name.h @@ -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(); } diff --git a/core/string/ustring.h b/core/string/ustring.h index 6fe5e3d7088..0ad50fdd6c7 100644 --- a/core/string/ustring.h +++ b/core/string/ustring.h @@ -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); } diff --git a/core/typedefs.h b/core/typedefs.h index 62a6ab9553f..576f6a686d0 100644 --- a/core/typedefs.h +++ b/core/typedefs.h @@ -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_