Look Up Time Step Object Exactly Once

Using .contains() followed by .at() with the same argument will
perform the same map lookup twice.
This commit is contained in:
Bård Skaflestad 2023-01-26 17:13:50 +01:00 committed by Kristian Bendiksen
parent 62ce2b18e0
commit 6eebd01bd4

View File

@ -48,10 +48,11 @@ RimWellAllocationOverTimeCollection::RimWellAllocationOverTimeCollection(
QDateTime prevValidTimeStep;
for ( auto it = m_timeStepDates.rbegin(); it != m_timeStepDates.rend(); ++it )
{
const QDateTime& timeStep = *it;
if ( timeStepAndCalculatorPairs.contains( timeStep ) )
const QDateTime& timeStep = *it;
auto timeStepCalculatorIt = timeStepAndCalculatorPairs.find( timeStep );
if ( timeStepCalculatorIt != timeStepAndCalculatorPairs.end() )
{
m_timeStepAndCalculatorPairs.emplace( timeStep, timeStepAndCalculatorPairs.at( timeStep ) );
m_timeStepAndCalculatorPairs.emplace( timeStep, timeStepCalculatorIt->second );
prevValidTimeStep = timeStep;
}
else if ( prevValidTimeStep.isValid() )