--- rxvt-unicode/src/rxvtutil.h 2007/12/14 11:11:31 1.36 +++ rxvt-unicode/src/rxvtutil.h 2009/09/04 15:40:13 1.39 @@ -15,10 +15,18 @@ #if __GNUC__ >= 4 # define rxvt_attribute(x) __attribute__(x) +# define expect(expr,value) __builtin_expect ((expr),(value)) #else # define rxvt_attribute(x) +# define expect(expr,value) (expr) #endif +// put into ifs if you are very sure that the expression +// is mostly true or mosty false. note that these return +// booleans, not the expression. +#define expect_false(expr) expect ((expr) != 0, 0) +#define expect_true(expr) expect ((expr) != 0, 1) + #define NORETURN rxvt_attribute ((noreturn)) #define UNUSED rxvt_attribute ((unused)) #define CONST rxvt_attribute ((const)) @@ -85,12 +93,13 @@ // some bit functions, xft fuck me plenty #if HAVE_GCC_BUILTINS -static inline int ctz (unsigned int x) { return __builtin_ctz (x); } -static inline int popcount (unsigned int x) { return __builtin_popcount (x); } +/* netbsd stupidly defines popcount itself and puts it into string.h */ +static inline int rxvt_ctz (unsigned int x) { return __builtin_ctz (x); } +static inline int rxvt_popcount (unsigned int x) { return __builtin_popcount (x); } #else // count trailing zero bits and count # of one bits -int ctz (unsigned int x) CONST; -int popcount (unsigned int x) CONST; +int rxvt_ctz (unsigned int x) CONST; +int rxvt_popcount (unsigned int x) CONST; #endif // in range including end @@ -105,7 +114,8 @@ #define MOD(m,n) (((m) + (n)) % (n)) // makes dynamically allocated objects zero-initialised -struct zero_initialized { +struct zero_initialized +{ void *operator new (size_t s); void operator delete (void *p, size_t s); }; @@ -116,7 +126,8 @@ * Copyright (C) 1997-98 Kay Roemer & Arno Puder */ template -struct simplevec { +struct simplevec +{ typedef T* iterator; typedef const T* const_iterator; typedef unsigned long size_type; @@ -381,7 +392,8 @@ #if 0 template -struct rxvt_vec : simplevec { +struct rxvt_vec : simplevec +{ typedef T *iterator; void push_back (T d) { simplevec::push_back ((void *)d); } @@ -396,7 +408,8 @@ #endif template -struct auto_ptr { +struct auto_ptr +{ T *p; auto_ptr () : p (0) { }