Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Value::update performance enhancement & simplification #521

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 2 additions & 12 deletions src/value.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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()) {
return decoder_.decode_int32(count_);
} else if (data_type_->is_tuple()) {
const CompositeType& composite_type = static_cast<const CompositeType&>(*data_type_);
count_ = composite_type.types().size();
} else if (data_type_->is_user_type()) {
const UserType& user_type = static_cast<const UserType&>(*data_type_);
count_ = user_type.fields().size();
}
} else {
count_ = 0;
if (!is_null_ && data_type_->is_collection()) {
Copy link
Contributor

@mpenick mpenick Dec 8, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Doesn't this result in an invalid count for tuples and UDTs?

return decoder_.decode_int32(count_);
}
return true;
}
Expand Down
22 changes: 5 additions & 17 deletions src/value.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -102,27 +102,15 @@ class Value {

bool is_null() const { return is_null_; }

bool is_collection() const {
if (!data_type_) return false;
return data_type_->is_collection();
}
bool is_collection() const { return data_type_ && data_type_->is_collection(); }

bool is_map() const {
if (!data_type_) return false;
return data_type_->is_map();
}
bool is_map() const { return data_type_ && data_type_->is_map(); }

bool is_tuple() const {
if (!data_type_) return false;
return data_type_->is_tuple();
}
bool is_tuple() const { return data_type_ && data_type_->is_tuple(); }

bool is_user_type() const {
if (!data_type_) return false;
return data_type_->is_user_type();
}
bool is_user_type() const { 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();
Expand Down