From: Radoslaw Zarzynski Date: Tue, 21 Jan 2020 16:19:57 +0000 (+0100) Subject: common: encode for std::list doesn't use bl::copy_in() anymore. X-Git-Tag: v15.1.0~55^2 X-Git-Url: http://git-server-git.apps.pok.os.sepia.ceph.com/?a=commitdiff_plain;h=refs%2Fpull%2F32785%2Fhead;p=ceph.git common: encode for std::list doesn't use bl::copy_in() anymore. Signed-off-by: Radoslaw Zarzynski --- diff --git a/src/include/encoding.h b/src/include/encoding.h index 1df65ad14ce..4bb9233df78 100644 --- a/src/include/encoding.h +++ b/src/include/encoding.h @@ -673,25 +673,20 @@ template inline std::enable_if_t encode(const std::list& ls, bufferlist& bl, uint64_t features) { - // should i pre- or post- count? - if (!ls.empty()) { - unsigned pos = bl.length(); - unsigned n = 0; - encode(n, bl); - for (auto p = ls.begin(); p != ls.end(); ++p) { - n++; - encode(*p, bl, features); - } - ceph_le32 en; - en = n; - bl.copy_in(pos, sizeof(en), (char*)&en); - } else { - __u32 n = (__u32)(ls.size()); // FIXME: this is slow on a list. - encode(n, bl); - for (auto p = ls.begin(); p != ls.end(); ++p) - encode(*p, bl, features); + using counter_encode_t = ceph_le32; + unsigned n = 0; + auto filler = bl.append_hole(sizeof(counter_encode_t)); + for (const auto& item : ls) { + // we count on our own because of buggy std::list::size() implementation + // which doesn't follow the O(1) complexity constraint C++11 has brought. + ++n; + encode(item, bl, features); } + counter_encode_t en; + en = n; + filler.copy_in(sizeof(en), reinterpret_cast(&en)); } + template inline std::enable_if_t decode(std::list& ls, bufferlist::const_iterator& p)