summaryrefslogtreecommitdiff
path: root/src/wayland/surface.c
diff options
context:
space:
mode:
authorBerke Güzel <wenekar1@gmail.com>2026-10-12 14:27:51 +0300
committerBerke Güzel <wenekar1@gmail.com>2026-10-12 14:27:51 +0300
commit9ed89c17dee752154c36d71cae93d20cccfc71ef (patch)
treea32cd894643ff6f6ebce83dd745bd24b35eb6520 /src/wayland/surface.c
parentaedd863e6f66fd446227e9b107bc9c1970092634 (diff)
perf: optimize hot-path loops, data structures, and cache locality
Diffstat (limited to 'src/wayland/surface.c')
-rw-r--r--src/wayland/surface.c12
1 files changed, 10 insertions, 2 deletions
diff --git a/src/wayland/surface.c b/src/wayland/surface.c
index ce1764b..242531c 100644
--- a/src/wayland/surface.c
+++ b/src/wayland/surface.c
@@ -321,7 +321,11 @@ static void conn_unlink(struct wayland_surface *w)
struct wayland_surface *conn_surface_for(struct wayland_display *c, struct wl_surface *s)
{
- for (struct wayland_surface *w = c->surfaces; w && s; w = w->conn_next)
+ if (unlikely(!c || !s)) return NULL;
+ struct wayland_surface *fast = (struct wayland_surface *)wl_surface_get_user_data(s);
+ if (likely(fast && fast->conn == c && fast->surface == s))
+ return fast;
+ for (struct wayland_surface *w = c->surfaces; w; w = w->conn_next)
if (w->surface == s)
return w;
return NULL;
@@ -361,6 +365,7 @@ struct wayland_surface *wayland_surface_create_toplevel(struct wayland_display *
w->surface = wl_compositor_create_surface(c->compositor);
if (!w->surface) goto err;
+ wl_surface_set_user_data(w->surface, w);
if (surface_init_scaling(w) < 0) goto err;
if (surface_init_shell(w, spec->title) < 0) goto err;
w->opaque = spec->fullscreen;
@@ -420,7 +425,10 @@ void wayland_surface_destroy(struct wayland_surface *w)
if (w->toplevel) xdg_toplevel_destroy(w->toplevel);
if (w->popup) xdg_popup_destroy(w->popup);
if (w->xdg_surface) xdg_surface_destroy(w->xdg_surface);
- if (w->surface) wl_surface_destroy(w->surface);
+ if (w->surface) {
+ wl_surface_set_user_data(w->surface, NULL);
+ wl_surface_destroy(w->surface);
+ }
struct wayland_display *c = w->conn;
conn_unlink(w);
static const struct yasl_surface_cbs no_callbacks = {0};