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>
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);
}
}