From: Kefu Chai Date: Fri, 6 Nov 2020 05:34:38 +0000 (+0800) Subject: mon/health_check: use range-based loop when appropriate X-Git-Tag: v16.1.0~606^2~1 X-Git-Url: http://git-server-git.apps.pok.os.sepia.ceph.com/?a=commitdiff_plain;h=4a0a737409f8ff3a5dbb752ade485fcc287d69a6;p=ceph.git mon/health_check: use range-based loop when appropriate Signed-off-by: Kefu Chai --- diff --git a/src/mon/health_check.h b/src/mon/health_check.h index 1473c496eec5..4e74637f9e53 100644 --- a/src/mon/health_check.h +++ b/src/mon/health_check.h @@ -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; } } }