From a7484ecf7933ed70158d25e34c722cfc4b2943cb Mon Sep 17 00:00:00 2001 From: Alex Revetchi Date: Mon, 8 Nov 2021 15:32:41 +0000 Subject: [PATCH 1/3] - reduce branching in Value::update and is_(type) functions --- src/value.cpp | 12 +----------- src/value.hpp | 14 +++++--------- 2 files changed, 6 insertions(+), 20 deletions(-) diff --git a/src/value.cpp b/src/value.cpp index afff4a7f1..bdb2d51dc 100644 --- a/src/value.cpp +++ b/src/value.cpp @@ -210,18 +210,8 @@ Value::Value(const DataType::ConstPtr& data_type, Decoder decoder) bool Value::update(const Decoder& decoder) { decoder_ = decoder; is_null_ = decoder_.is_null(); - if (!is_null_) { - if (data_type_->is_collection()) { + if (!is_null_ && data_type_->is_collection()) { return decoder_.decode_int32(count_); - } else if (data_type_->is_tuple()) { - const CompositeType& composite_type = static_cast(*data_type_); - count_ = composite_type.types().size(); - } else if (data_type_->is_user_type()) { - const UserType& user_type = static_cast(*data_type_); - count_ = user_type.fields().size(); - } - } else { - count_ = 0; } return true; } diff --git a/src/value.hpp b/src/value.hpp index 109a677a5..92c87d7b2 100644 --- a/src/value.hpp +++ b/src/value.hpp @@ -103,26 +103,22 @@ class Value { bool is_null() const { return is_null_; } bool is_collection() const { - if (!data_type_) return false; - return data_type_->is_collection(); + return data_type_ && data_type_->is_collection(); } bool is_map() const { - if (!data_type_) return false; - return data_type_->is_map(); + return data_type_ && data_type_->is_map(); } bool is_tuple() const { - if (!data_type_) return false; - return data_type_->is_tuple(); + return data_type_ && data_type_->is_tuple(); } bool is_user_type() const { - if (!data_type_) return false; - return data_type_->is_user_type(); + return data_type_ && data_type_->is_user_type(); } - int32_t count() const { return count_; } + int32_t count() const { return count_ * is_null_; } StringRef to_string_ref() const { if (is_null()) return StringRef(); From 4ef33e5f92625621f278776083fa3ee1df2e834d Mon Sep 17 00:00:00 2001 From: Alex Revetchi Date: Mon, 8 Nov 2021 17:48:33 +0000 Subject: [PATCH 2/3] - fix typo --- src/value.hpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/value.hpp b/src/value.hpp index 92c87d7b2..e6ca801ba 100644 --- a/src/value.hpp +++ b/src/value.hpp @@ -118,7 +118,7 @@ class Value { return data_type_ && data_type_->is_user_type(); } - int32_t count() const { return count_ * is_null_; } + int32_t count() const { return count_ * !is_null_; } StringRef to_string_ref() const { if (is_null()) return StringRef(); From b7fdcf524c4a619bff66a154e7faee03fba28338 Mon Sep 17 00:00:00 2001 From: Alex Revetchi Date: Sun, 21 Nov 2021 12:56:12 +0000 Subject: [PATCH 3/3] - apply make format --- src/value.cpp | 2 +- src/value.hpp | 16 ++++------------ 2 files changed, 5 insertions(+), 13 deletions(-) diff --git a/src/value.cpp b/src/value.cpp index bdb2d51dc..c8a2239b4 100644 --- a/src/value.cpp +++ b/src/value.cpp @@ -211,7 +211,7 @@ bool Value::update(const Decoder& decoder) { decoder_ = decoder; is_null_ = decoder_.is_null(); if (!is_null_ && data_type_->is_collection()) { - return decoder_.decode_int32(count_); + return decoder_.decode_int32(count_); } return true; } diff --git a/src/value.hpp b/src/value.hpp index e6ca801ba..5145cea0f 100644 --- a/src/value.hpp +++ b/src/value.hpp @@ -102,21 +102,13 @@ class Value { bool is_null() const { return is_null_; } - bool is_collection() const { - return data_type_ && data_type_->is_collection(); - } + bool is_collection() const { return data_type_ && data_type_->is_collection(); } - bool is_map() const { - return data_type_ && data_type_->is_map(); - } + bool is_map() const { return data_type_ && data_type_->is_map(); } - bool is_tuple() const { - return data_type_ && data_type_->is_tuple(); - } + bool is_tuple() const { return data_type_ && data_type_->is_tuple(); } - bool is_user_type() const { - return data_type_ && data_type_->is_user_type(); - } + bool is_user_type() const { return data_type_ && data_type_->is_user_type(); } int32_t count() const { return count_ * !is_null_; }