From 472ed3e4e50a165638acecaf071ec3c2c13c451f Mon Sep 17 00:00:00 2001 From: Berke Güzel Date: Sun, 11 Oct 2026 23:27:41 +0300 Subject: core: optimize struct layouts, eliminate branches, and fix event loop dispatch - Fix Wayland event loop lockout by properly decoupling read arming and adding poll-backed dispatching - Support standalone display lifecycle without requiring caller to manage a loop - Eliminate alignment holes across yasl_surface, yasl_display, seat, touch_point, and conn_drag using pahole - Replace branching state/button decoders with compile-time locked LUTs and branchless bitwise operations - Accelerate UTF-8 validation with 64-bit word scanning for ASCII runs --- src/wayland/buffer.c | 31 ++++++++++++++++++------------- 1 file changed, 18 insertions(+), 13 deletions(-) (limited to 'src/wayland/buffer.c') diff --git a/src/wayland/buffer.c b/src/wayland/buffer.c index 492cfde..0d639e6 100644 --- a/src/wayland/buffer.c +++ b/src/wayland/buffer.c @@ -305,13 +305,20 @@ static void arm_frame(struct yasl_surface *w) } } +static const int8_t free_buf_lut[3][8] = { + [0] = { 1, 1, 2, 2, 1, 1, 0, -1 }, + [1] = { 0, 2, 0, 2, 0, 1, 0, -1 }, + [2] = { 0, 1, 0, 2, 0, 1, 0, -1 }, +}; + int buffer_pick_free_index(const struct buffer *bufs, int cur) { - if (!bufs[cur ^ 1].busy) return cur ^ 1; - for (int i = 0; i < NBUF; i++) - if (i != cur && i != (cur ^ 1) && !bufs[i].busy) return i; - if (!bufs[cur].busy) return cur; - return -1; + unsigned busy = ((unsigned)bufs[0].busy) | + (((unsigned)bufs[1].busy) << 1) | + (((unsigned)bufs[2].busy) << 2); + unsigned c = (unsigned)cur; + if (unlikely(c >= 3)) c = 0; + return free_buf_lut[c][busy]; } struct latency_feedback { @@ -523,14 +530,12 @@ void yasl_surface_set_title(struct yasl_surface *w, const char *title) uint32_t yasl_surface_state(const struct yasl_surface *w) { - if (!w) return 0; - uint32_t s = 0; - if (w->fullscreen) s |= YASL_STATE_FULLSCREEN; - if (w->maximized) s |= YASL_STATE_MAXIMIZED; - if (w->activated) s |= YASL_STATE_ACTIVATED; - if (w->suspended) s |= YASL_STATE_SUSPENDED; - if (!w->server_decorated) s |= YASL_STATE_CSD; - return s; + if (unlikely(!w)) return 0; + return ((uint32_t)w->fullscreen * YASL_STATE_FULLSCREEN) | + ((uint32_t)w->maximized * YASL_STATE_MAXIMIZED) | + ((uint32_t)w->activated * YASL_STATE_ACTIVATED) | + ((uint32_t)w->suspended * YASL_STATE_SUSPENDED) | + ((uint32_t)!w->server_decorated * YASL_STATE_CSD); } struct yasl_timing yasl_surface_timing(const struct yasl_surface *w) -- cgit v1.2.3