From: Brian Aker Date: Wed, 23 Jan 2008 03:19:52 +0000 (-0800) Subject: Slight optimization in write() call X-Git-Tag: 0.15~6 X-Git-Url: https://git.m6w6.name/?a=commitdiff_plain;h=8c3bca01cf65534b71679bdadad6c4d1637c844f;p=m6w6%2Flibmemcached Slight optimization in write() call --- diff --git a/lib/memcached_io.c b/lib/memcached_io.c index be186c4b..52d91297 100644 --- a/lib/memcached_io.c +++ b/lib/memcached_io.c @@ -166,22 +166,33 @@ ssize_t memcached_io_write(memcached_server_st *ptr, { unsigned long long x; - for (x= 0; x < length; x++) + if (length < (MEMCACHED_MAX_BUFFER - ptr->write_buffer_offset )) { - ptr->write_buffer[ptr->write_buffer_offset]= buffer[x]; - ptr->write_buffer_offset++; - WATCHPOINT_ASSERT(ptr->write_buffer_offset <= MEMCACHED_MAX_BUFFER); + char *write_ptr; - if (ptr->write_buffer_offset == MEMCACHED_MAX_BUFFER) + write_ptr= ptr->write_buffer + ptr->write_buffer_offset; + memcpy(write_ptr, buffer, length); + ptr->write_buffer_offset+= length; + } + else + { + for (x= 0; x < length; x++) { - memcached_return rc; - ssize_t sent_length; + ptr->write_buffer[ptr->write_buffer_offset]= buffer[x]; + ptr->write_buffer_offset++; + WATCHPOINT_ASSERT(ptr->write_buffer_offset <= MEMCACHED_MAX_BUFFER); - sent_length= io_flush(ptr, &rc); - if (sent_length == -1) - return -1; + if (ptr->write_buffer_offset == MEMCACHED_MAX_BUFFER) + { + memcached_return rc; + ssize_t sent_length; - WATCHPOINT_ASSERT(sent_length == MEMCACHED_MAX_BUFFER); + sent_length= io_flush(ptr, &rc); + if (sent_length == -1) + return -1; + + WATCHPOINT_ASSERT(sent_length == MEMCACHED_MAX_BUFFER); + } } }