From: Vsevolod Stakhov Date: Sat, 2 May 2026 10:46:40 +0000 (+0100) Subject: [Minor] lua_upstream: pack acquired/retired into bitfields X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=c8c5a5d38eb1ff3fce8e397aa649221addf5e72d;p=thirdparty%2Frspamd.git [Minor] lua_upstream: pack acquired/retired into bitfields 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. --- diff --git a/src/lua/lua_common.h b/src/lua/lua_common.h index a3b9030b04..4f8b213b1e 100644 --- a/src/lua/lua_common.h +++ b/src/lua/lua_common.h @@ -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 */ diff --git a/src/lua/lua_upstream.c b/src/lua/lua_upstream.c index 31e0717982..f1a423694e 100644 --- a/src/lua/lua_upstream.c +++ b/src/lua/lua_upstream.c @@ -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);