Skip to content

STYLE: Remove GoToBegin() from just constructed iterators "WithIndex"#6096

Merged
hjmjohnson merged 1 commit intoInsightSoftwareConsortium:mainfrom
N-Dekker:Remove-GoToBegin-from-just-constructed-iterator-WithIndex
Apr 22, 2026
Merged

STYLE: Remove GoToBegin() from just constructed iterators "WithIndex"#6096
hjmjohnson merged 1 commit intoInsightSoftwareConsortium:mainfrom
N-Dekker:Remove-GoToBegin-from-just-constructed-iterator-WithIndex

Conversation

@N-Dekker
Copy link
Copy Markdown
Contributor

Using Notepad++, Replace in Files, doing:

Find what: ^([ ]+)(Image\w+IteratorWithIndex[ ]+)(\w+)(.+)[\r\n]+\1\3\.GoToBegin\(\).
Replace with: $1$2$3$4
Search Mode: Regular expression

Using Notepad++, Replace in Files, doing:

    Find what: ^([ ]+)(Image\w+IteratorWithIndex[ ]+)(\w+)(.+)[\r\n]+\1\3\.GoToBegin\(\).
    Replace with: $1$2$3$4
    Search Mode: Regular expression

Follow-up to pull request InsightSoftwareConsortium#4830
commit cf57876
"STYLE: Remove unnecessary iterator `GoToBegin()` calls from Core"
@github-actions github-actions Bot added area:Filtering Issues affecting the Filtering module area:Registration Issues affecting the Registration module type:Style Style changes: no logic impact (indentation, comments, naming) labels Apr 21, 2026
@N-Dekker N-Dekker marked this pull request as ready for review April 21, 2026 15:11
@greptile-apps
Copy link
Copy Markdown
Contributor

greptile-apps Bot commented Apr 21, 2026

Greptile Summary

This is a straightforward style cleanup that removes redundant GoToBegin() calls from ImageRegionIteratorWithIndex and ImageRegionConstIteratorWithIndex variables that were called immediately after construction (the constructor already positions the iterator at the beginning of the region). All four changes are correct and safe.

Confidence Score: 5/5

This PR is safe to merge — all changes correctly remove redundant post-construction GoToBegin() calls with no behavioral impact.

All four changes are mechanical removals of no-op GoToBegin() calls on iterators that already start at the beginning after construction. No logic is altered, no new code paths are introduced, and the one nuanced case (itkRegionBasedLevelSetFunction.hxx) has already been discussed and acknowledged in the existing review thread.

No files require special attention.

Important Files Changed

Filename Overview
Modules/Filtering/DiffusionTensorImage/include/itkDiffusionTensor3DReconstructionImageFilter.hxx Removes redundant git.GoToBegin() immediately after ImageRegionConstIteratorWithIndex git(...) construction; clean and correct.
Modules/Filtering/Smoothing/include/itkBinomialBlurImageFilter.hxx Removes redundant tempItDir.GoToBegin() immediately after ImageRegionIteratorWithIndex tempItDir(...) construction; clean and correct.
Modules/Nonunit/Review/include/itkRegionBasedLevelSetFunction.hxx Removes It.GoToBegin() from a comma-expression; constIt.GoToBegin() is retained (acknowledged as a follow-up item per existing thread discussion).
Modules/Registration/Common/include/itkImageToImageMetric.hxx Removes redundant regionIter.GoToBegin() immediately after ImageRegionConstIteratorWithIndex regionIter(...) construction; clean and correct.

Flowchart

%%{init: {'theme': 'neutral'}}%%
flowchart TD
    A["ImageRegionIteratorWithIndex it(image, region)"]
    B["it.GoToBegin() — REMOVED (redundant)"]
    C["while (!it.IsAtEnd()) { ... }"]

    A -->|"Constructor already positions\niterator at begin"| C
    A -. "was" .-> B
    B -. "was" .-> C
Loading

Reviews (2): Last reviewed commit: "STYLE: Remove GoToBegin() from just cons..." | Re-trigger Greptile

Comment thread Modules/Nonunit/Review/include/itkRegionBasedLevelSetFunction.hxx
@hjmjohnson hjmjohnson marked this pull request as draft April 21, 2026 22:55
@hjmjohnson hjmjohnson marked this pull request as ready for review April 21, 2026 22:56
@hjmjohnson hjmjohnson merged commit 056f5eb into InsightSoftwareConsortium:main Apr 22, 2026
19 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area:Filtering Issues affecting the Filtering module area:Registration Issues affecting the Registration module type:Style Style changes: no logic impact (indentation, comments, naming)

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants