From: Date: Sun, 24 Feb 2008 18:51:14 +0000 (+0000) Subject: Added unlikely for branch predicition :) X-Git-Tag: _20~1^2~55^2~3^2~6 X-Git-Url: https://git.m6w6.name/?a=commitdiff_plain;h=2bb6c49b4e52a66177dab44f5dd6a50f1bb63fe4;p=m6w6%2Flibmemcached Added unlikely for branch predicition :) --- diff --git a/lib/common.h b/lib/common.h index b09d5433..095b7f5e 100644 --- a/lib/common.h +++ b/lib/common.h @@ -40,6 +40,19 @@ #include +#if !defined(__GNUC__) || (__GNUC__ == 2 && __GNUC_MINOR__ < 96) +#define __builtin_expect(x, expected_value) (x) + +#define likely(x) __builtin_expect((x),1) +#define unlikely(x) __builtin_expect((x),0) + +#else + +#define likely(x) if((x)) +#define unlikely(x) if((x)) + +#endif + #ifdef HAVE_DTRACE #define _DTRACE_VERSION 1 #else diff --git a/lib/memcached_auto.c b/lib/memcached_auto.c index 0d0fc917..a607ed66 100644 --- a/lib/memcached_auto.c +++ b/lib/memcached_auto.c @@ -11,10 +11,10 @@ static memcached_return memcached_auto(memcached_st *ptr, char buffer[MEMCACHED_DEFAULT_COMMAND_SIZE]; unsigned int server_key; - if (key_length == 0) + unlikely (key_length == 0) return MEMCACHED_NO_KEY_PROVIDED; - if (ptr->hosts == NULL || ptr->number_of_hosts == 0) + unlikely (ptr->hosts == NULL || ptr->number_of_hosts == 0) return MEMCACHED_NO_SERVERS; if ((ptr->flags & MEM_VERIFY_KEY) && (memcachd_key_test(&key, &key_length, 1) == MEMCACHED_BAD_KEY_PROVIDED)) @@ -26,7 +26,7 @@ static memcached_return memcached_auto(memcached_st *ptr, "%s %.*s %u\r\n", verb, (int)key_length, key, offset); - if (send_length >= MEMCACHED_DEFAULT_COMMAND_SIZE) + unlikely (send_length >= MEMCACHED_DEFAULT_COMMAND_SIZE) return MEMCACHED_WRITE_FAILURE; rc= memcached_do(&ptr->hosts[server_key], buffer, send_length, 1); diff --git a/lib/memcached_connect.c b/lib/memcached_connect.c index 50c6fa62..9d935e02 100644 --- a/lib/memcached_connect.c +++ b/lib/memcached_connect.c @@ -101,7 +101,7 @@ static memcached_return set_socket_options(memcached_server_st *ptr) int flags; flags= fcntl(ptr->fd, F_GETFL, 0); - if (flags != -1) + unlikely (flags != -1) { (void)fcntl(ptr->fd, F_SETFL, flags | O_NONBLOCK); } diff --git a/lib/memcached_delete.c b/lib/memcached_delete.c index b3ae560d..60e3bed4 100644 --- a/lib/memcached_delete.c +++ b/lib/memcached_delete.c @@ -20,10 +20,10 @@ memcached_return memcached_delete_by_key(memcached_st *ptr, LIBMEMCACHED_MEMCACHED_DELETE_START(); - if (key_length == 0) + unlikely (key_length == 0) return MEMCACHED_NO_KEY_PROVIDED; - if (ptr->hosts == NULL || ptr->number_of_hosts == 0) + unlikely (ptr->hosts == NULL || ptr->number_of_hosts == 0) return MEMCACHED_NO_SERVERS; server_key= memcached_generate_hash(ptr, master_key, master_key_length); diff --git a/lib/memcached_flush.c b/lib/memcached_flush.c index fa3dd8d8..1511adbe 100644 --- a/lib/memcached_flush.c +++ b/lib/memcached_flush.c @@ -8,7 +8,7 @@ memcached_return memcached_flush(memcached_st *ptr, time_t expiration) char buffer[MEMCACHED_DEFAULT_COMMAND_SIZE]; LIBMEMCACHED_MEMCACHED_FLUSH_START(); - if (ptr->number_of_hosts == 0) + unlikely (ptr->number_of_hosts == 0) return MEMCACHED_NO_SERVERS; for (x= 0; x < ptr->number_of_hosts; x++) diff --git a/lib/memcached_storage.c b/lib/memcached_storage.c index 6d115913..fb3e6b2b 100644 --- a/lib/memcached_storage.c +++ b/lib/memcached_storage.c @@ -60,10 +60,10 @@ static inline memcached_return memcached_send(memcached_st *ptr, WATCHPOINT_ASSERT(!(value == NULL && value_length > 0)); WATCHPOINT_ASSERT(!(value && value_length == 0)); - if (key_length == 0) + unlikely (key_length == 0) return MEMCACHED_NO_KEY_PROVIDED; - if (ptr->number_of_hosts == 0) + unlikely (ptr->number_of_hosts == 0) return MEMCACHED_NO_SERVERS; if ((ptr->flags & MEM_VERIFY_KEY) && (memcachd_key_test(&key, &key_length, 1) == MEMCACHED_BAD_KEY_PROVIDED)) diff --git a/lib/memcached_verbosity.c b/lib/memcached_verbosity.c index f599787b..7cfb073f 100644 --- a/lib/memcached_verbosity.c +++ b/lib/memcached_verbosity.c @@ -9,7 +9,7 @@ memcached_return memcached_verbosity(memcached_st *ptr, unsigned int verbosity) send_length= snprintf(buffer, MEMCACHED_DEFAULT_COMMAND_SIZE, "verbosity %u\r\n", verbosity); - if (send_length >= MEMCACHED_DEFAULT_COMMAND_SIZE) + unlikely (send_length >= MEMCACHED_DEFAULT_COMMAND_SIZE) return MEMCACHED_WRITE_FAILURE; rc= MEMCACHED_SUCCESS;