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

Simplify move constructors. #5409

merged 2 commits into from
Jan 7, 2025

Conversation

teo-tsirpanis
Copy link
Member

@teo-tsirpanis teo-tsirpanis commented Dec 17, 2024

Partially reverts #5412.


TYPE: NO_HISTORY

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.

@@ -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.

@teo-tsirpanis

This comment was marked as outdated.

@@ -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.

@teo-tsirpanis teo-tsirpanis changed the title Fix warnings-as-errors. Simplify move constructors. Jan 2, 2025
@teo-tsirpanis teo-tsirpanis marked this pull request as ready for review January 2, 2025 17:57
@teo-tsirpanis teo-tsirpanis requested a review from dudoslav January 2, 2025 17:57
@dudoslav
Copy link
Collaborator

dudoslav commented Jan 3, 2025

LGTM, but one thing comes to my mind:

is_view_ will never change during the lifetime of the object? If so, can it be made const? (I just skimmed through the code, so I am not sure if it cannot change).

@teo-tsirpanis
Copy link
Member Author

It wouldn't have much benefit in this case, since all methods in BufferOrView are const-qualified.

@teo-tsirpanis teo-tsirpanis merged commit 468046c into main Jan 7, 2025
64 of 65 checks passed
@teo-tsirpanis teo-tsirpanis deleted the teo/fix-werrors branch January 7, 2025 12:51
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants