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 <kchai@redhat.com>
This commit is contained in:
Kefu Chai 2021-06-29 13:52:04 +08:00
parent 5bb4d37410
commit d6334e5c43

View File

@ -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 {