From: Kefu Chai Date: Sat, 6 Mar 2021 10:00:49 +0000 (+0800) Subject: osd/Watch: use vector<> instead of list<> X-Git-Tag: v17.1.0~2670^2 X-Git-Url: http://git-server-git.apps.pok.os.sepia.ceph.com/?a=commitdiff_plain;h=d4c94d2b50f9535ce847bbae3f4c5ebb3a0aa1b6;p=ceph.git osd/Watch: use vector<> instead of list<> 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, bufferlist> reply_map; std::set > 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 --- diff --git a/src/osd/Watch.cc b/src/osd/Watch.cc index 78aae6e2d962..ca71620d0df3 100644 --- a/src/osd/Watch.cc +++ b/src/osd/Watch.cc @@ -193,10 +193,11 @@ void Notify::maybe_complete_notify() // prepare reply bufferlist bl; encode(notify_replies, bl); - list > missed; - for (auto p = watchers.begin(); p != watchers.end(); ++p) { - missed.push_back(make_pair((*p)->get_watcher_gid(), - (*p)->get_cookie())); + vector> missed; + missed.reserve(watchers.size()); + for (auto& watcher : watchers) { + missed.emplace_back(watcher->get_watcher_gid(), + watcher->get_cookie()); } encode(missed, bl);