]> git.apps.os.sepia.ceph.com Git - ceph.git/commitdiff
osd/Watch: use vector<> instead of list<> 39882/head
authorKefu Chai <kchai@redhat.com>
Sat, 6 Mar 2021 10:00:49 +0000 (18:00 +0800)
committerKefu Chai <kchai@redhat.com>
Sun, 7 Mar 2021 17:32:24 +0000 (01:32 +0800)
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>
src/osd/Watch.cc

index 78aae6e2d9629b98bd6fb4abcdc8b950a68959ad..ca71620d0df366ed4ac85d450c183dc6064e3b2d 100644 (file)
@@ -193,10 +193,11 @@ void Notify::maybe_complete_notify()
     // 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);