From 777e66d45981f287a88a7f63e645b637588288f5 Mon Sep 17 00:00:00 2001 From: Bradley Lowekamp Date: Thu, 28 Jul 2022 16:59:42 -0400 Subject: [PATCH] PERF: improve map usage and increment prefix --- .../itkLabelOverlapMeasuresImageFilter.hxx | 36 ++++++------------- 1 file changed, 11 insertions(+), 25 deletions(-) diff --git a/Modules/Filtering/ImageStatistics/include/itkLabelOverlapMeasuresImageFilter.hxx b/Modules/Filtering/ImageStatistics/include/itkLabelOverlapMeasuresImageFilter.hxx index d74a5a2cfe4..f5ee24198e6 100644 --- a/Modules/Filtering/ImageStatistics/include/itkLabelOverlapMeasuresImageFilter.hxx +++ b/Modules/Filtering/ImageStatistics/include/itkLabelOverlapMeasuresImageFilter.hxx @@ -91,39 +91,25 @@ LabelOverlapMeasuresImageFilter::ThreadedStreamedGenerateData(const LabelType sourceLabel = itS.Get(); LabelType targetLabel = itT.Get(); - // Does the label exist in the local map? - auto mapItS = localStatistics.find(sourceLabel); - auto mapItT = localStatistics.find(targetLabel); + // Initialized to empty if key does not already exist + auto & sValue = localStatistics[sourceLabel]; + auto & tValue = localStatistics[targetLabel]; - if (mapItS == localStatistics.end()) - { - // Create a new label set measures object - using MapValueType = typename MapType::value_type; - mapItS = localStatistics.insert(MapValueType(sourceLabel, LabelSetMeasures())).first; - } - - if (mapItT == localStatistics.end()) - { - // Create a new label set measures object - using MapValueType = typename MapType::value_type; - mapItT = localStatistics.insert(MapValueType(targetLabel, LabelSetMeasures())).first; - } - - mapItS->second.m_Source++; - mapItT->second.m_Target++; + ++sValue.m_Source; + ++tValue.m_Target; if (sourceLabel == targetLabel) { - mapItS->second.m_Intersection++; - mapItS->second.m_Union++; + ++sValue.m_Intersection; + ++sValue.m_Union; } else { - mapItS->second.m_Union++; - mapItT->second.m_Union++; + ++sValue.m_Union; + ++tValue.m_Union; - mapItS->second.m_SourceComplement++; - mapItT->second.m_TargetComplement++; + ++sValue.m_SourceComplement; + ++tValue.m_TargetComplement; } progress.CompletedPixel();