From: Kefu Chai Date: Wed, 21 Jul 2021 04:40:20 +0000 (+0800) Subject: crush/CrushWrapper: avoid lookup in a map twice X-Git-Tag: v17.1.0~1256^2 X-Git-Url: http://git-server-git.apps.pok.os.sepia.ceph.com/?a=commitdiff_plain;h=d0686c47d387fdbd7ee26f48264600d626e8a965;p=ceph.git crush/CrushWrapper: avoid lookup in a map twice there is no need to look up in a map twice for searching an item by a given key. Signed-off-by: Kefu Chai --- diff --git a/src/crush/CrushWrapper.h b/src/crush/CrushWrapper.h index 14295f4c6702..b8caa24ce621 100644 --- a/src/crush/CrushWrapper.h +++ b/src/crush/CrushWrapper.h @@ -374,9 +374,12 @@ public: } int get_type_id(const std::string& name) const { build_rmaps(); - if (type_rmap.count(name)) - return type_rmap[name]; - return -1; + auto found = type_rmap.find(name); + if (found != type_rmap.end()) { + return found->second; + } else { + return -1; + } } std::optional get_validated_type_id(const std::string& name) const { int retval = get_type_id(name);