STYLE: Replace Allocate(true) with AllocateInitialized()#6009
Conversation
AllocateInitialized() is an alias for Allocate(true) introduced in itkImageBase.h to make zero-initialization intent explicit in code. Replace all call sites in Modules/ and Examples/. The trailing "// initialize buffer to zero" comments are also removed since AllocateInitialized() is self-documenting. Suggested by N-Dekker in ITK PR InsightSoftwareConsortium#6003.
|
| Filename | Overview |
|---|---|
| Examples/DataRepresentation/Image/Image3.cxx | Replaced image->Allocate(true); // initialize buffer to zero with image->AllocateInitialized() — mechanical style substitution, no semantic change |
| Examples/DataRepresentation/Image/Image4.cxx | Replaced image->Allocate(true); // initialize buffer to zero with image->AllocateInitialized() — same style substitution as Image3.cxx |
| Examples/Filtering/DigitallyReconstructedRadiograph1.cxx | Replaced image->Allocate(true); // initialize to zero. with image->AllocateInitialized(), removing the now-redundant comment |
| Examples/Segmentation/HoughTransform2DCirclesImageFilter.cxx | Replaced localOutputImage->Allocate(true); // initializes buffer to zero with localOutputImage->AllocateInitialized() |
| Examples/Segmentation/HoughTransform2DLinesImageFilter.cxx | Replaced localOutputImage->Allocate(true); // initialize buffer to zero with localOutputImage->AllocateInitialized() |
| Examples/SpatialObjects/ImageMaskSpatialObject.cxx | Replaced image->Allocate(true); // initialize buffer to zero with image->AllocateInitialized(), removing the now-redundant comment |
| Modules/IO/TransformMINC/src/itkMINCTransformIO.cxx | Two replacements of ->Allocate(true) with ->AllocateInitialized() in ReadOneTransform and WriteOneTransform; no comments were present |
Sequence Diagram
sequenceDiagram
participant Caller
participant Image as ITK Image
participant Buffer as Pixel Buffer
Note over Caller,Image: Before PR
Caller->>Image: Allocate(true)
Image->>Buffer: allocate + zero-initialize
Buffer-->>Caller: done
Note over Caller,Image: After PR (semantically identical)
Caller->>Image: AllocateInitialized()
Image->>Image: Allocate(true) [inline alias in itkImageBase.h]
Image->>Buffer: allocate + zero-initialize
Buffer-->>Caller: done
Reviews (2): Last reviewed commit: "STYLE: Replace Allocate(true) with Alloc..." | Re-trigger Greptile
Did you test it locally? You know, the CI doesn't build the Examples! Do you think Claude specifically uses the examples for its code generation? |
Local Build & Test Report (macOS arm64, clang++)Platform: macOS 15.1, Apple Silicon (arm64) Build: ✅ No errors or warningsAll 7 changed targets compiled and linked cleanly:
Tests: ✅ 28/28 passedNo regressions detected. The |
|
Pixi-Cxx CI failure note: The |
fe35b68
into
InsightSoftwareConsortium:main
Summary
Replaces all
->Allocate(true)call sites with the self-documenting alias->AllocateInitialized()throughoutModules/andExamples/.Motivation
Allocate(true)zero-initializes the image buffer, but the boolean argument is easy to misread.AllocateInitialized()was added toitkImageBase.hspecifically for readability:The redundant trailing comments (
// initialize buffer to zero) are also removed since the method name is now self-documenting.Scope
Modules/IO/TransformMINC/src/itkMINCTransformIO.cxx— 2 sitesExamples/— 6 sitesAllocate()(no args) andAllocate(false)are not changed. The definition initkImageBase.his unchanged.Pure mechanical substitution — no semantic change.
Suggested by @N-Dekker in #6003 (comment)