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)) {
<< " length " << p->length()
<< " " << (p->length() & (align - 1)) << " ok" << std::endl;
*/
- ++p;
+ p_prev = p++;
continue;
}
*/
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) ||
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();
_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();
}
// 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;
// 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) {
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;
}
_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;
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;
}
_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;
}