From: terencehill <piuntn@gmail.com>
Date: Mon, 4 Feb 2019 22:06:41 +0000 (+0100)
Subject: Don't call these 2 LOG_FATALF directly from 2 macros that are called literally thousa... 
X-Git-Tag: xonotic-v0.8.5~1609
X-Git-Url: https://git.rm.cloudns.org/?a=commitdiff_plain;h=5d24750ce0e47b80c4ad26a9fa8a5a1020d969d2;p=xonotic%2Fxonotic-data.pk3dir.git

Don't call these 2 LOG_FATALF directly from 2 macros that are called literally thousands times in order to reduce compilation output and globals (strings containing filename and line number)

Some stats:
server.qc 710KB smaller
client.qc 780KB smaller

progs.dat 340KB smaller
csprogs.dat 330KB smaller

server globals reduced by 2818 globals
---

diff --git a/qcsrc/common/impulses/all.qh b/qcsrc/common/impulses/all.qh
index 8bd0c41da..e5a2b7b60 100644
--- a/qcsrc/common/impulses/all.qh
+++ b/qcsrc/common/impulses/all.qh
@@ -27,10 +27,17 @@ REGISTRY_CHECK(IMPULSES)
 
 #define LEGACY_IMPULSE_ID(alias, id) LEGACY_IMPULSE(alias, id, sprintf("impulse %d", IMP_##alias.impulse))
 
+void _impCheck(string s, string alias)
+{
+	// this is inside a function to avoid expanding it on compilation everytime
+	if (s == alias)
+		LOG_FATALF("LEGACY_IMPULSE: would define a recursive alias for '%s', use LEGACY_IMPULSE_ID instead", s);
+}
+
 #define LEGACY_IMPULSE(alias, id, new) \
 	STATIC_INIT(legacy_##alias) { \
 		string s = new; \
-		if (s == #alias) LOG_FATALF("LEGACY_IMPULSE: would define a recursive alias for '%s', use LEGACY_IMPULSE_ID instead", s); \
+		_impCheck(s, #alias); \
 		IMPULSE_ALIAS(alias, s); \
 	} \
 	SHUTDOWN(legacy_##alias) { IMPULSE_ALIAS(alias, "impulse " #id); }
diff --git a/qcsrc/lib/registry.qh b/qcsrc/lib/registry.qh
index 163ca17b4..4e8e09083 100644
--- a/qcsrc/lib/registry.qh
+++ b/qcsrc/lib/registry.qh
@@ -52,6 +52,14 @@ REGISTRY(Registries, BITS(8))
 /** registered item identifier */
 .string registered_id;
 
+void _regCheck(int i, int _max)
+{
+	// this is inside a function to avoid expanding it on compilation everytime
+	// (this very long line would be repeated literally thousands times!)
+	if (i >= _max)
+		LOG_FATALF("Registry capacity exceeded (%d)", _max);
+}
+
 /**
  * Register a new entity with a registry.
  * Must be followed by a semicolon or a function body with a `this` parameter.
@@ -79,7 +87,7 @@ REGISTRY(Registries, BITS(8))
 	{ \
 		entity this = id; \
 		if (this == NULL) { \
-			if (registry##_COUNT >= registry##_MAX) LOG_FATALF("Registry capacity exceeded (%d)", registry##_MAX); \
+			_regCheck(registry##_COUNT, registry##_MAX); \
 			this = id = inst; \
 			this.registered_id = #id; \
 			REGISTRY_PUSH(registry, fld, this); \