felipecrv commented on code in PR #36256:
URL: https://github.com/apache/arrow/pull/36256#discussion_r1243852700


##########
cpp/src/arrow/compute/kernels/scalar_if_else_benchmark.cc:
##########
@@ -24,42 +24,79 @@
 #include "arrow/testing/gtest_util.h"
 #include "arrow/testing/random.h"
 #include "arrow/util/key_value_metadata.h"
+#include "arrow/util/logging.h"
 
 namespace arrow {
 namespace compute {
 
 const int64_t kNumItems = 1024 * 1024;
 const int64_t kFewItems = 64 * 1024;
 
-template <typename Type, typename Enable = void>
-struct GetBytesProcessed {};
+struct GetBytesProcessedVisitor {
+  const Array* arr;
+  int64_t total_bytes = 0;
 
-template <>
-struct GetBytesProcessed<BooleanType> {
-  static int64_t Get(const std::shared_ptr<Array>& arr) { return arr->length() 
/ 8; }
-};
+  explicit GetBytesProcessedVisitor(const Array* arr) : arr(arr) {}
 
-template <typename Type>
-struct GetBytesProcessed<Type, enable_if_number<Type>> {
-  static int64_t Get(const std::shared_ptr<Array>& arr) {
+  Status RecurseInto(const Array* child_arr) {
+    // return VisitTypeInline(*child_arr->type(), this);
+    return Status::OK();
+  }
+
+  Status Visit(const BooleanType& type) {
+    total_bytes = arr->length() / 8;
+    return Status::OK();
+  }
+
+  template <typename Type>
+  std::enable_if_t<is_number_type<Type>::value, Status> Visit(const Type& 
type) {
     using CType = typename Type::c_type;
-    return arr->length() * sizeof(CType);
+    total_bytes += arr->length() * sizeof(CType);
+    return Status::OK();
   }
-};
 
-template <typename Type>
-struct GetBytesProcessed<Type, enable_if_base_binary<Type>> {
-  static int64_t Get(const std::shared_ptr<Array>& arr) {
+  template <typename Type>
+  std::enable_if_t<is_base_binary_type<Type>::value, Status> Visit(const Type& 
type) {
     using ArrayType = typename TypeTraits<Type>::ArrayType;
     using OffsetType = typename TypeTraits<Type>::OffsetType::c_type;
-    return arr->length() * sizeof(OffsetType) +
-           std::static_pointer_cast<ArrayType>(arr)->total_values_length();
+    total_bytes += arr->length() * sizeof(OffsetType) +
+                   internal::checked_cast<const 
ArrayType*>(arr)->total_values_length();
+    return Status::OK();
+  }
+
+  template <typename ArrowType>
+  std::enable_if_t<is_list_like_type<ArrowType>::value &&
+                       !is_fixed_size_list_type<ArrowType>::value,
+                   Status>
+  Visit(const ArrowType& type) {
+    using ArrayType = typename TypeTraits<ArrowType>::ArrayType;
+    using OffsetType = typename TypeTraits<ArrowType>::OffsetType::c_type;
+
+    if constexpr (ArrowType::type_id == Type::LIST ||
+                  ArrowType::type_id == Type::LARGE_LIST) {
+      total_bytes += (arr->length() + 1) * sizeof(OffsetType);
+      auto child_array = internal::checked_cast<const 
ArrayType*>(arr)->values();
+      return RecurseInto(child_array.get());
+    } else {
+      return Unimplemented(type);

Review Comment:
   Removing the `if` altogether.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to