Skip to content

Commit a37bf81

Browse files
committed
PERF: Let ImageRegionRange bypass OffsetTable[0] (which is always 1)
It appears unnecessary to access `m_OffsetTable[VIndex]` when `VIndex` is zero. A performance improvement of around 1% was observed, doing a range-based `for` loop on a region of 1'000'000 x 10'000 pixels.
1 parent 70204be commit a37bf81

1 file changed

Lines changed: 16 additions & 2 deletions

File tree

Modules/Core/Common/include/itkImageRegionRange.h

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -148,7 +148,14 @@ class ImageRegionRange final
148148
void
149149
Increment() noexcept
150150
{
151-
m_BufferIterator += m_OffsetTable[VIndex];
151+
if constexpr (VIndex == 0)
152+
{
153+
++m_BufferIterator;
154+
}
155+
else
156+
{
157+
m_BufferIterator += m_OffsetTable[VIndex];
158+
}
152159

153160
if constexpr (VIndex < (ImageDimension - 1))
154161
{
@@ -172,7 +179,14 @@ class ImageRegionRange final
172179
void
173180
Decrement() noexcept
174181
{
175-
m_BufferIterator -= m_OffsetTable[VIndex];
182+
if constexpr (VIndex == 0)
183+
{
184+
--m_BufferIterator;
185+
}
186+
else
187+
{
188+
m_BufferIterator -= m_OffsetTable[VIndex];
189+
}
176190

177191
if constexpr (VIndex < (ImageDimension - 1))
178192
{

0 commit comments

Comments
 (0)