if (p == ls->end())
seek(off);
unsigned left = len;
- for (std::list<ptr>::const_iterator i = otherl._buffers.begin();
+ for (buffers_t::const_iterator i = otherl._buffers.begin();
i != otherl._buffers.end();
++i) {
unsigned l = (*i).length();
// buffer-wise comparison
if (true) {
- std::list<ptr>::const_iterator a = _buffers.begin();
- std::list<ptr>::const_iterator b = other._buffers.begin();
+ buffers_t::const_iterator a = _buffers.begin();
+ buffers_t::const_iterator b = other._buffers.begin();
unsigned aoff = 0, boff = 0;
while (a != _buffers.end()) {
unsigned len = a->length() - aoff;
bool buffer::list::is_aligned(unsigned align) const
{
- for (std::list<ptr>::const_iterator it = _buffers.begin();
+ for (buffers_t::const_iterator it = _buffers.begin();
it != _buffers.end();
++it)
if (!it->is_aligned(align))
bool buffer::list::is_n_align_sized(unsigned align) const
{
- for (std::list<ptr>::const_iterator it = _buffers.begin();
+ for (buffers_t::const_iterator it = _buffers.begin();
it != _buffers.end();
++it)
if (!it->is_n_align_sized(align))
bool buffer::list::is_aligned_size_and_memory(unsigned align_size,
unsigned align_memory) const
{
- for (std::list<ptr>::const_iterator it = _buffers.begin();
+ for (buffers_t::const_iterator it = _buffers.begin();
it != _buffers.end();
++it) {
if (!it->is_aligned(align_memory) || !it->is_n_align_sized(align_size))
}
bool buffer::list::is_zero() const {
- for (std::list<ptr>::const_iterator it = _buffers.begin();
+ for (buffers_t::const_iterator it = _buffers.begin();
it != _buffers.end();
++it) {
if (!it->is_zero()) {
void buffer::list::zero()
{
- for (std::list<ptr>::iterator it = _buffers.begin();
+ for (buffers_t::iterator it = _buffers.begin();
it != _buffers.end();
++it)
it->zero();
{
ceph_assert(o+l <= _len);
unsigned p = 0;
- for (std::list<ptr>::iterator it = _buffers.begin();
+ for (buffers_t::iterator it = _buffers.begin();
it != _buffers.end();
++it) {
if (p + it->length() > o) {
void buffer::list::rebuild(ptr& nb)
{
unsigned pos = 0;
- for (std::list<ptr>::iterator it = _buffers.begin();
+ for (buffers_t::iterator it = _buffers.begin();
it != _buffers.end();
++it) {
nb.copy_in(pos, it->length(), it->c_str(), false);
&& _len > (max_buffers * align_size)) {
align_size = round_up_to(round_up_to(_len, max_buffers) / max_buffers, align_size);
}
- std::list<ptr>::iterator p = _buffers.begin();
+ buffers_t::iterator p = _buffers.begin();
while (p != _buffers.end()) {
// keep anything that's already align and sized aligned
if (p->is_aligned(align_memory) && p->is_n_align_sized(align_size)) {
*/
offset += p->length();
unaligned.push_back(*p);
- _buffers.erase(p++);
+ p = _buffers.erase(p);
} while (p != _buffers.end() &&
(!p->is_aligned(align_memory) ||
!p->is_n_align_sized(align_size) ||
_len += bl._len;
if (!(flags & CLAIM_ALLOW_NONSHAREABLE))
bl.make_shareable();
- _buffers.splice(_buffers.end(), bl._buffers );
+ std::move(bl._buffers.begin(), bl._buffers.end(),
+ std::back_inserter(_buffers));
+ bl._buffers.clear();
bl._len = 0;
bl.last_p = bl.begin();
}
void buffer::list::claim_append_piecewise(list& bl)
{
// steal the other guy's buffers
- for (std::list<buffer::ptr>::const_iterator i = bl.buffers().begin();
+ for (buffers_t::const_iterator i = bl.buffers().begin();
i != bl.buffers().end(); ++i) {
append(*i, 0, i->length());
}
void buffer::list::append(const list& bl)
{
_len += bl._len;
- for (std::list<ptr>::const_iterator p = bl._buffers.begin();
+ for (buffers_t::const_iterator p = bl._buffers.begin();
p != bl._buffers.end();
++p)
_buffers.push_back(*p);
if (n >= _len)
throw end_of_buffer();
- for (std::list<ptr>::const_iterator p = _buffers.begin();
+ for (buffers_t::const_iterator p = _buffers.begin();
p != _buffers.end();
++p) {
if (n >= p->length()) {
if (_buffers.empty())
return 0; // no buffers
- std::list<ptr>::const_iterator iter = _buffers.begin();
+ buffers_t::const_iterator iter = _buffers.begin();
++iter;
if (iter != _buffers.end())
string buffer::list::to_str() const {
string s;
s.reserve(length());
- for (std::list<ptr>::const_iterator p = _buffers.begin();
+ for (buffers_t::const_iterator p = _buffers.begin();
p != _buffers.end();
++p) {
if (p->length()) {
clear();
// skip off
- std::list<ptr>::const_iterator curbuf = other._buffers.begin();
+ buffers_t::const_iterator curbuf = other._buffers.begin();
while (off > 0 &&
off >= curbuf->length()) {
// skip this buffer
//cout << "splice off " << off << " len " << len << " ... mylen = " << length() << std::endl;
// skip off
- std::list<ptr>::iterator curbuf = _buffers.begin();
+ buffers_t::iterator curbuf = _buffers.begin();
while (off > 0) {
ceph_assert(curbuf != _buffers.end());
if (off >= (*curbuf).length()) {
if (claim_by)
claim_by->append( *curbuf, off, howmuch );
_len -= (*curbuf).length();
- _buffers.erase( curbuf++ );
+ curbuf = _buffers.erase( curbuf );
len -= howmuch;
off = 0;
}
{
list s;
s.substr_of(*this, off, len);
- for (std::list<ptr>::const_iterator it = s._buffers.begin();
+ for (buffers_t::const_iterator it = s._buffers.begin();
it != s._buffers.end();
++it)
if (it->length())
int iovlen = 0;
ssize_t bytes = 0;
- std::list<ptr>::const_iterator p = _buffers.begin();
+ buffers_t::const_iterator p = _buffers.begin();
while (p != _buffers.end()) {
if (p->length() > 0) {
iov[iovlen].iov_base = (void *)p->c_str();
{
iovec iov[IOV_MAX];
- std::list<ptr>::const_iterator p = _buffers.begin();
+ buffers_t::const_iterator p = _buffers.begin();
uint64_t left_pbrs = _buffers.size();
while (left_pbrs) {
ssize_t bytes = 0;
int cache_hits = 0;
int cache_adjusts = 0;
- for (std::list<ptr>::const_iterator it = _buffers.begin();
+ for (buffers_t::const_iterator it = _buffers.begin();
it != _buffers.end();
++it) {
if (it->length()) {
void buffer::list::invalidate_crc()
{
- for (std::list<ptr>::const_iterator p = _buffers.begin(); p != _buffers.end(); ++p) {
+ for (buffers_t::const_iterator p = _buffers.begin(); p != _buffers.end(); ++p) {
raw *r = p->get_raw();
if (r) {
r->invalidate_crc();
*/
void buffer::list::write_stream(std::ostream &out) const
{
- for (std::list<ptr>::const_iterator p = _buffers.begin(); p != _buffers.end(); ++p) {
+ for (buffers_t::const_iterator p = _buffers.begin(); p != _buffers.end(); ++p) {
if (p->length() > 0) {
out.write(p->c_str(), p->length());
}
std::ostream& buffer::operator<<(std::ostream& out, const buffer::list& bl) {
out << "buffer::list(len=" << bl.length() << "," << std::endl;
- std::list<buffer::ptr>::const_iterator it = bl.buffers().begin();
+ buffer::list::buffers_t::const_iterator it = bl.buffers().begin();
while (it != bl.buffers().end()) {
out << "\t" << *it;
if (++it == bl.buffers().end()) break;
*/
class CEPH_BUFFER_API list {
+ public:
+ typedef std::list<ptr> buffers_t;
+ class iterator;
+
+ private:
// my private bits
- std::list<ptr> _buffers;
+ buffers_t _buffers;
unsigned _len;
unsigned _memcopy_count; //the total of memcopy using rebuild().
ptr append_buffer; // where i put small appends.
- public:
- class iterator;
-
- private:
template <bool is_const>
class CEPH_BUFFER_API iterator_impl {
protected:
const list,
list>::type bl_t;
typedef typename std::conditional<is_const,
- const std::list<ptr>,
- std::list<ptr> >::type list_t;
+ const buffers_t,
+ buffers_t >::type list_t;
typedef typename std::conditional<is_const,
- typename std::list<ptr>::const_iterator,
- typename std::list<ptr>::iterator>::type list_iter_t;
+ typename buffers_t::const_iterator,
+ typename buffers_t::iterator>::type list_iter_t;
using iterator_category = std::forward_iterator_tag;
using value_type = typename std::conditional<is_const, const char, char>::type;
using difference_type = std::ptrdiff_t;
}
unsigned get_memcopy_count() const {return _memcopy_count; }
- const std::list<ptr>& buffers() const { return _buffers; }
+ const buffers_t& buffers() const { return _buffers; }
void swap(list& other) noexcept;
unsigned length() const {
#if 0
// clone non-shareable buffers (make shareable)
void make_shareable() {
- std::list<buffer::ptr>::iterator pb;
+ decltype(_buffers)::iterator pb;
for (pb = _buffers.begin(); pb != _buffers.end(); ++pb) {
(void) pb->make_shareable();
}
{
if (this != &bl) {
clear();
- std::list<buffer::ptr>::const_iterator pb;
+ decltype(_buffers)::const_iterator pb;
for (pb = bl._buffers.begin(); pb != bl._buffers.end(); ++pb) {
push_back(*pb);
}