From 3917b605ef1851ad036fb62856efcc83e32f8580 Mon Sep 17 00:00:00 2001 From: mwish Date: Thu, 31 Oct 2024 11:50:09 +0800 Subject: [PATCH] GH-44581: [C++] Minor: ArrayData ctor can assign null_count directly (#44582) ### Rationale for this change See https://godbolt.org/z/37reoKTfK The `ArrayData` ctor can assign `null_count` directly, rather than `SetNullCount`. ### What changes are included in this PR? Change `null_count` assigned directly ### Are these changes tested? Covered by existing ### Are there any user-facing changes? No * GitHub Issue: #44581 Authored-by: mwish Signed-off-by: mwish --- cpp/src/arrow/array/data.h | 14 ++++++-------- cpp/src/arrow/extension_type.h | 2 +- 2 files changed, 7 insertions(+), 9 deletions(-) diff --git a/cpp/src/arrow/array/data.h b/cpp/src/arrow/array/data.h index 1e6ee9a1d32ff..eed7860a9f703 100644 --- a/cpp/src/arrow/array/data.h +++ b/cpp/src/arrow/array/data.h @@ -150,25 +150,23 @@ struct ARROW_EXPORT ArrayData { ArrayData(ArrayData&& other) noexcept : type(std::move(other.type)), length(other.length), + null_count(other.null_count.load()), offset(other.offset), buffers(std::move(other.buffers)), child_data(std::move(other.child_data)), dictionary(std::move(other.dictionary)), - statistics(std::move(other.statistics)) { - SetNullCount(other.null_count); - } + statistics(std::move(other.statistics)) {} // Copy constructor ArrayData(const ArrayData& other) noexcept : type(other.type), length(other.length), + null_count(other.null_count.load()), offset(other.offset), buffers(other.buffers), child_data(other.child_data), dictionary(other.dictionary), - statistics(other.statistics) { - SetNullCount(other.null_count); - } + statistics(other.statistics) {} // Move assignment ArrayData& operator=(ArrayData&& other) { @@ -324,7 +322,7 @@ struct ARROW_EXPORT ArrayData { /// \brief Return true if the validity bitmap may have 0's in it, or if the /// child arrays (in the case of types without a validity bitmap) may have - /// nulls, or if the dictionary of dictionay array may have nulls. + /// nulls, or if the dictionary of dictionary array may have nulls. /// /// This is not a drop-in replacement for MayHaveNulls, as historically /// MayHaveNulls() has been used to check for the presence of a validity @@ -639,7 +637,7 @@ struct ARROW_EXPORT ArraySpan { bool HasVariadicBuffers() const; private: - ARROW_FRIEND_EXPORT friend bool internal::IsNullRunEndEncoded(const ArrayData& span, + ARROW_FRIEND_EXPORT friend bool internal::IsNullRunEndEncoded(const ArrayData& data, int64_t i); bool IsNullSparseUnion(int64_t i) const; diff --git a/cpp/src/arrow/extension_type.h b/cpp/src/arrow/extension_type.h index b3f085198be69..38200f42c62e8 100644 --- a/cpp/src/arrow/extension_type.h +++ b/cpp/src/arrow/extension_type.h @@ -98,7 +98,7 @@ class ARROW_EXPORT ExtensionType : public DataType { protected: explicit ExtensionType(std::shared_ptr storage_type) - : DataType(Type::EXTENSION), storage_type_(storage_type) {} + : DataType(Type::EXTENSION), storage_type_(std::move(storage_type)) {} std::shared_ptr storage_type_; };