Don't do hash lookup twice in FindDef
authorChris Forbes <chrisforbes@google.com>
Tue, 27 Jun 2017 21:21:33 +0000 (14:21 -0700)
committerDavid Neto <dneto@google.com>
Wed, 28 Jun 2017 15:13:26 +0000 (11:13 -0400)
source/val/validation_state.cpp

index 350b09df436a8b2b66478247cfa5fcc268c09940..850f15eecc3a255bc592ee0f19044749b7d7d675 100644 (file)
@@ -209,25 +209,17 @@ bool ValidationState_t::IsDefinedId(uint32_t id) const {
 }
 
 const Instruction* ValidationState_t::FindDef(uint32_t id) const {
-  if (all_definitions_.count(id) == 0) {
+  auto it = all_definitions_.find(id);
+  if (it == all_definitions_.end())
     return nullptr;
-  } else {
-    /// We are in a const function, so we cannot use defs.operator[]().
-    /// Luckily we know the key exists, so defs_.at() won't throw an
-    /// exception.
-    return all_definitions_.at(id);
-  }
+  return it->second;
 }
 
 Instruction* ValidationState_t::FindDef(uint32_t id) {
-  if (all_definitions_.count(id) == 0) {
+  auto it = all_definitions_.find(id);
+  if (it == all_definitions_.end())
     return nullptr;
-  } else {
-    /// We are in a const function, so we cannot use defs.operator[]().
-    /// Luckily we know the key exists, so defs_.at() won't throw an
-    /// exception.
-    return all_definitions_.at(id);
-  }
+  return it->second;
 }
 
 // Increments the instruction count. Used for diagnostic