--- deliantra/server/include/util.h 2008/12/31 17:35:37 1.84 +++ deliantra/server/include/util.h 2009/01/12 03:40:21 1.87 @@ -30,10 +30,12 @@ # define is_constant(c) __builtin_constant_p (c) # define expect(expr,value) __builtin_expect ((expr),(value)) # define prefetch(addr,rw,locality) __builtin_prefetch (addr, rw, locality) +# define noinline __attribute__((__noinline__)) #else # define is_constant(c) 0 # define expect(expr,value) (expr) # define prefetch(addr,rw,locality) +# define noinline #endif #if __GNUC__ < 4 || (__GNUC__ == 4 || __GNUC_MINOR__ < 4) @@ -409,6 +411,7 @@ // http://www.jstatsoft.org/v08/i14/paper // this one is about 40% faster than the tausworthe one above (i.e. not much), // despite the inlining, and has the issue of only creating 2**32-1 numbers. +// see also http://www.iro.umontreal.ca/~lecuyer/myftp/papers/xorshift.pdf struct xorshift_random_generator { uint32_t x, y; @@ -675,13 +678,14 @@ }; // basically does what strncpy should do, but appends "..." to strings exceeding length -void assign (char *dst, const char *src, int maxlen); +// returns the number of bytes actually used (including \0) +int assign (char *dst, const char *src, int maxsize); // type-safe version of assign template -inline void assign (char (&dst)[N], const char *src) +inline int assign (char (&dst)[N], const char *src) { - assign ((char *)&dst, src, N); + return assign ((char *)&dst, src, N); } typedef double tstamp;