From 3d7b14af031b164d6e038476b8d1dbd1b6e7c3bc Mon Sep 17 00:00:00 2001 From: yeoncheol-kim Date: Tue, 14 Jan 2025 11:59:12 +0900 Subject: [PATCH] INTERNAL: Refactor a memcached_fetch function --- libmemcached/fetch.cc | 62 +++++++------------------------------------ 1 file changed, 9 insertions(+), 53 deletions(-) diff --git a/libmemcached/fetch.cc b/libmemcached/fetch.cc index aa022ee2..54f3c1bc 100644 --- a/libmemcached/fetch.cc +++ b/libmemcached/fetch.cc @@ -63,73 +63,29 @@ char *memcached_fetch(memcached_st *ptr, char *key, size_t *key_length, if (not error) error= &unused; - - unlikely (ptr->flags.use_udp) - { - if (value_length) - *value_length= 0; - - if (key_length) - *key_length= 0; - - if (flags) - *flags= 0; - - if (key) - *key= 0; - - *error= MEMCACHED_NOT_SUPPORTED; - return NULL; - } - result_buffer= memcached_fetch_result(ptr, result_buffer, error); - if (result_buffer == NULL or memcached_failed(*error)) + if (result_buffer == NULL || result_buffer->key_length > MEMCACHED_MAX_KEY) { - WATCHPOINT_ASSERT(result_buffer == NULL); - if (value_length) - *value_length= 0; - - if (key_length) - *key_length= 0; - - if (flags) - *flags= 0; + *error= (result_buffer != NULL) ? MEMCACHED_KEY_TOO_BIG : *error; - if (key) - *key= 0; + if (key) *key= 0; + if (key_length) *key_length= 0; + if (value_length) *value_length= 0; + if (flags) *flags= 0; return NULL; } - if (value_length) - { - *value_length= memcached_string_length(&result_buffer->value); - } - if (key) { - if (result_buffer->key_length > MEMCACHED_MAX_KEY) - { - *error= MEMCACHED_KEY_TOO_BIG; - if (value_length) - *value_length= 0; - - if (key_length) - *key_length= 0; - - if (flags) - *flags= 0; - - if (key) - *key= 0; - - return NULL; - } strncpy(key, result_buffer->item_key, result_buffer->key_length); // For the binary protocol we will cut off the key :( if (key_length) *key_length= result_buffer->key_length; } + if (value_length) + *value_length= memcached_string_length(&result_buffer->value); + if (flags) *flags= result_buffer->item_flags;