From 47d940485a1c9c184ddc73d3bd563ec21d7b2088 Mon Sep 17 00:00:00 2001 From: Willy Tarreau Date: Mon, 23 Jun 2008 22:39:37 +0200 Subject: [PATCH] [OPTIM] add branch prediction hints in list manipulations GCC does not do very clever things with the ifs in list manipulation macros. Adding a 'likely' helps it remove expensive jumps and useless code. --- include/common/mini-clist.h | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/include/common/mini-clist.h b/include/common/mini-clist.h index 9fe342de8..fca2d7627 100644 --- a/include/common/mini-clist.h +++ b/include/common/mini-clist.h @@ -1,6 +1,6 @@ /* * list.h : list manipulation macros and structures. - * Copyright 2002-2007 Willy Tarreau + * Copyright 2002-2008 Willy Tarreau * */ @@ -41,10 +41,10 @@ struct list { */ /* adds an element at the beginning of a dual-linked list ; returns the element */ -#define DLIST_ADD(lh, el) ({ typeof(el) __ret = (el); __ret->n = (void *)(lh); __ret->p = (void *)&(lh); if (__ret->n != NULL) __ret->n->p = __ret; (lh) = (typeof(lh))&__ret->n; __ret; }) +#define DLIST_ADD(lh, el) ({ typeof(el) __ret = (el); __ret->n = (void *)(lh); __ret->p = (void *)&(lh); if (likely(__ret->n != NULL)) __ret->n->p = __ret; (lh) = (typeof(lh))&__ret->n; __ret; }) /* removes an element from a dual-linked list and returns it */ -#define DLIST_DEL(el) ({ typeof(el) __ret = (el); if (__ret->n != NULL) __ret->n->p = __ret->p; __ret->p->n = __ret->n; __ret; }) +#define DLIST_DEL(el) ({ typeof(el) __ret = (el); if (likely(__ret->n != NULL)) __ret->n->p = __ret->p; __ret->p->n = __ret->n; __ret; }) /* * iterates through a list of items of type "" which are