GH-48802: [C++] Replace redundant nullptr assignment to DCHECK_EQ in FixedSizeBinary to String/Binary cast #48803
+2
−3
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.
Rationale for this change
The TODO comment saying explicitly setting
output->buffers[2] = nullptrin the else branch was redundant.The output
ArrayDatais allocated byPrepareOutput()before the kernel executes:arrow/cpp/src/arrow/compute/exec.cc
Lines 907 to 908 in 7be5a89
PrepareOutput()resizes the buffers vector to the required size for the output type (3 for String/Binary: validity, offsets, data):arrow/cpp/src/arrow/compute/exec.cc
Lines 729 to 731 in 7be5a89
For String/Binary output types,
ComputeDataPreallocate()only preallocates the offsets buffer (not the data buffer):arrow/cpp/src/arrow/compute/exec.cc
Lines 294 to 298 in 7be5a89
PrepareOutput()only allocates buffers that are in thedata_preallocated_vector. For String/Binary, this means onlybuffers[1](offsets) is allocated:arrow/cpp/src/arrow/compute/exec.cc
Lines 739 to 747 in 7be5a89
Since
std::vector::resize()constructs all elements,buffers[2]is alreadynullptrfrom the resize call. Therefore, explicitly assigningnullptrin the else branch is redundant.What changes are included in this PR?
Converted the redundant else clause to
DCHECK_EQ.Are these changes tested?
Yes, I locally ran
Cast.FixedSizeBinaryToBinaryOrStringandCast.FixedSizeBinaryToBinaryOrStringWithSlice.Are there any user-facing changes?
No.