STYLE: Replace declare-then-initialize with direct initialization#597
Open
hjmjohnson wants to merge 1 commit intomainfrom
Open
STYLE: Replace declare-then-initialize with direct initialization#597hjmjohnson wants to merge 1 commit intomainfrom
hjmjohnson wants to merge 1 commit intomainfrom
Conversation
Replace two-line declare-then-initialize patterns with idiomatic C++
single-line initialization across 39 files, following N-Dekker's
methodology from ITK commits 6cb6bf9823, 9962e2f971, 03941e42d8.
Patterns applied:
- fill_zero: Type v; v.Fill(0) -> Type v{}
- fill_nonzero: Type v; v.Fill(N) -> auto v = MakeFilled<Type>(N)
- elem_same: Type v; v[i]=x (all same) -> Type::Filled(x) or Fill(x)
- elem_zero: Type v; v[i]=0 -> Type v{}
- setsize_fill: v.SetSize(N); v.Fill(V) -> Type v(N, V)
All changes verified with full ninja build (841 targets, zero errors,
zero new warnings).
Co-Authored-By: Claude Opus 4.6 (1M context) <[email protected]>
a1a7463 to
83621f0
Compare
hjmjohnson
commented
Apr 13, 2026
| VectorType axis{}; | ||
|
|
||
| axis[0] = 0.0; | ||
| axis[1] = 0.0; |
Member
Author
There was a problem hiding this comment.
remove unnecessary resetting to zero.
hjmjohnson
commented
Apr 13, 2026
| RadiusType r1; | ||
| r1.Fill(1); | ||
| auto r1 = itk::MakeFilled<RadiusType>(1); | ||
| return r1; |
Member
Author
There was a problem hiding this comment.
Just return itk::MakeFilled<RadiusType>(1)
hjmjohnson
commented
Apr 13, 2026
| RotationMatrixType SpacingMatrix; | ||
| SpacingMatrix.Fill(0.0); | ||
| RotationMatrixType SpacingMatrix{}; | ||
| SpacingMatrix[0][0] = this->m_Volume->GetSpacing()[0]; |
Member
Author
There was a problem hiding this comment.
Make a single call to "this->m_Volume->GetSpacing();" and index on temp variable.
hjmjohnson
commented
Apr 13, 2026
| itk::ContinuousIndex<double, 3> imageIndex; | ||
| imageIndex[0] = 0; | ||
| itk::ContinuousIndex<double, 3> imageIndex{}; | ||
| imageIndex[1] = 0; |
Member
Author
There was a problem hiding this comment.
remove resetting to zero.
hjmjohnson
commented
Apr 13, 2026
| ConstNeighborhoodIteratorType::RadiusType radius; | ||
| radius[0] = 1; | ||
| auto radius = ConstNeighborhoodIteratorType::RadiusType::Filled(1); | ||
| radius[1] = 1; |
Member
Author
There was a problem hiding this comment.
remove resetting to 1.
hjmjohnson
commented
Apr 13, 2026
Member
Author
hjmjohnson
left a comment
There was a problem hiding this comment.
Some recommended cleanups.
Member
Author
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Replace two-line declare-then-initialize patterns with idiomatic C++ single-line initialization across 39 files, following N-Dekker's methodology from ITK.
Locally verified: full ninja build (841 targets), zero errors, zero new warnings.
Patterns applied (78 fixes total)
fill_zeroType v; v.Fill(0)→Type v{}fill_nonzeroType v; v.Fill(N)→auto v = MakeFilled<Type>(N)elem_sameType v; v[i]=x(all same) →Fill(x)elem_zeroType v; v[i]=0→Type v{}setsize_fillv.SetSize(N); v.Fill(V)→Type v(N, V)Patterns intentionally skipped
elem_diff(Type v; v[0]=x; v[1]=y;→Type v{x,y}): ITK derived types (Vector,Point,ContinuousIndex) don't inheritFixedArray's brace-init constructor; narrowing conversions (int→SizeValueType) also block this pattern.assign(Type v; v = expr;→Type v = expr;): Script's forward-reference hazard detection is unreliable — several fixes moved variable uses above their declarations.Reference commits in ITK
6cb6bf9823— N-Dekker:fill_nonzeropattern9962e2f971— N-Dekker:elem_samepattern03941e42d8— N-Dekker:elem_diffpattern