From 1ce17ad8f5ee5782a1a3a946fe6227aa1f0def3e Mon Sep 17 00:00:00 2001 From: Matt Topol Date: Fri, 24 May 2024 12:16:04 -0400 Subject: [PATCH] MINOR: [C++] Slight improvement for ArrayData device_type --- cpp/src/arrow/array/data.cc | 12 ++++++++++++ cpp/src/arrow/array/data.h | 2 +- 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/cpp/src/arrow/array/data.cc b/cpp/src/arrow/array/data.cc index 76a43521394..83eeb56c496 100644 --- a/cpp/src/arrow/array/data.cc +++ b/cpp/src/arrow/array/data.cc @@ -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(buf->device_type()); } else { DCHECK_EQ(type, static_cast(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(child->device_type()); } else { DCHECK_EQ(type, static_cast(child->device_type())); } +#endif } if (dictionary) { +#ifdef NDEBUG + return dictionary->device_type(); +#else if (type == 0) { type = static_cast(dictionary->device_type()); } else { DCHECK_EQ(type, static_cast(dictionary->device_type())); } +#endif } return type == 0 ? DeviceAllocationType::kCPU : static_cast(type); diff --git a/cpp/src/arrow/array/data.h b/cpp/src/arrow/array/data.h index 0c49f36229a..e0508fe6980 100644 --- a/cpp/src/arrow/array/data.h +++ b/cpp/src/arrow/array/data.h @@ -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