From 403eef86999f483733245930120cf273afa8ec9a Mon Sep 17 00:00:00 2001 From: Radoslaw Zarzynski Date: Sat, 1 Dec 2018 19:27:46 +0100 Subject: [PATCH] common: drop the doubly-linked-list compatibility of bl::buffers_t. Signed-off-by: Radoslaw Zarzynski --- src/common/buffer.cc | 21 +++++++++++-------- src/include/buffer.h | 49 ++++++++++++++------------------------------ 2 files changed, 28 insertions(+), 42 deletions(-) diff --git a/src/common/buffer.cc b/src/common/buffer.cc index 9c5d5ecbbe8..b1c533ed310 100644 --- a/src/common/buffer.cc +++ b/src/common/buffer.cc @@ -1368,6 +1368,7 @@ using namespace ceph; align_size = round_up_to(round_up_to(_len, max_buffers) / max_buffers, align_size); } auto p = std::begin(_buffers); + auto p_prev = _buffers.before_begin(); while (p != std::end(_buffers)) { // keep anything that's already align and sized aligned if (p->is_aligned(align_memory) && p->is_n_align_sized(align_size)) { @@ -1376,7 +1377,7 @@ using namespace ceph; << " length " << p->length() << " " << (p->length() & (align - 1)) << " ok" << std::endl; */ - ++p; + p_prev = p++; continue; } @@ -1392,10 +1393,10 @@ using namespace ceph; */ offset += p->length(); // no need to reallocate, relinking is enough thankfully to bi::list. - auto after = _buffers.erase(p); + auto p_after = _buffers.erase_after(p_prev); unaligned._buffers.push_back(*p); unaligned._len += p->length(); - p = after; + p = p_after; } while (p != std::end(_buffers) && (!p->is_aligned(align_memory) || !p->is_n_align_sized(align_size) || @@ -1406,7 +1407,8 @@ using namespace ceph; buffer::create_aligned(unaligned._len, align_memory))); _memcopy_count += unaligned._len; } - _buffers.insert(p, *ptr_node::create(unaligned._buffers.front()).release()); + _buffers.insert_after(p_prev, *ptr_node::create(unaligned._buffers.front()).release()); + ++p_prev; } last_p = begin(); @@ -1440,7 +1442,7 @@ using namespace ceph; _len += bl._len; if (!(flags & CLAIM_ALLOW_NONSHAREABLE)) bl.make_shareable(); - _buffers.splice(std::end(_buffers), bl._buffers); + _buffers.splice_back(bl._buffers); bl._len = 0; bl.last_p = bl.begin(); } @@ -1723,13 +1725,14 @@ using namespace ceph; // skip off auto curbuf = std::begin(_buffers); + auto curbuf_prev = _buffers.before_begin(); while (off > 0) { ceph_assert(curbuf != std::end(_buffers)); if (off >= (*curbuf).length()) { // skip this buffer //cout << "off = " << off << " skipping over " << *curbuf << std::endl; off -= (*curbuf).length(); - ++curbuf; + curbuf_prev = curbuf++; } else { // somewhere in this buffer! //cout << "off = " << off << " somewhere in " << *curbuf << std::endl; @@ -1741,8 +1744,10 @@ using namespace ceph; // add a reference to the front bit // insert it before curbuf (which we'll hose) //cout << "keeping front " << off << " of " << *curbuf << std::endl; - _buffers.insert( curbuf, *ptr_node::create( *curbuf, 0, off ).release()); + _buffers.insert_after(curbuf_prev, + *ptr_node::create(*curbuf, 0, off).release()); _len += off; + ++curbuf_prev; } while (len > 0) { @@ -1764,7 +1769,7 @@ using namespace ceph; if (claim_by) claim_by->append( *curbuf, off, howmuch ); _len -= (*curbuf).length(); - curbuf = _buffers.erase_and_dispose(curbuf); + curbuf = _buffers.erase_after_and_dispose(curbuf_prev); len -= howmuch; off = 0; } diff --git a/src/include/buffer.h b/src/include/buffer.h index 086414ffbcb..56c5e8154e2 100644 --- a/src/include/buffer.h +++ b/src/include/buffer.h @@ -574,20 +574,15 @@ namespace buffer CEPH_BUFFER_API { _size++; } - void splice_after(const_iterator it, buffers_t& other) { + void splice_back(buffers_t& other) { if (other._size == 0) { return; } - other._tail->next = it->next; - it->next = other._root.next; - - // the insert_after(end(), ...) case - _root.next = it == end() ? other._root.next : _root.next; - - // push_back equivalent - _tail = const_iterator(_tail) == it ? other._tail : _tail; - + other._tail->next = &_root; + // will update root.next if empty() == true + _tail->next = other._root.next; + _tail = other._tail; _size += other._size; other._root.next = &other._root; @@ -595,39 +590,24 @@ namespace buffer CEPH_BUFFER_API { other._size = 0; } - const const_iterator previous(const_iterator it) const { - for (auto prev = begin(); prev != end(); prev = prev->next) { - if (const_iterator(prev->next) == it) { - return prev; - } - } - return end(); - } - - auto erase(const_iterator it) { - return erase_after(previous(it)); - } - - auto insert(const_iterator it, reference item) { - return insert_after(previous(it), item); - } - - auto splice(const_iterator it, buffers_t& other) { - return splice_after(previous(it), other); - } - std::size_t size() const { return _size; } bool empty() const { return _tail == &_root; } const_iterator begin() const { return _root.next; } + const_iterator before_begin() const { + return &_root; + } const_iterator end() const { return &_root; } iterator begin() { return _root.next; } + iterator before_begin() { + return &_root; + } iterator end() { return &_root; } @@ -662,9 +642,10 @@ namespace buffer CEPH_BUFFER_API { _tail = &_root; _size = 0; } - auto erase_and_dispose(iterator it) { - auto ret = erase(it); - ptr_node::disposer()(&*it); + iterator erase_after_and_dispose(iterator it) { + auto* to_dispose = &*std::next(it); + auto ret = erase_after(it); + ptr_node::disposer()(to_dispose); return ret; } -- 2.39.5