Skip to content

Commit 777e66d

Browse files
blowekampdzenanz
authored andcommitted
PERF: improve map usage and increment prefix
1 parent 9e90993 commit 777e66d

1 file changed

Lines changed: 11 additions & 25 deletions

File tree

Modules/Filtering/ImageStatistics/include/itkLabelOverlapMeasuresImageFilter.hxx

Lines changed: 11 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -91,39 +91,25 @@ LabelOverlapMeasuresImageFilter<TLabelImage>::ThreadedStreamedGenerateData(const
9191
LabelType sourceLabel = itS.Get();
9292
LabelType targetLabel = itT.Get();
9393

94-
// Does the label exist in the local map?
95-
auto mapItS = localStatistics.find(sourceLabel);
96-
auto mapItT = localStatistics.find(targetLabel);
94+
// Initialized to empty if key does not already exist
95+
auto & sValue = localStatistics[sourceLabel];
96+
auto & tValue = localStatistics[targetLabel];
9797

98-
if (mapItS == localStatistics.end())
99-
{
100-
// Create a new label set measures object
101-
using MapValueType = typename MapType::value_type;
102-
mapItS = localStatistics.insert(MapValueType(sourceLabel, LabelSetMeasures())).first;
103-
}
104-
105-
if (mapItT == localStatistics.end())
106-
{
107-
// Create a new label set measures object
108-
using MapValueType = typename MapType::value_type;
109-
mapItT = localStatistics.insert(MapValueType(targetLabel, LabelSetMeasures())).first;
110-
}
111-
112-
mapItS->second.m_Source++;
113-
mapItT->second.m_Target++;
98+
++sValue.m_Source;
99+
++tValue.m_Target;
114100

115101
if (sourceLabel == targetLabel)
116102
{
117-
mapItS->second.m_Intersection++;
118-
mapItS->second.m_Union++;
103+
++sValue.m_Intersection;
104+
++sValue.m_Union;
119105
}
120106
else
121107
{
122-
mapItS->second.m_Union++;
123-
mapItT->second.m_Union++;
108+
++sValue.m_Union;
109+
++tValue.m_Union;
124110

125-
mapItS->second.m_SourceComplement++;
126-
mapItT->second.m_TargetComplement++;
111+
++sValue.m_SourceComplement;
112+
++tValue.m_TargetComplement;
127113
}
128114

129115
progress.CompletedPixel();

0 commit comments

Comments
 (0)