You are viewing a plain text version of this content. The canonical link for it is here.
Posted to github@arrow.apache.org by "wgtmac (via GitHub)" <gi...@apache.org> on 2023/04/20 01:45:50 UTC

[GitHub] [arrow] wgtmac commented on a diff in pull request #35149: GH-35141: [C++] Versions of IsNull/IsValid that don't branch on type

wgtmac commented on code in PR #35149:
URL: https://github.com/apache/arrow/pull/35149#discussion_r1171995537


##########
cpp/src/arrow/array/data.h:
##########
@@ -180,25 +180,46 @@ struct ARROW_EXPORT ArrayData {
 
   std::shared_ptr<ArrayData> Copy() const { return std::make_shared<ArrayData>(*this); }
 
-  bool IsNull(int64_t i) const { return !IsValid(i); }
+  inline bool IsNull(int64_t i) const { return !IsValid(i); }
 
-  bool IsValid(int64_t i) const {
+  inline bool IsValid(int64_t i) const {
     if (buffers[0] != NULLPTR) {
       return bit_util::GetBit(buffers[0]->data(), i + offset);
     }
     const auto type = this->type->id();
     if (type == Type::SPARSE_UNION) {
       return !internal::IsNullSparseUnion(*this, i);
-    }
-    if (type == Type::DENSE_UNION) {
+    } else if (type == Type::DENSE_UNION) {

Review Comment:
   nit: this line of change seems to be complained by clang-tidy.



##########
cpp/src/arrow/array/data.h:
##########
@@ -180,25 +180,46 @@ struct ARROW_EXPORT ArrayData {
 
   std::shared_ptr<ArrayData> Copy() const { return std::make_shared<ArrayData>(*this); }
 
-  bool IsNull(int64_t i) const { return !IsValid(i); }
+  inline bool IsNull(int64_t i) const { return !IsValid(i); }
 
-  bool IsValid(int64_t i) const {
+  inline bool IsValid(int64_t i) const {
     if (buffers[0] != NULLPTR) {
       return bit_util::GetBit(buffers[0]->data(), i + offset);
     }
     const auto type = this->type->id();
     if (type == Type::SPARSE_UNION) {
       return !internal::IsNullSparseUnion(*this, i);
-    }
-    if (type == Type::DENSE_UNION) {
+    } else if (type == Type::DENSE_UNION) {
       return !internal::IsNullDenseUnion(*this, i);
-    }
-    if (type == Type::RUN_END_ENCODED) {
+    } else if (type == Type::RUN_END_ENCODED) {
       return !internal::IsNullRunEndEncoded(*this, i);
     }
     return null_count.load() != length;
   }
 
+  template <typename ArrowType>
+  bool IsNullFast(int64_t i) const {
+    return !IsValidFast<ArrowType>(i);
+  }
+
+  template <typename ArrowType>
+  bool IsValidFast(int64_t i) const {
+    if constexpr (ArrowType::type_id == Type::NA) {
+      return false;
+    } else if constexpr (ArrowType::type_id == Type::SPARSE_UNION) {
+      return !internal::IsNullSparseUnion(*this, i);
+    } else if constexpr (ArrowType::type_id == Type::DENSE_UNION) {
+      return !internal::IsNullDenseUnion(*this, i);
+    } else if constexpr (ArrowType::type_id == Type::RUN_END_ENCODED) {
+      return !internal::IsNullRunEndEncoded(*this, i);
+    } else {
+      if (buffers[0] != NULLPTR) {
+        return bit_util::GetBit(buffers[0]->data(), i + offset);
+      }
+      return null_count.load() != length;

Review Comment:
   Maybe a dumb question: if the validity bitmap does not exist, shouldn't `null_count` be either 0 or -1 instead of other values?



-- 
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: github-unsubscribe@arrow.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org