From eaf38a6a69a088dec32d2d440b3240e503af12ac Mon Sep 17 00:00:00 2001 From: Julien Danjou Date: Thu, 29 May 2008 14:24:33 +0200 Subject: [PATCH] [xutil] Add list_attach_after() and use it for cache atom Signed-off-by: Julien Danjou --- common/list.h | 16 ++++++++++------ common/xutil.c | 8 +------- 2 files changed, 11 insertions(+), 13 deletions(-) diff --git a/common/list.h b/common/list.h index c59355f2..f230d070 100644 --- a/common/list.h +++ b/common/list.h @@ -154,9 +154,7 @@ { \ if(item->next) \ return item->next; \ - else \ - return *list; \ - return NULL; \ + return *list; \ } \ \ static inline type *prefix##_list_detach(type **list, type *item) \ @@ -170,16 +168,23 @@ item->next = NULL; \ item->prev = NULL; \ return item; \ + } \ + static inline type *prefix##_list_attach_after(type *item1, type *item2) \ + { \ + item2->prev = item1; \ + item2->next = item1->next; \ + if(item1->next) \ + item1->next->prev = item2; \ + item1->next = item2; \ + return item2; \ } #define DO_SLIST_UNREF(type, prefix, dtor) \ static inline void prefix##_list_unref(type **list) \ { \ type *next, *item = *list; \ - printf("list_unref\n");\ while(item) \ { \ - printf(" item %p refcount %d", item, item->refcount);\ next = item->next; \ if(--(item->refcount) <= 0) \ { \ @@ -188,7 +193,6 @@ } \ item = next; \ } \ - printf("end list_unref\n");\ } #endif diff --git a/common/xutil.c b/common/xutil.c index c129a1c4..42aea0d1 100644 --- a/common/xutil.c +++ b/common/xutil.c @@ -233,13 +233,7 @@ xutil_intern_atom_reply(xcb_connection_t *c, xutil_atom_cache_t **atoms, atom_next && atom_next->next && a_strcmp(atom_req.name, atom_next->next->name) > 0; atom_next = atom_cache_list_next(NULL, atom_next)); - atom_cache->prev = atom_next; - atom_cache->next = atom_next->next; - - if(atom_next->next) - atom_next->next->prev = atom_cache; - - atom_next->next = atom_cache; + atom_cache_list_attach_after(atom_next, atom_cache); } p_delete(&atom_rep);