]> git-server-git.apps.pok.os.sepia.ceph.com Git - ceph.git/commitdiff
rgw: ordered list map efficiency 36305/head
authorJ. Eric Ivancich <ivancich@redhat.com>
Thu, 23 Jul 2020 20:54:14 +0000 (16:54 -0400)
committerJ. Eric Ivancich <ivancich@redhat.com>
Wed, 7 Apr 2021 17:31:50 +0000 (13:31 -0400)
Adding an object to the result map required two "find" operations
back-to-back, each of which was O(log n). By using
std::map::insert_or_assign function and getting an iterator, we can
avoid the second find.

Signed-off-by: J. Eric Ivancich <ivancich@redhat.com>
src/rgw/rgw_rados.cc

index 441b56574f6c13402b6328a278e710ed1569bea0..329e713fc329d5dbbbbbd9d56ca97174bafa0a24 100644 (file)
@@ -8533,10 +8533,16 @@ int RGWRados::cls_bucket_list_ordered(const DoutPrefixProvider *dpp,
       ldpp_dout(dpp, 10) << "RGWRados::" << __func__ << ": got " <<
        dirent.key << dendl;
 
-      m[name] = std::move(dirent);
-      last_entry_visited = &(m[name]);
-      ++count;
-    } else { // r == -ENOENT
+      auto [it, inserted] = m.insert_or_assign(name, std::move(dirent));
+      last_entry_visited = &it->second;
+      if (inserted) {
+       ++count;
+      } else {
+       ldpp_dout(dpp, 0) << "WARNING: RGWRados::" << __func__ <<
+         ": reassigned map value at \"" << name <<
+         "\", which should not happen" << dendl;
+      }
+    } else {
       ldpp_dout(dpp, 10) << "RGWRados::" << __func__ << ": skipping " <<
        dirent.key.name << "[" << dirent.key.instance << "]" << dendl;
       last_entry_visited = &tracker.dir_entry();