there is no need to use a list<> here. and this change does not
change the encoding schema here. also, as a fact, the user of the
watch-notify feature is decoding the bufferlist like:
std::map<std::pair<uint64_t,uint64_t>, bufferlist> reply_map;
std::set<std::pair<uint64_t,uint64_t> > missed_map;
decode(reply_map, reply_p);
decode(missed_map, reply_p);
so, in this change, change list<> to vector<> for both smaller memory
footprint and for better readability.
Signed-off-by: Kefu Chai <kchai@redhat.com>
// prepare reply
bufferlist bl;
encode(notify_replies, bl);
- list<pair<uint64_t,uint64_t> > missed;
- for (auto p = watchers.begin(); p != watchers.end(); ++p) {
- missed.push_back(make_pair((*p)->get_watcher_gid(),
- (*p)->get_cookie()));
+ vector<pair<uint64_t,uint64_t>> missed;
+ missed.reserve(watchers.size());
+ for (auto& watcher : watchers) {
+ missed.emplace_back(watcher->get_watcher_gid(),
+ watcher->get_cookie());
}
encode(missed, bl);