From d4c94d2b50f9535ce847bbae3f4c5ebb3a0aa1b6 Mon Sep 17 00:00:00 2001 From: Kefu Chai Date: Sat, 6 Mar 2021 18:00:49 +0800 Subject: [PATCH] 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 --- src/osd/Watch.cc | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) 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); -- 2.47.3