]> git-server-git.apps.pok.os.sepia.ceph.com Git - ceph.git/commitdiff
crush/CrushWrapper: avoid lookup in a map twice 42432/head
authorKefu Chai <kchai@redhat.com>
Wed, 21 Jul 2021 04:40:20 +0000 (12:40 +0800)
committerKefu Chai <kchai@redhat.com>
Wed, 21 Jul 2021 04:57:21 +0000 (12:57 +0800)
there is no need to look up in a map twice for searching an item by a
given key.

Signed-off-by: Kefu Chai <kchai@redhat.com>
src/crush/CrushWrapper.h

index 14295f4c67020b7dbfaddf30fca74974402c5b09..b8caa24ce621c989ec70820f59c3245cbc033636 100644 (file)
@@ -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<int> get_validated_type_id(const std::string& name) const {
     int retval = get_type_id(name);