From 2b52edd9e385a2d36965af73ce722032a7f94c0c Mon Sep 17 00:00:00 2001 From: Yuxuan Shui <yshuiv7@gmail.com> Date: Fri, 16 Feb 2024 01:00:50 +0000 Subject: [PATCH] cache: hide details of struct atom_entry Signed-off-by: Yuxuan Shui <yshuiv7@gmail.com> --- src/atom.c | 9 +++++++++ src/atom.h | 13 ++----------- 2 files changed, 11 insertions(+), 11 deletions(-) diff --git a/src/atom.c b/src/atom.c index 8ef699e8..fdcf73a9 100644 --- a/src/atom.c +++ b/src/atom.c @@ -8,6 +8,11 @@ #include "log.h" #include "utils.h" +struct atom_entry { + struct cache_handle entry; + xcb_atom_t atom; +}; + static inline int atom_getter(struct cache *cache attr_unused, const char *atom_name, struct cache_handle **value, void *user_data) { xcb_connection_t *c = user_data; @@ -45,6 +50,10 @@ xcb_atom_t get_atom(struct atom *a, const char *key, xcb_connection_t *c) { return cache_entry(entry, struct atom_entry, entry)->atom; } +xcb_atom_t get_atom_cached(struct atom *a, const char *key) { + return cache_entry(cache_get(&a->c, key), struct atom_entry, entry)->atom; +} + /** * Create a new atom structure and fetch all predefined atoms */ diff --git a/src/atom.h b/src/atom.h index d5a41d58..0cebe3a0 100644 --- a/src/atom.h +++ b/src/atom.h @@ -1,10 +1,7 @@ #pragma once -#include <stdlib.h> - #include <xcb/xcb.h> #include "cache.h" -#include "log.h" #include "meta.h" // clang-format off @@ -54,24 +51,18 @@ #define ATOM_DEF(x) xcb_atom_t a##x +struct atom_entry; struct atom { struct cache c; LIST_APPLY(ATOM_DEF, SEP_COLON, ATOM_LIST1); LIST_APPLY(ATOM_DEF, SEP_COLON, ATOM_LIST2); }; -struct atom_entry { - struct cache_handle entry; - xcb_atom_t atom; -}; - /// Create a new atom object with a xcb connection. `struct atom` does not hold /// a reference to the connection. struct atom *init_atoms(xcb_connection_t *c); xcb_atom_t get_atom(struct atom *a, const char *key, xcb_connection_t *c); -static inline xcb_atom_t get_atom_cached(struct atom *a, const char *key) { - return cache_entry(cache_get(&a->c, key), struct atom_entry, entry)->atom; -} +xcb_atom_t get_atom_cached(struct atom *a, const char *key); void destroy_atoms(struct atom *a);