浏览代码

Don't inline certain functions for smaller binary size.

Co-authored-by: Thaddeus Crews <[email protected]>
Yyf2333 6 月之前
父节点
当前提交
b28d6d1fa3
共有 4 个文件被更改,包括 20 次插入6 次删除
  1. 7 3
      SConstruct
  2. 7 1
      core/string/string_name.h
  3. 3 0
      core/string/ustring.h
  4. 3 2
      core/typedefs.h

+ 7 - 3
SConstruct

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

+ 7 - 1
core/string/string_name.h

@@ -208,7 +208,13 @@ public:
 	StringName() {}
 	StringName() {}
 
 
 	static void assign_static_unique_class_name(StringName *ptr, const char *p_name);
 	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
 		if (likely(configured) && _data) { //only free if configured
 			unref();
 			unref();
 		}
 		}

+ 3 - 0
core/string/ustring.h

@@ -617,6 +617,9 @@ public:
 	_FORCE_INLINE_ String(const String &p_str) { _cowdata._ref(p_str._cowdata); }
 	_FORCE_INLINE_ String(const String &p_str) { _cowdata._ref(p_str._cowdata); }
 	_FORCE_INLINE_ String(String &&p_str) :
 	_FORCE_INLINE_ String(String &&p_str) :
 			_cowdata(std::move(p_str._cowdata)) {}
 			_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=(const String &p_str) { _cowdata._ref(p_str._cowdata); }
 	_FORCE_INLINE_ void operator=(String &&p_str) { _cowdata = std::move(p_str._cowdata); }
 	_FORCE_INLINE_ void operator=(String &&p_str) { _cowdata = std::move(p_str._cowdata); }
 
 

+ 3 - 2
core/typedefs.h

@@ -65,9 +65,10 @@ static_assert(__cplusplus >= 201703L);
 #endif
 #endif
 #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_
 #ifndef _FORCE_INLINE_
-#ifdef DEV_ENABLED
+#if defined(DEV_ENABLED) || defined(SIZE_EXTRA)
 #define _FORCE_INLINE_ inline
 #define _FORCE_INLINE_ inline
 #else
 #else
 #define _FORCE_INLINE_ _ALWAYS_INLINE_
 #define _FORCE_INLINE_ _ALWAYS_INLINE_