From c946349871b86b99f1a37b241b12ea64dab36459 Mon Sep 17 00:00:00 2001 From: Changcheng Liu Date: Wed, 26 Jun 2019 14:46:03 +0800 Subject: [PATCH] msg/async/rdma: simplify chunk::write implementation Keep same logic to improve readability Signed-off-by: Changcheng Liu --- src/msg/async/rdma/Infiniband.cc | 14 ++++---------- 1 file changed, 4 insertions(+), 10 deletions(-) diff --git a/src/msg/async/rdma/Infiniband.cc b/src/msg/async/rdma/Infiniband.cc index 0d2fdebb4d370..dc82f1915f9b0 100644 --- a/src/msg/async/rdma/Infiniband.cc +++ b/src/msg/async/rdma/Infiniband.cc @@ -549,16 +549,10 @@ uint32_t Infiniband::MemoryManager::Chunk::read(char* buf, uint32_t len) uint32_t Infiniband::MemoryManager::Chunk::write(char* buf, uint32_t len) { - uint32_t left = bytes - offset; - if (left >= len) { - memcpy(buffer+offset, buf, len); - offset += len; - return len; - } else { - memcpy(buffer+offset, buf, left); - offset = bytes; - return left; - } + uint32_t write_len = (bytes - offset) <= len ? (bytes - offset) : len; + memcpy(buffer + offset, buf, write_len); + offset += write_len; + return write_len; } bool Infiniband::MemoryManager::Chunk::full() -- 2.39.5