From: Kefu Chai Date: Fri, 31 Jan 2020 05:07:39 +0000 (+0800) Subject: src/: s/advance/operator+=/ X-Git-Tag: v15.1.1~550^2 X-Git-Url: http://git-server-git.apps.pok.os.sepia.ceph.com/?a=commitdiff_plain;h=55953ba0dac86be9d497b433b1cec20fa99d3aca;p=ceph.git src/: s/advance/operator+=/ for better readablity Signed-off-by: Kefu Chai --- diff --git a/src/common/buffer.cc b/src/common/buffer.cc index 0030ef9d613..8b9061268e4 100644 --- a/src/common/buffer.cc +++ b/src/common/buffer.cc @@ -675,7 +675,7 @@ static ceph::spinlock debug_lock; buffer::list::iterator_impl::iterator_impl(bl_t *l, unsigned o) : bl(l), ls(&bl->_buffers), p(ls->begin()), off(0), p_off(0) { - advance(o); + *this += o; } template @@ -683,7 +683,8 @@ static ceph::spinlock debug_lock; : iterator_impl(i.bl, i.off, i.p, i.p_off) {} template - void buffer::list::iterator_impl::advance(unsigned o) + auto buffer::list::iterator_impl::operator +=(unsigned o) + -> iterator_impl& { //cout << this << " advance " << o << " from " << off // << " (p_off " << p_off << " in " << p->length() << ")" @@ -704,6 +705,7 @@ static ceph::spinlock debug_lock; throw end_of_buffer(); } off += o; + return *this; } template @@ -711,7 +713,7 @@ static ceph::spinlock debug_lock; { p = ls->begin(); off = p_off = 0; - advance(o); + *this += o; } template @@ -728,7 +730,7 @@ static ceph::spinlock debug_lock; { if (p == ls->end()) throw end_of_buffer(); - advance(1u); + *this += 1; return *this; } @@ -765,7 +767,7 @@ static ceph::spinlock debug_lock; dest += howmuch; len -= howmuch; - advance(howmuch); + *this += howmuch; } } @@ -801,7 +803,7 @@ static ceph::spinlock debug_lock; copy(len, dest.c_str()); } else { dest = ptr(*p, p_off, len); - advance(len); + *this += len; } } @@ -820,7 +822,7 @@ static ceph::spinlock debug_lock; dest.append(*p, p_off, howmuch); len -= howmuch; - advance(howmuch); + *this += howmuch; } } @@ -840,7 +842,7 @@ static ceph::spinlock debug_lock; dest.append(c_str + p_off, howmuch); len -= howmuch; - advance(howmuch); + *this += howmuch; } } @@ -857,7 +859,7 @@ static ceph::spinlock debug_lock; const char *c_str = p->c_str(); dest.append(c_str + p_off, howmuch); - advance(howmuch); + *this += howmuch; } } @@ -927,7 +929,7 @@ static ceph::spinlock debug_lock; src += howmuch; len -= howmuch; - advance(howmuch); + *this += howmuch; } } diff --git a/src/compressor/snappy/SnappyCompressor.h b/src/compressor/snappy/SnappyCompressor.h index 0291a923112..0cfb819cd96 100644 --- a/src/compressor/snappy/SnappyCompressor.h +++ b/src/compressor/snappy/SnappyCompressor.h @@ -46,7 +46,7 @@ class CEPH_BUFFER_API BufferlistSource : public snappy::Source { } void Skip(size_t n) override { ceph_assert(n <= remaining); - pb.advance(n); + pb += n; remaining -= n; } diff --git a/src/include/buffer.h b/src/include/buffer.h index 6bcbecc3a82..2745675cdb3 100644 --- a/src/include/buffer.h +++ b/src/include/buffer.h @@ -214,7 +214,7 @@ inline namespace v14_2_0 { using pointer = typename std::conditional::type; pointer get_pos_add(size_t n) { auto r = pos; - advance(n); + *this += n; return r; } ptr get_ptr(size_t len) { @@ -222,18 +222,15 @@ inline namespace v14_2_0 { return buffer::copy(get_pos_add(len), len); } else { size_t off = pos - bp->c_str(); - advance(len); + *this += len; return ptr(*bp, off, len); } } - void advance(size_t len) { + iterator_impl& operator+=(size_t len) { pos += len; if (pos > end_ptr) throw end_of_buffer(); - } - iterator_impl& operator+=(size_t len) { - advance(len); return *this; } @@ -721,13 +718,9 @@ inline namespace v14_2_0 { return p == ls->end(); //return off == bl->length(); } - void advance(unsigned o); void seek(unsigned o); char operator*() const; - iterator_impl& operator+=(unsigned o) { - advance(o); - return *this; - } + iterator_impl& operator+=(unsigned o); iterator_impl& operator++(); ptr get_current_ptr() const; bool is_pointing_same_raw(const ptr& other) const; diff --git a/src/include/denc.h b/src/include/denc.h index 2a3a6401476..adb93ad16a1 100644 --- a/src/include/denc.h +++ b/src/include/denc.h @@ -1590,7 +1590,7 @@ inline std::enable_if_t decode( t.copy_shallow(remaining, tmp); auto cp = std::cbegin(tmp); traits::decode(o, cp); - p.advance(cp.get_offset()); + p += cp.get_offset(); } } @@ -1611,7 +1611,7 @@ inline std::enable_if_t decode( t.copy_shallow(p.get_bl().length() - p.get_off(), tmp); auto cp = std::cbegin(tmp); traits::decode(o, cp); - p.advance(cp.get_offset()); + p += cp.get_offset(); } // nohead variants @@ -1650,7 +1650,7 @@ inline std::enable_if_t decode_nohead( } auto cp = std::cbegin(tmp); traits::decode_nohead(num, o, cp); - p.advance(cp.get_offset()); + p += cp.get_offset(); } else { traits::decode_nohead(num, o, p); } @@ -1715,7 +1715,7 @@ inline std::enable_if_t decode_nohead( char *end = *start_pos + *struct_len; \ ceph_assert(pos <= end); \ if (pos < end) { \ - p.advance(end - pos); \ + p += end - pos; \ } \ } diff --git a/src/include/encoding.h b/src/include/encoding.h index 4bb9233df78..2b3e723da22 100644 --- a/src/include/encoding.h +++ b/src/include/encoding.h @@ -1382,7 +1382,7 @@ decode(std::array& v, bufferlist::const_iterator& p) } else if (skip_v) { \ if (bl.get_remaining() < skip_v) \ throw ::ceph::buffer::malformed_input(DECODE_ERR_PAST(__PRETTY_FUNCTION__)); \ - bl.advance(skip_v); \ + bl += skip_v; \ } \ unsigned struct_end = 0; \ if (struct_v >= lenv) { \ @@ -1467,7 +1467,7 @@ decode(std::array& v, bufferlist::const_iterator& p) if (bl.get_off() > struct_end) \ throw ::ceph::buffer::malformed_input(DECODE_ERR_PAST(__PRETTY_FUNCTION__)); \ if (bl.get_off() < struct_end) \ - bl.advance(struct_end - bl.get_off()); \ + bl += struct_end - bl.get_off(); \ } namespace ceph { diff --git a/src/journal/Entry.cc b/src/journal/Entry.cc index 7899bf1cc5a..9879a9aad97 100644 --- a/src/journal/Entry.cc +++ b/src/journal/Entry.cc @@ -102,7 +102,7 @@ bool Entry::is_readable(bufferlist::const_iterator iter, uint32_t *bytes_needed) *bytes_needed = 0; return false; } - iter.advance(HEADER_FIXED_SIZE - sizeof(bl_preamble)); + iter += HEADER_FIXED_SIZE - sizeof(bl_preamble); if (iter.get_remaining() < sizeof(uint32_t)) { *bytes_needed = sizeof(uint32_t) - iter.get_remaining(); @@ -115,7 +115,7 @@ bool Entry::is_readable(bufferlist::const_iterator iter, uint32_t *bytes_needed) *bytes_needed = data_size - iter.get_remaining(); return false; } - iter.advance(data_size); + iter += data_size; uint32_t end_off = iter.get_off(); if (iter.get_remaining() < sizeof(uint32_t)) { diff --git a/src/mds/journal.cc b/src/mds/journal.cc index 17c7c3a0a3a..14966f14ce1 100644 --- a/src/mds/journal.cc +++ b/src/mds/journal.cc @@ -3153,7 +3153,7 @@ void ENoOp::decode(bufferlist::const_iterator &bl) // journal debug tools catch it and recognise a malformed entry. throw buffer::end_of_buffer(); } else { - bl.advance(pad_size); + bl += pad_size; } DECODE_FINISH(bl); } diff --git a/src/messages/MOSDPing.h b/src/messages/MOSDPing.h index f95fe0a613e..530c803ce48 100644 --- a/src/messages/MOSDPing.h +++ b/src/messages/MOSDPing.h @@ -110,7 +110,7 @@ public: decode(delta_ub, p); } - p.advance(size); + p += size; min_message_size = size + payload_mid_length; } void encode_payload(uint64_t features) override { diff --git a/src/msg/async/ProtocolV1.cc b/src/msg/async/ProtocolV1.cc index c5d5e021fbd..06f77efa7a3 100644 --- a/src/msg/async/ProtocolV1.cc +++ b/src/msg/async/ProtocolV1.cc @@ -862,7 +862,7 @@ CtPtr ProtocolV1::handle_message_data(char *buffer, int r) { unsigned read_len = std::min(bp.length(), msg_left); ceph_assert(read_len < static_cast(std::numeric_limits::max())); - data_blp.advance(read_len); + data_blp += read_len; data.append(bp, 0, read_len); msg_left -= read_len; diff --git a/src/os/Transaction.cc b/src/os/Transaction.cc index 0701e14daa5..325f887d94d 100644 --- a/src/os/Transaction.cc +++ b/src/os/Transaction.cc @@ -14,10 +14,10 @@ void decode_str_str_map_to_bl(bufferlist::const_iterator& p, while (n--) { __u32 l; decode(l, p); - p.advance(l); + p += l; len += 4 + l; decode(l, p); - p.advance(l); + p += l; len += 4 + l; } start.copy(len, *out); @@ -33,7 +33,7 @@ void decode_str_set_to_bl(bufferlist::const_iterator& p, while (n--) { __u32 l; decode(l, p); - p.advance(l); + p += l; len += 4 + l; } start.copy(len, *out); diff --git a/src/os/bluestore/bluestore_types.cc b/src/os/bluestore/bluestore_types.cc index f7ff63e936d..a0b799422f7 100644 --- a/src/os/bluestore/bluestore_types.cc +++ b/src/os/bluestore/bluestore_types.cc @@ -36,7 +36,7 @@ void bluestore_bdev_label_t::encode(bufferlist& bl) const void bluestore_bdev_label_t::decode(bufferlist::const_iterator& p) { - p.advance(60u); // see above + p += 60u; // see above DECODE_START(2, p); decode(osd_uuid, p); decode(size, p); diff --git a/src/os/filestore/FileJournal.h b/src/os/filestore/FileJournal.h index e9d41331bcc..c4357b473cf 100644 --- a/src/os/filestore/FileJournal.h +++ b/src/os/filestore/FileJournal.h @@ -184,7 +184,7 @@ public: decode(v, bl); if (v < 2) { // normally 0, but conceivably 1 // decode old header_t struct (pre v0.40). - bl.advance(4u); // skip __u32 flags (it was unused by any old code) + bl += 4u; // skip __u32 flags (it was unused by any old code) flags = 0; uint64_t tfsid; decode(tfsid, bl); diff --git a/src/osd/OSDMap.h b/src/osd/OSDMap.h index db45f811ae8..15ce0ef7216 100644 --- a/src/osd/OSDMap.h +++ b/src/osd/OSDMap.h @@ -142,7 +142,7 @@ struct PGTempMap { offsets[i].second = p.get_off() - start_off; uint32_t vn; decode(vn, p); - p.advance(vn * sizeof(int32_t)); + p += vn * sizeof(int32_t); } size_t len = p.get_off() - start_off; pstart.copy(len, data); diff --git a/src/osd/PrimaryLogPG.cc b/src/osd/PrimaryLogPG.cc index f7a465b9c18..731866aac1e 100644 --- a/src/osd/PrimaryLogPG.cc +++ b/src/osd/PrimaryLogPG.cc @@ -5226,7 +5226,7 @@ int PrimaryLogPG::do_checksum(OpContext *ctx, OSDOp& osd_op, bufferlist init_value_bl; init_value_bl.substr_of(bl_it->get_bl(), bl_it->get_off(), csum_init_value_size); - bl_it->advance(csum_init_value_size); + *bl_it += csum_init_value_size; if (pool.info.is_erasure() && op.checksum.length > 0) { // If there is a data digest and it is possible we are reading diff --git a/src/osd/osd_types.cc b/src/osd/osd_types.cc index 901480b849f..0e0b47cfbbf 100644 --- a/src/osd/osd_types.cc +++ b/src/osd/osd_types.cc @@ -314,7 +314,7 @@ void request_redirect_t::decode(ceph::buffer::list::const_iterator& bl) decode(redirect_object, bl); decode(legacy_osd_instructions_len, bl); if (legacy_osd_instructions_len) { - bl.advance(legacy_osd_instructions_len); + bl += legacy_osd_instructions_len; } DECODE_FINISH(bl); } @@ -5578,7 +5578,7 @@ void SnapSet::decode(ceph::buffer::list::const_iterator& bl) { DECODE_START_LEGACY_COMPAT_LEN(3, 2, 2, bl); decode(seq, bl); - bl.advance(1u); // skip legacy head_exists (always true) + bl += 1u; // skip legacy head_exists (always true) decode(snaps, bl); decode(clones, bl); decode(clone_overlap, bl); diff --git a/src/osd/osd_types.h b/src/osd/osd_types.h index a405c69d36a..3102bcb8903 100644 --- a/src/osd/osd_types.h +++ b/src/osd/osd_types.h @@ -491,7 +491,7 @@ struct pg_t { decode(v, bl); decode(m_pool, bl); decode(m_seed, bl); - bl.advance(sizeof(int32_t)); // was preferred + bl += sizeof(int32_t); // was preferred } void decode_old(ceph::buffer::list::const_iterator& bl) { using ceph::decode; diff --git a/src/rgw/services/svc_notify.cc b/src/rgw/services/svc_notify.cc index a7148adadb0..e6c0b58fbd2 100644 --- a/src/rgw/services/svc_notify.cc +++ b/src/rgw/services/svc_notify.cc @@ -396,7 +396,7 @@ int RGWSI_Notify::robust_notify(RGWSI_RADOS::Obj& notify_obj, bufferlist& bl, ldout(cct, 20) << "robust_notify: acked by " << id << dendl; uint32_t blen; decode(blen, p); - p.advance(blen); + p += blen; } } catch (const buffer::error& e) { ldout(cct, 0) << "robust_notify: notify response parse failed: " @@ -435,7 +435,7 @@ int RGWSI_Notify::robust_notify(RGWSI_RADOS::Obj& notify_obj, bufferlist& bl, } uint32_t blen; decode(blen, p); - p.advance(blen); + p += blen; } uint32_t num_timeouts; diff --git a/src/test/bufferlist.cc b/src/test/bufferlist.cc index 9f9c206d4f0..6ec640fdb15 100644 --- a/src/test/bufferlist.cc +++ b/src/test/bufferlist.cc @@ -804,7 +804,7 @@ static void bench_bufferlistiter_deref(const size_t step, utime_t start = ceph_clock_now(); bufferlist::iterator iter = bl.begin(); while (iter != bl.end()) { - iter.advance(step); + iter += step; } utime_t end = ceph_clock_now(); cout << bufsize * bufnum << " derefs over bl with " << bufnum @@ -833,14 +833,14 @@ TEST(BufferListIterator, advance) { { bufferlist::iterator i(&bl); - EXPECT_THROW(i.advance(200u), buffer::end_of_buffer); + EXPECT_THROW(i += 200u, buffer::end_of_buffer); } { bufferlist::iterator i(&bl); EXPECT_EQ('A', *i); - i.advance(1u); + i += 1u; EXPECT_EQ('B', *i); - i.advance(3u); + i += 3u; EXPECT_EQ('E', *i); } } @@ -939,14 +939,14 @@ TEST(BufferListIterator, iterator_crc32c) { bl3.append(s.substr(98, 55)); it = bl1.begin(); - it.advance(98u); + it += 98u; ASSERT_EQ(bl3.crc32c(0), it.crc32c(55, 0)); ASSERT_EQ(4u, it.get_remaining()); bl3.clear(); bl3.append(s.substr(98 + 55)); it = bl1.begin(); - it.advance(98u + 55u); + it += 98u + 55u; ASSERT_EQ(bl3.crc32c(0), it.crc32c(10, 0)); ASSERT_EQ(0u, it.get_remaining()); } @@ -970,7 +970,7 @@ TEST(BufferListIterator, operator_star) { { bufferlist::iterator i(&bl); EXPECT_EQ('A', *i); - EXPECT_THROW(i.advance(200u), buffer::end_of_buffer); + EXPECT_THROW(i += 200u, buffer::end_of_buffer); EXPECT_THROW(*i, buffer::end_of_buffer); } } @@ -1062,7 +1062,7 @@ TEST(BufferListIterator, copy) { // // demonstrates that it seeks back to offset if p == ls->end() // - EXPECT_THROW(i.advance(200u), buffer::end_of_buffer); + EXPECT_THROW(i += 200u, buffer::end_of_buffer); i.copy(2, copy); EXPECT_EQ(0, ::memcmp(copy, expected, 2)); EXPECT_EQ('X', copy[2]); @@ -1102,7 +1102,7 @@ TEST(BufferListIterator, copy) { // // demonstrates that it seeks back to offset if p == ls->end() // - EXPECT_THROW(i.advance(200u), buffer::end_of_buffer); + EXPECT_THROW(i += 200u, buffer::end_of_buffer); i.copy(2, copy); EXPECT_EQ(0, ::memcmp(copy.c_str(), expected, 2)); i.seek(0); @@ -1123,7 +1123,7 @@ TEST(BufferListIterator, copy) { // // demonstrates that it seeks back to offset if p == ls->end() // - EXPECT_THROW(i.advance(200u), buffer::end_of_buffer); + EXPECT_THROW(i += 200u, buffer::end_of_buffer); i.copy_all(copy); EXPECT_EQ('A', copy[0]); EXPECT_EQ('B', copy[1]); @@ -1139,7 +1139,7 @@ TEST(BufferListIterator, copy) { // // demonstrates that it seeks back to offset if p == ls->end() // - EXPECT_THROW(i.advance(200u), buffer::end_of_buffer); + EXPECT_THROW(i += 200u, buffer::end_of_buffer); i.copy(2, copy); EXPECT_EQ(0, ::memcmp(copy.c_str(), expected, 2)); i.seek(0); @@ -1165,7 +1165,7 @@ TEST(BufferListIterator, copy_in) { // // demonstrates that it seeks back to offset if p == ls->end() // - EXPECT_THROW(i.advance(200u), buffer::end_of_buffer); + EXPECT_THROW(i += 200u, buffer::end_of_buffer); const char *expected = "ABC"; i.copy_in(3, expected); EXPECT_EQ(0, ::memcmp(bl.c_str(), expected, 3)); @@ -1182,7 +1182,7 @@ TEST(BufferListIterator, copy_in) { // // demonstrates that it seeks back to offset if p == ls->end() // - EXPECT_THROW(i.advance(200u), buffer::end_of_buffer); + EXPECT_THROW(i += 200u, buffer::end_of_buffer); bufferlist expected; expected.append("ABC", 3); i.copy_in(3, expected); diff --git a/src/test/compressor/test_compression.cc b/src/test/compressor/test_compression.cc index 52857cd5415..34049305460 100644 --- a/src/test/compressor/test_compression.cc +++ b/src/test/compressor/test_compression.cc @@ -201,7 +201,7 @@ TEST_P(CompressorTest, compress_decompress) prefix.claim_append(out); out.swap(prefix); it = out.cbegin(); - it.advance(prefix_len); + it += prefix_len; res = compressor->decompress(it, compressed_len, after); EXPECT_EQ(res, 0); EXPECT_TRUE(exp.contents_equal(after)); diff --git a/src/test/journal/test_Entry.cc b/src/test/journal/test_Entry.cc index ff0e82c01f0..1fa3136f795 100644 --- a/src/test/journal/test_Entry.cc +++ b/src/test/journal/test_Entry.cc @@ -70,7 +70,7 @@ TEST_F(TestEntry, IsReadableBadPreamble) { ASSERT_FALSE(journal::Entry::is_readable(it, &bytes_needed)); ASSERT_EQ(0U, bytes_needed); - it.advance(sizeof(stray_bytes)); + it += sizeof(stray_bytes); ASSERT_TRUE(journal::Entry::is_readable(it, &bytes_needed)); ASSERT_EQ(0U, bytes_needed); } diff --git a/src/test/test_denc.cc b/src/test/test_denc.cc index 4e7838a9391..0924ee4eda2 100644 --- a/src/test/test_denc.cc +++ b/src/test/test_denc.cc @@ -124,7 +124,7 @@ struct denc_counter_t { ++counts.num_encode; } void decode(buffer::ptr::const_iterator &p) { - p.advance(1); + p += 1; ++counts.num_decode; } }; @@ -140,7 +140,7 @@ struct denc_counter_bounded_t { ++counts.num_encode; } void decode(buffer::ptr::const_iterator &p) { - p.advance(1); + p += 1; ++counts.num_decode; } }; @@ -712,7 +712,7 @@ TEST(denc, no_copy_if_segmented_and_lengthy) ASSERT_GT(segmented.get_num_buffers(), 1u); ASSERT_GT(segmented.length(), CEPH_PAGE_SIZE); auto p = segmented.cbegin(); - p.advance(large_bl.length()); + p += large_bl.length(); ASSERT_LT(segmented.length() - p.get_off(), CEPH_PAGE_SIZE); vector v; Legacy::reset(); @@ -730,7 +730,7 @@ TEST(denc, no_copy_if_segmented_and_lengthy) ASSERT_GT(segmented.get_num_buffers(), 1u); ASSERT_GT(segmented.length(), CEPH_PAGE_SIZE); auto p = segmented.cbegin(); - p.advance(small_bl.length()); + p += small_bl.length(); ASSERT_GT(segmented.length() - p.get_off(), CEPH_PAGE_SIZE); vector v; Legacy::reset();