From c3f2b87e3a9f3263d1c88d513202458e7f6cdecc Mon Sep 17 00:00:00 2001 From: Radoslaw Zarzynski Date: Mon, 17 Dec 2018 21:06:38 +0100 Subject: [PATCH] common: avoid bl::get_current_ptr()-driven ref counting in denc.h. Signed-off-by: Radoslaw Zarzynski --- src/common/buffer.cc | 9 +++++++++ src/include/buffer.h | 1 + src/include/denc.h | 3 +-- 3 files changed, 11 insertions(+), 2 deletions(-) diff --git a/src/common/buffer.cc b/src/common/buffer.cc index b1c533ed310..8925d007610 100644 --- a/src/common/buffer.cc +++ b/src/common/buffer.cc @@ -898,6 +898,15 @@ using namespace ceph; return ptr(*p, p_off, p->length() - p_off); } + template + bool buffer::list::iterator_impl::is_pointing_same_raw( + const ptr& other) const + { + if (p == ls->end()) + throw end_of_buffer(); + return p->get_raw() == other.get_raw(); + } + // copy data out. // note that these all _append_ to dest! template diff --git a/src/include/buffer.h b/src/include/buffer.h index 56c5e8154e2..6038529b49e 100644 --- a/src/include/buffer.h +++ b/src/include/buffer.h @@ -728,6 +728,7 @@ namespace buffer CEPH_BUFFER_API { char operator*() const; iterator_impl& operator++(); ptr get_current_ptr() const; + bool is_pointing_same_raw(const ptr& other) const; bl_t& get_bl() const { return *bl; } diff --git a/src/include/denc.h b/src/include/denc.h index 1e0b38723cb..cc2b906bf02 100644 --- a/src/include/denc.h +++ b/src/include/denc.h @@ -1523,8 +1523,7 @@ inline std::enable_if_t decode( const auto& bl = p.get_bl(); const auto remaining = bl.length() - p.get_off(); // it is expensive to rebuild a contigous buffer and drop it, so avoid this. - if (p.get_current_ptr().get_raw() != bl.back().get_raw() && - remaining > CEPH_PAGE_SIZE) { + if (!p.is_pointing_same_raw(bl.back()) && remaining > CEPH_PAGE_SIZE) { traits::decode(o, p); } else { // ensure we get a contigous buffer... until the end of the -- 2.39.5