… | |
… | |
13 | |
13 | |
14 | #define HAVE_GCC_BUILTINS (__GNUC__ >= 4 || (__GNUC__ == 3 && __GNUC_MINOR__ == 4)) |
14 | #define HAVE_GCC_BUILTINS (__GNUC__ >= 4 || (__GNUC__ == 3 && __GNUC_MINOR__ == 4)) |
15 | |
15 | |
16 | #if __GNUC__ >= 4 |
16 | #if __GNUC__ >= 4 |
17 | # define rxvt_attribute(x) __attribute__(x) |
17 | # define rxvt_attribute(x) __attribute__(x) |
|
|
18 | # define expect(expr,value) __builtin_expect ((expr),(value)) |
18 | #else |
19 | #else |
19 | # define rxvt_attribute(x) |
20 | # define rxvt_attribute(x) |
|
|
21 | # define expect(expr,value) (expr) |
20 | #endif |
22 | #endif |
|
|
23 | |
|
|
24 | // put into ifs if you are very sure that the expression |
|
|
25 | // is mostly true or mosty false. note that these return |
|
|
26 | // booleans, not the expression. |
|
|
27 | #define expect_false(expr) expect ((expr) != 0, 0) |
|
|
28 | #define expect_true(expr) expect ((expr) != 0, 1) |
21 | |
29 | |
22 | #define NORETURN rxvt_attribute ((noreturn)) |
30 | #define NORETURN rxvt_attribute ((noreturn)) |
23 | #define UNUSED rxvt_attribute ((unused)) |
31 | #define UNUSED rxvt_attribute ((unused)) |
24 | #define CONST rxvt_attribute ((const)) |
32 | #define CONST rxvt_attribute ((const)) |
25 | |
33 | |
… | |
… | |
98 | ((unsigned int)(val) - (unsigned int)(beg) <= (unsigned int)(end) - (unsigned int)(beg)) |
106 | ((unsigned int)(val) - (unsigned int)(beg) <= (unsigned int)(end) - (unsigned int)(beg)) |
99 | |
107 | |
100 | // in range excluding end |
108 | // in range excluding end |
101 | #define IN_RANGE_EXC(val,beg,end) \ |
109 | #define IN_RANGE_EXC(val,beg,end) \ |
102 | ((unsigned int)(val) - (unsigned int)(beg) < (unsigned int)(end) - (unsigned int)(beg)) |
110 | ((unsigned int)(val) - (unsigned int)(beg) < (unsigned int)(end) - (unsigned int)(beg)) |
|
|
111 | |
|
|
112 | // for m >= -n, ensure remainder lies between 0..n-1 |
|
|
113 | #define MOD(m,n) (((m) + (n)) % (n)) |
103 | |
114 | |
104 | // makes dynamically allocated objects zero-initialised |
115 | // makes dynamically allocated objects zero-initialised |
105 | struct zero_initialized { |
116 | struct zero_initialized { |
106 | void *operator new (size_t s); |
117 | void *operator new (size_t s); |
107 | void operator delete (void *p, size_t s); |
118 | void operator delete (void *p, size_t s); |
… | |
… | |
362 | } |
373 | } |
363 | |
374 | |
364 | |
375 | |
365 | template<typename T> |
376 | template<typename T> |
366 | struct vector : simplevec<T> |
377 | struct vector : simplevec<T> |
367 | { }; |
378 | { |
|
|
379 | }; |
368 | |
380 | |
369 | struct stringvec : simplevec<char *> |
381 | struct stringvec : simplevec<char *> |
370 | { |
382 | { |
371 | ~stringvec () |
383 | ~stringvec () |
372 | { |
384 | { |
373 | for (char **c = begin (); c != end (); c++) |
385 | for (char **c = begin (); c != end (); c++) |
374 | free (*c); |
386 | free (*c); |
375 | } |
387 | } |
376 | }; |
388 | }; |
377 | |
389 | |
|
|
390 | #if 0 |
378 | template<typename T> |
391 | template<typename T> |
379 | struct rxvt_vec : simplevec<void *> { |
392 | struct rxvt_vec : simplevec<void *> { |
380 | typedef T *iterator; |
393 | typedef T *iterator; |
381 | |
394 | |
382 | void push_back (T d) { simplevec<void *>::push_back ((void *)d); } |
395 | void push_back (T d) { simplevec<void *>::push_back ((void *)d); } |
… | |
… | |
386 | iterator begin () const { return (iterator)simplevec<void *>::begin (); } |
399 | iterator begin () const { return (iterator)simplevec<void *>::begin (); } |
387 | iterator end () const { return (iterator)simplevec<void *>::end (); } |
400 | iterator end () const { return (iterator)simplevec<void *>::end (); } |
388 | T &operator [] (int i) { return * (T *) (& ((* (simplevec<void *> *)this)[i])); } |
401 | T &operator [] (int i) { return * (T *) (& ((* (simplevec<void *> *)this)[i])); } |
389 | const T &operator [] (int i) const { return * (const T *) (& ((* (const simplevec<void *> *)this)[i])); } |
402 | const T &operator [] (int i) const { return * (const T *) (& ((* (const simplevec<void *> *)this)[i])); } |
390 | }; |
403 | }; |
|
|
404 | #endif |
391 | |
405 | |
392 | template<typename T> |
406 | template<typename T> |
393 | struct auto_ptr { |
407 | struct auto_ptr { |
394 | T *p; |
408 | T *p; |
395 | |
409 | |