From: Marko Kreen Date: Wed, 25 Jun 2008 15:06:22 +0000 (+0000) Subject: drop too clever optimizations from system.h X-Git-Tag: pgbouncer_1_2_rc2~20 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=40e5eefd8521751bd483efd8a6d4ed1f03d632b6;p=pgbouncer drop too clever optimizations from system.h --- diff --git a/include/system.h b/include/system.h index a9151a6..eb9ef98 100644 --- a/include/system.h +++ b/include/system.h @@ -161,51 +161,4 @@ const char *basename(const char *path); void change_user(const char *user); -/* - * memcpy() optimization - improves hash.c. - * - * GCC can optimize fixed-length memcpys but not variable-length ones. - * For short variable-length memcpys its faster to do dumb inlined copy - * than call out to libc. - */ - -#if defined(__GNUC__) && (__GNUC__ >= 3) - -static inline void *_inline_memcpy(void *dst_, const void *src_, size_t len) -{ - const uint8_t *src = src_; - uint8_t *dst = dst_; - while (len--) - *dst++ = *src++; - return dst_; -} - -static inline void *_own_memcpy(void *dst, const void *src, size_t len) -{ - if (!__builtin_constant_p(len) - && __builtin_constant_p(len < 16) - && len < 16) - return _inline_memcpy(dst, src, len); - else - return memcpy(dst, src, len); -} - -#undef memcpy -#define memcpy(d, s, n) _own_memcpy(d, s, n) - -#endif - -/* - * strcmp() optimization - compare first char inline. - */ - -static inline int _inline_strcmp(const char *a, const char *b) -{ - if ((*a - *b) != 0) - return (*a - *b); - return strcmp(a, b); -} - -#undef strcmp -#define strcmp(a, b) _inline_strcmp(a, b) diff --git a/src/hash.c b/src/hash.c index bb60cec..ff05596 100644 --- a/src/hash.c +++ b/src/hash.c @@ -41,6 +41,18 @@ c ^= b; c -= rot(b,24); \ } while (0) +/* + * GCC does not know how to optimize short variable-length copies. + * Its faster to do dumb inlined copy than call out to libc. + */ +static inline void simple_memcpy(void *dst_, const void *src_, size_t len) +{ + const uint8_t *src = src_; + uint8_t *dst = dst_; + while (len--) + *dst++ = *src++; +} + /* short version - let compiler worry about memory access */ uint32_t lookup3_hash(const void *data, size_t len) { @@ -63,7 +75,7 @@ uint32_t lookup3_hash(const void *data, size_t len) } buf[0] = buf[1] = buf[2] = 0; - memcpy(buf, p, len); + simple_memcpy(buf, p, len); a += buf[0]; b += buf[1]; c += buf[2];