From: Leonid Usov Date: Thu, 8 Feb 2024 11:39:31 +0000 (+0200) Subject: encoding: add emplace variants for map dencoders X-Git-Tag: v20.0.0~2418^2~21 X-Git-Url: http://git.apps.os.sepia.ceph.com/?a=commitdiff_plain;h=641279c4d0feb1fd18fe0544e40c86c4b0ada38a;p=ceph.git encoding: add emplace variants for map dencoders Signed-off-by: Leonid Usov --- diff --git a/src/include/encoding.h b/src/include/encoding.h index 08c67c33eecf8..575580f41a8ff 100644 --- a/src/include/encoding.h +++ b/src/include/encoding.h @@ -1095,6 +1095,22 @@ inline std::enable_if_t decode(m[k], p); } } +template +inline std::enable_if_t +decode(std::map& m, bufferlist::const_iterator& p) +{ + __u32 n; + decode(n, p); + m.clear(); + while (n--) { + T k; + U v; + decode(k, p); + decode(v, p); + m.emplace(std::move(k), std::move(v)); + } +} template inline void decode_noclear(std::map& m, bufferlist::const_iterator& p) { @@ -1106,6 +1122,19 @@ inline void decode_noclear(std::map& m, bufferlist::const_iterat decode(m[k], p); } } +template +inline void decode_noclear(std::map& m, bufferlist::const_iterator& p) +{ + __u32 n; + decode(n, p); + while (n--) { + T k; + U v; + decode(k, p); + decode(v, p); + m.emplace(std::move(k), std::move(v)); + } +} template inline std::enable_if_t @@ -1139,6 +1168,21 @@ inline std::enable_if_t } } +template +inline std::enable_if_t +decode_nohead(int n, std::map& m, bufferlist::const_iterator& p) +{ + m.clear(); + while (n--) { + T k; + U v; + decode(k, p); + decode(v, p); + m.emplace(std::move(k), std::move(v)); + } +} + // boost::container::flat-map template @@ -1290,6 +1334,21 @@ inline void decode(unordered_map& m, bufferlist::const_iter } } +template +inline void decode(unordered_map& m, bufferlist::const_iterator& p) +{ + __u32 n; + decode(n, p); + m.clear(); + while (n--) { + T k; + U v; + decode(k, p); + decode(v, p); + m.emplace(std::move(k), std::move(v)); + } +} + // ceph::unordered_set template inline void encode(const ceph::unordered_set& m, bufferlist& bl)