From d0686c47d387fdbd7ee26f48264600d626e8a965 Mon Sep 17 00:00:00 2001 From: Kefu Chai Date: Wed, 21 Jul 2021 12:40:20 +0800 Subject: [PATCH] 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 --- src/crush/CrushWrapper.h | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) 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); -- 2.47.3