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

Simplify move constructors. #5409

Merged
merged 2 commits into from
Jan 7, 2025
Merged
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
6 changes: 1 addition & 5 deletions tiledb/sm/filter/filter_buffer.cc
Original file line number Diff line number Diff line change
Expand Up @@ -55,11 +55,7 @@ FilterBuffer::BufferOrView::BufferOrView(
tdb_new(Buffer, (char*)buffer->data() + offset, nbytes));
}

FilterBuffer::BufferOrView::BufferOrView(BufferOrView&& other) {
underlying_buffer_.swap(other.underlying_buffer_);
view_.swap(other.view_);
std::swap(is_view_, other.is_view_);
Copy link
Member Author

Choose a reason for hiding this comment

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

We were accessing is_view_ while unititialized. A default move constructor suffices here.

}
FilterBuffer::BufferOrView::BufferOrView(BufferOrView&& other) = default;

Buffer* FilterBuffer::BufferOrView::buffer() const {
return is_view_ ? view_.get() : underlying_buffer_.get();
Expand Down
2 changes: 1 addition & 1 deletion tiledb/sm/filter/filter_buffer.h
Original file line number Diff line number Diff line change
Expand Up @@ -339,7 +339,7 @@ class FilterBuffer {
shared_ptr<Buffer> underlying_buffer_;

/** True if this instance is a view on the underlying buffer. */
bool is_view_{false};
bool is_view_;
Copy link
Member Author

Choose a reason for hiding this comment

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

is_view_ (and FilterPipeline::max_chunk_size_) are always initialized by the constructors, so this is not necessary. And if they ever don't, the compiler will warn-as-error again.


/**
* If this instance is a view, the view Buffer (which does not own its
Expand Down
11 changes: 4 additions & 7 deletions tiledb/sm/filter/filter_pipeline.cc
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,8 @@ FilterPipeline::FilterPipeline(
, max_chunk_size_(max_chunk_size) {
}

// Unlike move constructors, copy constructors must not use default,
// because individual filters are being copied by calling clone.
FilterPipeline::FilterPipeline(const FilterPipeline& other) {
for (auto& filter : other.filters_) {
add_filter(*filter);
Expand All @@ -85,9 +87,7 @@ FilterPipeline::FilterPipeline(
max_chunk_size_ = other.max_chunk_size_;
}

FilterPipeline::FilterPipeline(FilterPipeline&& other) {
swap(other);
Copy link
Member Author

Choose a reason for hiding this comment

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

Same problem as before. The compiler looked through swap and saw uninitialized member access.

}
FilterPipeline::FilterPipeline(FilterPipeline&& other) = default;

FilterPipeline& FilterPipeline::operator=(const FilterPipeline& other) {
// Call copy constructor
Expand All @@ -97,10 +97,7 @@ FilterPipeline& FilterPipeline::operator=(const FilterPipeline& other) {
return *this;
}

FilterPipeline& FilterPipeline::operator=(FilterPipeline&& other) {
swap(other);
return *this;
}
FilterPipeline& FilterPipeline::operator=(FilterPipeline&& other) = default;

void FilterPipeline::add_filter(const Filter& filter) {
shared_ptr<Filter> copy(filter.clone());
Expand Down
2 changes: 1 addition & 1 deletion tiledb/sm/filter/filter_pipeline.h
Original file line number Diff line number Diff line change
Expand Up @@ -323,7 +323,7 @@ class FilterPipeline {
std::vector<shared_ptr<Filter>> filters_;

/** The max chunk size allowed within tiles. */
uint32_t max_chunk_size_{0};
uint32_t max_chunk_size_;

/**
* Get the chunk offsets for a var sized tile so that integral cells are
Expand Down
Loading