ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/rxvt-unicode/src/rxvtutil.h
(Generate patch)

Comparing rxvt-unicode/src/rxvtutil.h (file contents):
Revision 1.36 by ayin, Fri Dec 14 11:11:31 2007 UTC vs.
Revision 1.39 by root, Fri Sep 4 15:40:13 2009 UTC

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
83 return (T *)rxvt_temp_buf (len * sizeof (T)); 91 return (T *)rxvt_temp_buf (len * sizeof (T));
84} 92}
85 93
86// some bit functions, xft fuck me plenty 94// some bit functions, xft fuck me plenty
87#if HAVE_GCC_BUILTINS 95#if HAVE_GCC_BUILTINS
96/* netbsd stupidly defines popcount itself and puts it into string.h */
88static inline int ctz (unsigned int x) { return __builtin_ctz (x); } 97static inline int rxvt_ctz (unsigned int x) { return __builtin_ctz (x); }
89static inline int popcount (unsigned int x) { return __builtin_popcount (x); } 98static inline int rxvt_popcount (unsigned int x) { return __builtin_popcount (x); }
90#else 99#else
91// count trailing zero bits and count # of one bits 100// count trailing zero bits and count # of one bits
92int ctz (unsigned int x) CONST; 101int rxvt_ctz (unsigned int x) CONST;
93int popcount (unsigned int x) CONST; 102int rxvt_popcount (unsigned int x) CONST;
94#endif 103#endif
95 104
96// in range including end 105// in range including end
97#define IN_RANGE_INC(val,beg,end) \ 106#define IN_RANGE_INC(val,beg,end) \
98 ((unsigned int)(val) - (unsigned int)(beg) <= (unsigned int)(end) - (unsigned int)(beg)) 107 ((unsigned int)(val) - (unsigned int)(beg) <= (unsigned int)(end) - (unsigned int)(beg))
103 112
104// for m >= -n, ensure remainder lies between 0..n-1 113// for m >= -n, ensure remainder lies between 0..n-1
105#define MOD(m,n) (((m) + (n)) % (n)) 114#define MOD(m,n) (((m) + (n)) % (n))
106 115
107// makes dynamically allocated objects zero-initialised 116// makes dynamically allocated objects zero-initialised
108struct zero_initialized { 117struct zero_initialized
118{
109 void *operator new (size_t s); 119 void *operator new (size_t s);
110 void operator delete (void *p, size_t s); 120 void operator delete (void *p, size_t s);
111}; 121};
112 122
113/* simplevec taken (and heavily modified), from: 123/* simplevec taken (and heavily modified), from:
114 * 124 *
115 * MICO --- a free CORBA implementation 125 * MICO --- a free CORBA implementation
116 * Copyright (C) 1997-98 Kay Roemer & Arno Puder 126 * Copyright (C) 1997-98 Kay Roemer & Arno Puder
117 */ 127 */
118template<class T> 128template<class T>
119struct simplevec { 129struct simplevec
130{
120 typedef T* iterator; 131 typedef T* iterator;
121 typedef const T* const_iterator; 132 typedef const T* const_iterator;
122 typedef unsigned long size_type; 133 typedef unsigned long size_type;
123 134
124private: 135private:
379 } 390 }
380}; 391};
381 392
382#if 0 393#if 0
383template<typename T> 394template<typename T>
384struct rxvt_vec : simplevec<void *> { 395struct rxvt_vec : simplevec<void *>
396{
385 typedef T *iterator; 397 typedef T *iterator;
386 398
387 void push_back (T d) { simplevec<void *>::push_back ((void *)d); } 399 void push_back (T d) { simplevec<void *>::push_back ((void *)d); }
388 T pop_back () { return (T*)simplevec<void *>::pop_back (); } 400 T pop_back () { return (T*)simplevec<void *>::pop_back (); }
389 void erase (int i) { erase (begin () + i); } 401 void erase (int i) { erase (begin () + i); }
394 const T &operator [] (int i) const { return * (const T *) (& ((* (const simplevec<void *> *)this)[i])); } 406 const T &operator [] (int i) const { return * (const T *) (& ((* (const simplevec<void *> *)this)[i])); }
395}; 407};
396#endif 408#endif
397 409
398template<typename T> 410template<typename T>
399struct auto_ptr { 411struct auto_ptr
412{
400 T *p; 413 T *p;
401 414
402 auto_ptr () : p (0) { } 415 auto_ptr () : p (0) { }
403 auto_ptr (T *a) : p (a) { } 416 auto_ptr (T *a) : p (a) { }
404 417

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines