]> git.apps.os.sepia.ceph.com Git - ceph.git/commitdiff
Revisit std::multimap decoder
authorColin Patrick McCabe <cmccabe@alumni.cmu.edu>
Fri, 5 Nov 2010 19:17:40 +0000 (12:17 -0700)
committerColin Patrick McCabe <cmccabe@alumni.cmu.edu>
Fri, 5 Nov 2010 19:20:38 +0000 (12:20 -0700)
Previously I changed the std::multimap decoder to minimize the number of
constructor invocations. However, it could be much more expensive to
copy an initialized (decoded) val_t than to copy an empty one. For
example, if we are decoding std::multimap < int, std::set <int> >. So
change the code to insert a non-decoded val_t again.

However, this still saves two constructor invocations over the original.

Signed-off-by: Colin McCabe <colinm@hq.newdream.net>
src/include/encoding.h

index 1a08b21ace5268019d9dab7776d781574be6f4a3..defb74dc5f1a7f89114154bf01fc2cc8d2651f1c 100644 (file)
@@ -450,10 +450,10 @@ inline void decode(std::multimap<T,U>& m, bufferlist::iterator& p)
   decode(n, p);
   m.clear();
   while (n--) {
-    typename std::pair<T,U> val;
-    decode(val.first, p);
-    decode(val.second, p);
-    m.insert(val);
+    typename std::pair<T,U> tu;
+    decode(tu.first, p);
+    typename std::multimap<T,U>::iterator it = m.insert(tu);
+    decode(it->second, p);
   }
 }