arrow-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From w...@apache.org
Subject arrow git commit: ARROW-712: [C++] Reimplement Array::Accept as inline visitor
Date Sun, 26 Mar 2017 15:01:19 GMT
Repository: arrow
Updated Branches:
  refs/heads/master fd876697f -> 6d4e86290


ARROW-712: [C++] Reimplement Array::Accept as inline visitor

Author: Wes McKinney <wes.mckinney@twosigma.com>

Closes #442 from wesm/more-inline-visitors and squashes the following commits:

69af01a [Wes McKinney] Remove unused member
362dd7e [Wes McKinney] cpplint
1e56f0f [Wes McKinney] Reimplement Array::Accept as inline visitor


Project: http://git-wip-us.apache.org/repos/asf/arrow/repo
Commit: http://git-wip-us.apache.org/repos/asf/arrow/commit/6d4e8629
Tree: http://git-wip-us.apache.org/repos/asf/arrow/tree/6d4e8629
Diff: http://git-wip-us.apache.org/repos/asf/arrow/diff/6d4e8629

Branch: refs/heads/master
Commit: 6d4e862902fd56c93ae394d6bc2938a1c4d1d949
Parents: fd87669
Author: Wes McKinney <wes.mckinney@twosigma.com>
Authored: Sun Mar 26 11:01:14 2017 -0400
Committer: Wes McKinney <wes.mckinney@twosigma.com>
Committed: Sun Mar 26 11:01:14 2017 -0400

----------------------------------------------------------------------
 cpp/src/arrow/array.cc | 58 +++++++++++++--------------------------------
 cpp/src/arrow/array.h  | 22 +----------------
 2 files changed, 18 insertions(+), 62 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/arrow/blob/6d4e8629/cpp/src/arrow/array.cc
----------------------------------------------------------------------
diff --git a/cpp/src/arrow/array.cc b/cpp/src/arrow/array.cc
index f1c8bd4..cff0126 100644
--- a/cpp/src/arrow/array.cc
+++ b/cpp/src/arrow/array.cc
@@ -29,6 +29,7 @@
 #include "arrow/util/bit-util.h"
 #include "arrow/util/logging.h"
 #include "arrow/visitor.h"
+#include "arrow/visitor_inline.h"
 
 namespace arrow {
 
@@ -103,6 +104,10 @@ bool Array::RangeEquals(const Array& other, int64_t start_idx, int64_t
end_idx,
   return are_equal;
 }
 
+Status Array::Validate() const {
+  return Status::OK();
+}
+
 // Last two parameters are in-out parameters
 static inline void ConformSliceParams(
     int64_t array_offset, int64_t array_length, int64_t* offset, int64_t* length) {
@@ -117,10 +122,6 @@ std::shared_ptr<Array> Array::Slice(int64_t offset) const {
   return Slice(offset, slice_length);
 }
 
-Status Array::Validate() const {
-  return Status::OK();
-}
-
 NullArray::NullArray(int64_t length) : Array(null(), length, nullptr, length) {}
 
 std::shared_ptr<Array> NullArray::Slice(int64_t offset, int64_t length) const {
@@ -426,47 +427,22 @@ std::shared_ptr<Array> DictionaryArray::Slice(int64_t offset,
int64_t length) co
 }
 
 // ----------------------------------------------------------------------
-// Implement ArrayVisitor methods
-
-Status NullArray::Accept(ArrayVisitor* visitor) const {
-  return visitor->Visit(*this);
-}
+// Implement Array::Accept as inline visitor
 
-Status BooleanArray::Accept(ArrayVisitor* visitor) const {
-  return visitor->Visit(*this);
-}
+struct AcceptVirtualVisitor {
+  explicit AcceptVirtualVisitor(ArrayVisitor* visitor) : visitor(visitor) {}
 
-template <typename T>
-Status NumericArray<T>::Accept(ArrayVisitor* visitor) const {
-  return visitor->Visit(*this);
-}
+  ArrayVisitor* visitor;
 
-Status BinaryArray::Accept(ArrayVisitor* visitor) const {
-  return visitor->Visit(*this);
-}
-
-Status StringArray::Accept(ArrayVisitor* visitor) const {
-  return visitor->Visit(*this);
-}
-
-Status FixedWidthBinaryArray::Accept(ArrayVisitor* visitor) const {
-  return visitor->Visit(*this);
-}
-
-Status ListArray::Accept(ArrayVisitor* visitor) const {
-  return visitor->Visit(*this);
-}
-
-Status StructArray::Accept(ArrayVisitor* visitor) const {
-  return visitor->Visit(*this);
-}
-
-Status UnionArray::Accept(ArrayVisitor* visitor) const {
-  return visitor->Visit(*this);
-}
+  template <typename T>
+  Status Visit(const T& array) {
+    return visitor->Visit(array);
+  }
+};
 
-Status DictionaryArray::Accept(ArrayVisitor* visitor) const {
-  return visitor->Visit(*this);
+Status Array::Accept(ArrayVisitor* visitor) const {
+  AcceptVirtualVisitor inline_visitor(visitor);
+  return VisitArrayInline(*this, visitor);
 }
 
 // ----------------------------------------------------------------------

http://git-wip-us.apache.org/repos/asf/arrow/blob/6d4e8629/cpp/src/arrow/array.h
----------------------------------------------------------------------
diff --git a/cpp/src/arrow/array.h b/cpp/src/arrow/array.h
index c73b7a8..cc0cf98 100644
--- a/cpp/src/arrow/array.h
+++ b/cpp/src/arrow/array.h
@@ -110,7 +110,7 @@ class ARROW_EXPORT Array {
   /// Defaults to always returning Status::OK. This can be an expensive check.
   virtual Status Validate() const;
 
-  virtual Status Accept(ArrayVisitor* visitor) const = 0;
+  Status Accept(ArrayVisitor* visitor) const;
 
   /// Construct a zero-copy slice of the array with the indicated offset and
   /// length
@@ -151,8 +151,6 @@ class ARROW_EXPORT NullArray : public Array {
 
   explicit NullArray(int64_t length);
 
-  Status Accept(ArrayVisitor* visitor) const override;
-
   std::shared_ptr<Array> Slice(int64_t offset, int64_t length) const override;
 };
 
@@ -196,8 +194,6 @@ class ARROW_EXPORT NumericArray : public PrimitiveArray {
     return reinterpret_cast<const value_type*>(raw_data_) + offset_;
   }
 
-  Status Accept(ArrayVisitor* visitor) const override;
-
   std::shared_ptr<Array> Slice(int64_t offset, int64_t length) const override;
 
   value_type Value(int64_t i) const { return raw_data()[i]; }
@@ -213,8 +209,6 @@ class ARROW_EXPORT BooleanArray : public PrimitiveArray {
       const std::shared_ptr<Buffer>& null_bitmap = nullptr, int64_t null_count
= 0,
       int64_t offset = 0);
 
-  Status Accept(ArrayVisitor* visitor) const override;
-
   std::shared_ptr<Array> Slice(int64_t offset, int64_t length) const override;
 
   bool Value(int64_t i) const {
@@ -262,8 +256,6 @@ class ARROW_EXPORT ListArray : public Array {
     return raw_value_offsets_[i + 1] - raw_value_offsets_[i];
   }
 
-  Status Accept(ArrayVisitor* visitor) const override;
-
   std::shared_ptr<Array> Slice(int64_t offset, int64_t length) const override;
 
  protected:
@@ -313,8 +305,6 @@ class ARROW_EXPORT BinaryArray : public Array {
 
   Status Validate() const override;
 
-  Status Accept(ArrayVisitor* visitor) const override;
-
   std::shared_ptr<Array> Slice(int64_t offset, int64_t length) const override;
 
  protected:
@@ -351,8 +341,6 @@ class ARROW_EXPORT StringArray : public BinaryArray {
 
   Status Validate() const override;
 
-  Status Accept(ArrayVisitor* visitor) const override;
-
   std::shared_ptr<Array> Slice(int64_t offset, int64_t length) const override;
 };
 
@@ -379,8 +367,6 @@ class ARROW_EXPORT FixedWidthBinaryArray : public Array {
 
   const uint8_t* raw_data() const { return raw_data_; }
 
-  Status Accept(ArrayVisitor* visitor) const override;
-
   std::shared_ptr<Array> Slice(int64_t offset, int64_t length) const override;
 
  protected:
@@ -409,8 +395,6 @@ class ARROW_EXPORT StructArray : public Array {
 
   const std::vector<std::shared_ptr<Array>>& fields() const { return children_;
}
 
-  Status Accept(ArrayVisitor* visitor) const override;
-
   std::shared_ptr<Array> Slice(int64_t offset, int64_t length) const override;
 
  protected:
@@ -450,8 +434,6 @@ class ARROW_EXPORT UnionArray : public Array {
 
   const std::vector<std::shared_ptr<Array>>& children() const { return children_;
}
 
-  Status Accept(ArrayVisitor* visitor) const override;
-
   std::shared_ptr<Array> Slice(int64_t offset, int64_t length) const override;
 
  protected:
@@ -496,8 +478,6 @@ class ARROW_EXPORT DictionaryArray : public Array {
 
   const DictionaryType* dict_type() { return dict_type_; }
 
-  Status Accept(ArrayVisitor* visitor) const override;
-
   std::shared_ptr<Array> Slice(int64_t offset, int64_t length) const override;
 
  protected:


Mime
View raw message