MantisBT - ITK
View Issue Details
0005646ITKpublic2007-09-03 09:292007-09-16 17:00
Dieter Hahn 
Luis Ibanez 
normalminoralways
closedfixed 
 
 
0005646: ImageRegionConstIteratorWithIndex redundant arithmetic operation
Hi,

within the -- operator, there is a redundant arithmetic call that should be deleted, as the iterator operations have to be as efficient as possible.

See the else part of the decrement code:

>> this->m_PositionIndex[ in ]--; << // this is redundant! as it is set below

      this->m_Position += this->m_OffsetTable[ in ]
        * ( static_cast<long>(this->m_Region.GetSize()[in])-1 );
      this->m_PositionIndex[ in ] = this->m_EndIndex[ in ] - 1;

Thanks,
Dieter
No tags attached.
Issue History
2007-09-03 09:29Dieter HahnNew Issue
2007-09-16 12:46Luis IbanezStatusnew => assigned
2007-09-16 12:46Luis IbanezAssigned To => Luis Ibanez
2007-09-16 12:49Luis IbanezNote Added: 0009005
2007-09-16 12:49Luis IbanezStatusassigned => acknowledged
2007-09-16 16:59Luis IbanezNote Added: 0009007
2007-09-16 17:00Luis IbanezStatusacknowledged => closed
2007-09-16 17:00Luis IbanezNote Added: 0009008
2007-09-16 17:00Luis IbanezResolutionopen => fixed

Notes
(0009005)
Luis Ibanez   
2007-09-16 12:49   
The bug report makes sense

The following changes seem to be needed.

Index: itkImageRegionConstIteratorWithIndex.txx
===================================================================
RCS file: /cvsroot/Insight/Insight/Code/Common/itkImageRegionConstIteratorWithIndex.txx,v
retrieving revision 1.6
diff -r1.6 itkImageRegionConstIteratorWithIndex.txx
37d36
< this->m_PositionIndex[ in ]++;
39a39
> this->m_PositionIndex[ in ]++;
83d82
< this->m_PositionIndex[ in ]--;
(0009007)
Luis Ibanez   
2007-09-16 16:59   
Actually only the line that Dieter indicated needed to be modifed,
the structure of the operator++ is a bit different, and the frequency
of the double operation is negligible.

The code was committed as:
http://www.itk.org/cgi-bin/viewcvs.cgi/Code/Common/itkImageRegionConstIteratorWithIndex.txx?root=Insight&sortby=date&r2=1.7&r1=1.6 [^]
(0009008)
Luis Ibanez   
2007-09-16 17:00   
an experimental build was submitted from Zion.
All tests passed.