]> git.rm.cloudns.org Git - xonotic/xonotic-data.pk3dir.git/commitdiff
Don't call these 2 LOG_FATALF directly from 2 macros that are called literally thousa...
authorterencehill <piuntn@gmail.com>
Mon, 4 Feb 2019 22:06:41 +0000 (23:06 +0100)
committerterencehill <piuntn@gmail.com>
Mon, 4 Feb 2019 22:06:41 +0000 (23:06 +0100)
Some stats:
server.qc 710KB smaller
client.qc 780KB smaller

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

server globals reduced by 2818 globals

qcsrc/common/impulses/all.qh
qcsrc/lib/registry.qh

index 8bd0c41dab29ec33e9f4f2877f00638e9578eb45..e5a2b7b6019a6bb7309908b51989426b208bdca7 100644 (file)
@@ -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); }
index 163ca17b40033190ff312f703dce90843011e8bc..4e8e09083f7749cb481655d64a0e01665f62b440 100644 (file)
@@ -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); \