From d431b69c28f1d608a14e85b93c60e99e85984c16 Mon Sep 17 00:00:00 2001 From: Chris Forbes Date: Tue, 27 Jun 2017 14:21:33 -0700 Subject: [PATCH] Don't do hash lookup twice in FindDef --- source/val/validation_state.cpp | 20 ++++++-------------- 1 file changed, 6 insertions(+), 14 deletions(-) diff --git a/source/val/validation_state.cpp b/source/val/validation_state.cpp index 350b09df..850f15ee 100644 --- a/source/val/validation_state.cpp +++ b/source/val/validation_state.cpp @@ -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 -- 2.34.1