From aa6ef7e42966e36db74a4d15367379cbff37bbc8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andr=C3=A9=20Nusser?= Date: Sat, 6 Apr 2019 20:14:05 +0200 Subject: Avoid calling find on a map twice in midimap lookup. --- src/midimapper.cc | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/src/midimapper.cc b/src/midimapper.cc index 9243ecf..9593aae 100644 --- a/src/midimapper.cc +++ b/src/midimapper.cc @@ -30,18 +30,19 @@ int MidiMapper::lookup(int note) { std::lock_guard guard(mutex); - if(midimap.find(note) == midimap.end()) + auto midimap_it = midimap.find(note); + if(midimap_it == midimap.end()) { return -1; } - const std::string& instr = midimap[note]; - if(instrmap.find(instr) == instrmap.end()) + auto instrmap_it = instrmap.find(midimap_it->second); + if(instrmap_it == instrmap.end()) { return -1; } - return instrmap[instr]; + return instrmap_it->second; } void MidiMapper::swap(instrmap_t& instrmap, midimap_t& midimap) -- cgit v1.2.3