]> git.apps.os.sepia.ceph.com Git - ceph.git/commitdiff
encoding: add emplace variants for map dencoders
authorLeonid Usov <leonid.usov@ibm.com>
Thu, 8 Feb 2024 11:39:31 +0000 (13:39 +0200)
committerLeonid Usov <leonid.usov@ibm.com>
Mon, 4 Mar 2024 11:48:03 +0000 (13:48 +0200)
Signed-off-by: Leonid Usov <leonid.usov@ibm.com>
src/include/encoding.h

index 08c67c33eecf8a73aef6a9759f10c59aa815ec88..575580f41a8ff7698af6787d5020b7d81dd3dacb 100644 (file)
@@ -1095,6 +1095,22 @@ inline std::enable_if_t<!t_traits::supported || !u_traits::supported>
     decode(m[k], p);
   }
 }
+template <std::move_constructible T, std::move_constructible U, class Comp, class Alloc,
+    typename t_traits, typename u_traits>
+inline std::enable_if_t<!t_traits::supported || !u_traits::supported>
+decode(std::map<T, U, Comp, Alloc>& 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<class T, class U, class Comp, class Alloc>
 inline void decode_noclear(std::map<T,U,Comp,Alloc>& m, bufferlist::const_iterator& p)
 {
@@ -1106,6 +1122,19 @@ inline void decode_noclear(std::map<T,U,Comp,Alloc>& m, bufferlist::const_iterat
     decode(m[k], p);
   }
 }
+template<std::move_constructible T, std::move_constructible U, class Comp, class Alloc>
+inline void decode_noclear(std::map<T,U,Comp,Alloc>& 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<class T, class U, class Comp, class Alloc,
         typename t_traits, typename u_traits>
 inline std::enable_if_t<!t_traits::supported || !u_traits::supported>
@@ -1139,6 +1168,21 @@ inline std::enable_if_t<!t_traits::supported || !u_traits::supported>
   }
 }
 
+template <std::move_constructible T, std::move_constructible U, class Comp, class Alloc,
+    typename t_traits, typename u_traits>
+inline std::enable_if_t<!t_traits::supported || !u_traits::supported>
+decode_nohead(int n, std::map<T, U, Comp, Alloc>& 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<class T, class U, class Comp, class Alloc,
         typename t_traits, typename u_traits>
@@ -1290,6 +1334,21 @@ inline void decode(unordered_map<T,U,Hash,Pred,Alloc>& m, bufferlist::const_iter
   }
 }
 
+template <std::move_constructible T, std::move_constructible U, class Hash, class Pred, class Alloc>
+inline void decode(unordered_map<T, U, Hash, Pred, Alloc>& 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<class T, class Hash, class Pred, class Alloc>
 inline void encode(const ceph::unordered_set<T,Hash,Pred,Alloc>& m, bufferlist& bl)