]> git.ipfire.org Git - thirdparty/rspamd.git/commitdiff
[Minor] lua_upstream: pack acquired/retired into bitfields 6013/head
authorVsevolod Stakhov <vsevolod@rspamd.com>
Sat, 2 May 2026 10:46:40 +0000 (11:46 +0100)
committerVsevolod Stakhov <vsevolod@rspamd.com>
Sat, 2 May 2026 10:46:40 +0000 (11:46 +0100)
Two gboolean (gint) fields cost 8 padded bytes plus alignment per
wrapper. Each wrapper only needs two bits, so use unsigned:1
bitfields instead. struct rspamd_lua_upstream shrinks from 24 to
16 bytes on 64-bit targets.

No behaviour change.

src/lua/lua_common.h
src/lua/lua_upstream.c

index a3b9030b04ed2558b7d20d043f0e86f3f834c3cb..4f8b213b1e810ddc3d47ded320b43e461637df83 100644 (file)
@@ -177,11 +177,12 @@ struct rspamd_lua_upstream {
         * first time :ok or :fail is called. If acquired && !retired at __gc
         * time, the destructor calls rspamd_upstream_release so abandoned
         * selections don't permanently skew P2C scoring. Wrappers handed out
-        * by all_upstreams() or watch callbacks set acquired = FALSE and the
-        * destructor leaves inflight alone.
+        * by all_upstreams() or watch callbacks set acquired = 0 and the
+        * destructor leaves inflight alone. Bitfields keep the wrapper at
+        * sizeof(ptr) + 8 instead of bloating it with two padded gint slots.
         */
-       gboolean acquired;
-       gboolean retired;
+       unsigned int acquired : 1;
+       unsigned int retired : 1;
 };
 
 /* Common utility functions */
index 31e071798218000c50805e63b602db48f42674e8..f1a423694e4ef12738b53505966da675f77eaef5 100644 (file)
@@ -197,7 +197,7 @@ lua_upstream_fail(lua_State *L)
                }
 
                rspamd_upstream_fail(up->up, fail_addr, reason);
-               up->retired = TRUE;
+               up->retired = 1;
        }
 
        return 0;
@@ -215,7 +215,7 @@ lua_upstream_ok(lua_State *L)
 
        if (up) {
                rspamd_upstream_ok(up->up);
-               up->retired = TRUE;
+               up->retired = 1;
        }
 
        return 0;
@@ -268,8 +268,8 @@ lua_push_upstream(lua_State *L, int up_idx, struct upstream *up,
 
        lua_ups = lua_newuserdata(L, sizeof(*lua_ups));
        lua_ups->up = up;
-       lua_ups->acquired = acquired;
-       lua_ups->retired = FALSE;
+       lua_ups->acquired = acquired ? 1 : 0;
+       lua_ups->retired = 0;
        rspamd_lua_setclass(L, rspamd_upstream_classname, -1);
        /* Store parent in the upstream to prevent gc */
        lua_pushvalue(L, up_idx);
@@ -586,8 +586,8 @@ lua_upstream_watch_func(struct upstream *up,
        struct rspamd_lua_upstream *lua_ups = lua_newuserdata(L, sizeof(*lua_ups));
        lua_ups->up = up;
        /* Watcher event: no inflight reference, leave it that way on __gc. */
-       lua_ups->acquired = FALSE;
-       lua_ups->retired = FALSE;
+       lua_ups->acquired = 0;
+       lua_ups->retired = 0;
        rspamd_lua_setclass(L, rspamd_upstream_classname, -1);
        /* Store parent in the upstream to prevent gc */
        lua_rawgeti(L, LUA_REGISTRYINDEX, cdata->parent_cbref);