Add a pointer to SLIST struct to store previous element

This will make back cycling faster
This commit is contained in:
Julien Danjou 2008-03-10 10:37:23 +01:00
parent 28af9e7e61
commit f3652aaca6
13 changed files with 96 additions and 59 deletions

View File

@ -60,7 +60,7 @@ typedef struct item_t item_t;
struct item_t
{
char *data;
item_t *next;
item_t *prev, *next;
Bool match;
};
@ -363,7 +363,7 @@ compute_match(const char *word)
if(a_strlen(globalconf.text))
item_list_fill_file(NULL);
for(item = globalconf.items; item; item = item->next)
item->match = True;
item->match = True;
}
}
@ -389,7 +389,7 @@ static void
redraw(void)
{
item_t *item;
Area geometry = { 0, 0, 0, 0, NULL };
Area geometry = { 0, 0, 0, 0, NULL, NULL };
Bool selected_item_is_drawn = False;
int len, prompt_len, x_of_previous_item;
@ -604,7 +604,7 @@ main(int argc, char **argv)
char *configfile = NULL, *cmd;
ssize_t len;
const char *shell = getenv("SHELL");
Area geometry = { 0, 0, 0, 0, NULL };
Area geometry = { 0, 0, 0, 0, NULL, NULL };
static struct option long_options[] =
{
{"help", 0, NULL, 'h'},

View File

@ -137,8 +137,8 @@ main(int argc, char **argv)
SimpleWindow *sw;
DrawCtx *ctx;
XEvent ev;
Area geometry = { 0, 0, 200, 50, NULL },
icon_geometry = { -1, -1, -1, -1, NULL };
Area geometry = { 0, 0, 200, 50, NULL, NULL },
icon_geometry = { -1, -1, -1, -1, NULL, NULL };
int opt, ret;
int delay = 0;
char *configfile = NULL;

View File

@ -531,7 +531,7 @@ draw_image(DrawCtx *ctx, int x, int y, int wanted_h, const char *filename)
Area
draw_get_image_size(const char *filename)
{
Area size = { -1, -1, -1, -1, NULL };
Area size = { -1, -1, -1, -1, NULL, NULL };
cairo_surface_t *surface;
cairo_status_t cairo_st;

View File

@ -46,7 +46,7 @@ struct Area
int y;
int width;
int height;
Area *next;
Area *prev, *next;
};
DO_SLIST(Area, area, p_delete);

View File

@ -29,19 +29,25 @@
{ \
return item->next; \
} \
\
static inline type *prefix##_list_pop(type **list) \
{ \
if (*list) \
{ \
type *res = *list; \
*list = res->next; \
if(res->next) \
res->next->prev = NULL; \
res->next = NULL; \
return res; \
} \
return NULL; \
} \
\
static inline void prefix##_list_push(type **list, type *item) \
{ \
if(*list) \
(*list)->prev = item; \
item->next = *list; \
*list = item; \
} \
@ -56,10 +62,14 @@
static inline void prefix##_list_append(type **list, type *item) \
{ \
if(*(list = prefix##_list_last(list))) \
{ \
(*list)->next = item; \
item->prev = *list; \
} \
else \
(*list) = item; \
} \
\
static inline type *prefix##_list_rev(type *list) \
{ \
type *l = NULL; \
@ -73,6 +83,7 @@
*list = NULL; \
return list; \
} \
\
static inline void prefix##_list_wipe(type **list) \
{ \
while (*list) \
@ -81,62 +92,83 @@
dtor(&item); \
} \
} \
static inline type *prefix##_list_prev(type **list, type *item) \
\
static inline type *prefix##_list_prev(type **list __attribute__ ((unused)), \
type *item) \
{ \
type *tmp; \
if(*list == item) return NULL; \
for(tmp = *list; tmp && tmp->next != item; tmp = tmp->next); \
return tmp; \
return item->prev; \
} \
static inline void prefix##_list_swap(type **list, type *item1, \
type *item2) \
\
static inline void prefix##_list_swap(type **list, type *item1, type *item2) \
{ \
if(!item1 || !item2) return; \
\
type *i1n = item1->next; \
type *i2n = item2->next; \
type * i1p = prefix##_list_prev(list, item1); \
type * i2p = prefix##_list_prev(list, item2); \
item1->next = i2n == item1 ? item2 : i2n; \
item2->next = i1n == item2 ? item1 : i1n; \
\
\
if(i1p && i1p != item2) \
i1p->next = item2; \
if(i2p && i2p != item1) \
i2p->next = item1; \
type *i1p = item1->prev; \
type *i2p = item2->prev; \
\
if(item1 == i2n) \
{ \
item1->next = item2; \
item2->prev = item1; \
if((item1->prev = i2p)) \
i2p->next = item1; \
if((item2->next = i1n)) \
i1n->prev = item2; \
} \
else if(item2 == i1n) \
{ \
item2->next = item1; \
item1->prev = item2; \
if((item2->prev = i1p)) \
i1p->next = item2; \
if((item1->next = i2n)) \
i2n->prev = item1; \
} \
else \
{ \
if((item1->next = i2n)) \
item1->next->prev = item1; \
if((item1->prev = i2p)) \
item1->prev->next = item1; \
if((item2->prev = i1p)) \
item2->prev->next = item2; \
if((item2->next = i1n)) \
item2->next->prev = item2; \
} \
if(*list == item1) \
*list = item2; \
else if(*list == item2) \
*list = item1; \
} \
\
static inline type *prefix##_list_prev_cycle(type **list, type *item) \
{ \
type *tmp = prefix##_list_prev(list, item); \
if(!tmp) \
tmp = *prefix##_list_last(list); \
return tmp; \
if(!item->prev) \
return *prefix##_list_last(list); \
return item->prev; \
} \
\
static inline type *prefix##_list_next_cycle(type **list, type *item) \
{ \
if(item) \
{ \
if(item->next) \
return item->next; \
else \
return *list; \
} \
if(item->next) \
return item->next; \
else \
return *list; \
return NULL; \
} \
\
static inline void prefix##_list_detach(type **list, type *item) \
{ \
type *prev = prefix##_list_prev(list, item); \
if(prev) \
prev->next = item->next; \
if(item == *list) \
*list = item->next; \
else if(item->prev) \
item->prev->next = item->next; \
if(item->next) \
item->next->prev = item->prev; \
item->next = NULL; \
item->prev = NULL; \
} \
#endif

View File

@ -35,7 +35,7 @@ struct Layout
{
char *image;
LayoutArrange *arrange;
Layout *next;
Layout *prev, *next;
};
DO_SLIST(Layout, layout, p_delete);

View File

@ -133,7 +133,7 @@ _tile(int screen, const Position position)
unsigned int mw = 0, mh = 0;
int n, i, masterwin = 0, otherwin = 0;
int real_ncol = 1, win_by_col = 1, current_col = 0;
Area area, geometry = { 0, 0, 0, 0, NULL };
Area area, geometry = { 0, 0, 0, 0, NULL, NULL };
Client *c;
Tag **curtags = tags_get_current(screen);

View File

@ -149,7 +149,7 @@ uicb_client_resizemouse(int screen, char *arg __attribute__ ((unused)))
Client *c = globalconf.focus->client;
Tag **curtags = tags_get_current(screen);
Layout *layout = curtags[0]->layout;
Area area = { 0, 0, 0, 0 , NULL}, geometry;
Area area = { 0, 0, 0, 0, NULL, NULL }, geometry;
double mwfact;
/* only handle floating and tiled layouts */

View File

@ -64,7 +64,7 @@ Area
placement_smart(Area geometry, int border, int screen)
{
Client *c;
Area newgeometry = { 0, 0, 0, 0, NULL };
Area newgeometry = { 0, 0, 0, 0, NULL, NULL };
Area *screen_geometry, *arealist = NULL, *r;
Bool found = False;

View File

@ -81,7 +81,7 @@ screen_get_area(int screen, Statusbar *statusbar, Padding *padding)
Area
get_display_area(int screen, Statusbar *statusbar, Padding *padding)
{
Area area = { 0, 0, 0, 0, NULL };
Area area = { 0, 0, 0, 0, NULL, NULL };
Statusbar *sb;
area.width = DisplayWidth(globalconf.display, screen);

View File

@ -74,7 +74,7 @@ statusbar_draw(Statusbar *statusbar)
int phys_screen = get_phys_screen(statusbar->screen);
Widget *widget;
int left = 0, right = 0;
Area rectangle = { 0, 0, 0, 0, NULL };
Area rectangle = { 0, 0, 0, 0, NULL, NULL };
Drawable d;
/* don't waste our time */

View File

@ -66,7 +66,8 @@ struct Rule
regex_t *prop_r;
regex_t *tags_r;
regex_t *xpropval_r;
Rule *next;
/** Next and previous rules */
Rule *prev, *next;
};
/** Key bindings */
@ -77,7 +78,8 @@ struct Key
KeyCode keycode;
Uicb *func;
char *arg;
Key *next;
/** Next and previous keys */
Key *prev, *next;
};
/** Mouse buttons bindings */
@ -88,7 +90,8 @@ struct Button
unsigned int button;
Uicb *func;
char *arg;
Button *next;
/** Next and previous buttons */
Button *prev, *next;
};
/** Widget tell status code */
@ -138,8 +141,8 @@ struct Widget
Bool needs_update;
int flags;
} cache;
/** Next widget */
Widget *next;
/** Next and previous widgets */
Widget *prev, *next;
};
/** Status bar */
@ -161,8 +164,8 @@ struct Statusbar
int screen;
/** Widget list */
Widget *widgets;
/** Next statusbar */
Statusbar *next;
/** Next and previous statusbars */
Statusbar *prev, *next;
};
/** Client type */
@ -194,8 +197,8 @@ struct Client
Bool skip;
/** True if the client must be skipped from task bar client list */
Bool skiptb;
/** Next client */
Client *next;
/** Next and previous clients */
Client *prev, *next;
/** Window of the client */
Window win;
/** Client logical screen */
@ -208,7 +211,8 @@ typedef struct client_node_t client_node_t;
struct client_node_t
{
Client *client;
client_node_t *next;
/** Next and previous client_nodes */
client_node_t *prev, *next;
};
/** Tag type */
@ -231,8 +235,8 @@ struct Tag
int nmaster;
/** Number of columns in tile layout */
int ncol;
/** Next tag */
Tag *next;
/** Next and previous tags */
Tag *prev, *next;
};
/** tag_client_node type */
@ -241,7 +245,8 @@ struct tag_client_node_t
{
Tag *tag;
Client *client;
tag_client_node_t *next;
/** Next and previous tag_client_nodes */
tag_client_node_t *prev, *next;
};
/** Padding type */

View File

@ -116,7 +116,7 @@ taglist_draw(Widget *widget,
widget->area.y,
flagsize,
flagsize,
NULL };
NULL, NULL };
draw_rectangle(ctx, rectangle, sel && is_client_tagged(sel, tag), colors[ColFG]);
}
widget->area.width += w;