]> git-server-git.apps.pok.os.sepia.ceph.com Git - ceph.git/commitdiff
mon/health_check: use range-based loop when appropriate
authorKefu Chai <kchai@redhat.com>
Fri, 6 Nov 2020 05:34:38 +0000 (13:34 +0800)
committerKefu Chai <kchai@redhat.com>
Mon, 9 Nov 2020 16:58:10 +0000 (00:58 +0800)
Signed-off-by: Kefu Chai <kchai@redhat.com>
src/mon/health_check.h

index 1473c496eec553f0a3ab738472a362f23a5f608f..4e74637f9e53d99622e8516cad9ff54653490ed9 100644 (file)
@@ -119,8 +119,8 @@ struct health_check_map_t {
   }
 
   void dump(ceph::Formatter *f) const {
-    for (auto& p : checks) {
-      f->dump_object(p.first.c_str(), p.second);
+    for (auto& [code, check] : checks) {
+      f->dump_object(code, check);
     }
   }
 
@@ -173,18 +173,15 @@ struct health_check_map_t {
   }
 
   void merge(const health_check_map_t& o) {
-    for (auto& p : o.checks) {
-      auto q = checks.find(p.first);
-      if (q == checks.end()) {
-       // new check
-       checks[p.first] = p.second;
-      } else {
-       // merge details, and hope the summary matches!
-       q->second.detail.insert(
-         q->second.detail.end(),
-         p.second.detail.begin(),
-         p.second.detail.end());
-       q->second.count += p.second.count;
+    for (auto& [code, check] : o.checks) {
+      auto [it, new_check] = checks.try_emplace(code, check);
+      if (!new_check) {
+        // merge details, and hope the summary matches!
+        it->second.detail.insert(
+          it->second.detail.end(),
+          check.detail.begin(),
+          check.detail.end());
+        it->second.count += check.count;
       }
     }
   }