Skip to content

Commit

Permalink
MINOR: [C++] Slight improvement for ArrayData device_type (#41814)
Browse files Browse the repository at this point in the history
Responding to feedback on #40807:

              This condition implies that, conversely, in non-debug mode we could immediately return when we encounter a buffer? Instead of continue looping on all buffers and children...

_Originally posted in #40807 (comment)

Authored-by: Matt Topol <[email protected]>
Signed-off-by: Matt Topol <[email protected]>
  • Loading branch information
zeroshade authored May 28, 2024
1 parent 8f3bf67 commit 235608b
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 1 deletion.
12 changes: 12 additions & 0 deletions cpp/src/arrow/array/data.cc
Original file line number Diff line number Diff line change
Expand Up @@ -233,28 +233,40 @@ DeviceAllocationType ArrayData::device_type() const {
int type = 0;
for (const auto& buf : buffers) {
if (!buf) continue;
#ifdef NDEBUG
return buf->device_type();
#else
if (type == 0) {
type = static_cast<int>(buf->device_type());
} else {
DCHECK_EQ(type, static_cast<int>(buf->device_type()));
}
#endif
}

for (const auto& child : child_data) {
if (!child) continue;
#ifdef NDEBUG
return child->device_type();
#else
if (type == 0) {
type = static_cast<int>(child->device_type());
} else {
DCHECK_EQ(type, static_cast<int>(child->device_type()));
}
#endif
}

if (dictionary) {
#ifdef NDEBUG
return dictionary->device_type();
#else
if (type == 0) {
type = static_cast<int>(dictionary->device_type());
} else {
DCHECK_EQ(type, static_cast<int>(dictionary->device_type()));
}
#endif
}

return type == 0 ? DeviceAllocationType::kCPU : static_cast<DeviceAllocationType>(type);
Expand Down
2 changes: 1 addition & 1 deletion cpp/src/arrow/array/data.h
Original file line number Diff line number Diff line change
Expand Up @@ -369,7 +369,7 @@ struct ARROW_EXPORT ArrayData {
/// \see GetNullCount
int64_t ComputeLogicalNullCount() const;

/// \brief Returns the device_type of the underlying buffers and children
/// \brief Return the device_type of the underlying buffers and children
///
/// If there are no buffers in this ArrayData object, it just returns
/// DeviceAllocationType::kCPU as a default. We also assume that all buffers
Expand Down

0 comments on commit 235608b

Please sign in to comment.