From 8c3bca01cf65534b71679bdadad6c4d1637c844f Mon Sep 17 00:00:00 2001 From: Brian Aker Date: Tue, 22 Jan 2008 19:19:52 -0800 Subject: [PATCH] Slight optimization in write() call --- lib/memcached_io.c | 33 ++++++++++++++++++++++----------- 1 file changed, 22 insertions(+), 11 deletions(-) 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); + } } } -- 2.30.2