From: Kefu Chai Date: Tue, 29 Jun 2021 05:52:04 +0000 (+0800) Subject: common/buffers: check _num directly in list::c_str() X-Git-Tag: v17.1.0~1520^2 X-Git-Url: http://git-server-git.apps.pok.os.sepia.ceph.com/?a=commitdiff_plain;h=d6334e5c433a94da37406943d2675befa2425720;p=ceph.git common/buffers: check _num directly in list::c_str() no need to create temporary iterator for comparing it with cend(). Signed-off-by: Kefu Chai --- diff --git a/src/common/buffer.cc b/src/common/buffer.cc index 548abc458fdc..44b7482213b0 100644 --- a/src/common/buffer.cc +++ b/src/common/buffer.cc @@ -1519,16 +1519,18 @@ static ceph::spinlock debug_lock; */ char *buffer::list::c_str() { - if (_buffers.empty()) - return 0; // no buffers - - auto iter = std::cbegin(_buffers); - ++iter; - - if (iter != std::cend(_buffers)) { + switch (get_num_buffers()) { + case 0: + // no buffers + return nullptr; + case 1: + // good, we're already contiguous. + break; + default: rebuild(); + break; } - return _buffers.front().c_str(); // good, we're already contiguous. + return _buffers.front().c_str(); } string buffer::list::to_str() const {