-
Notifications
You must be signed in to change notification settings - Fork 620
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
Override clone_from
implementations for a few types
#2236
Conversation
How common is manually implementing |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's odd that derive()
does not do it, but it obviously has the potential to save an allocation. Not quite as intricate as std::vec::Vec on the dynamic image but effective.
This would avoid the allocation but potentially "leak" memory if the image started out substantially larger than the new size. (Technically not a leak because the memory would still remain referenced but inaccessible.) Though perhaps that's well known behavior and folks using the method would expect that? |
I think it's fine that |
src/dynimage.rs
Outdated
(Self::ImageRgba16(p1), Self::ImageRgba16(p2)) => p1.clone_from(p2), | ||
(Self::ImageRgb32F(p1), Self::ImageRgb32F(p2)) => p1.clone_from(p2), | ||
(Self::ImageRgba32F(p1), Self::ImageRgba32F(p2)) => p1.clone_from(p2), | ||
(this, source) => *this = source.clone(), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This match arm should be avoided. The enum is marked non-exhaustive, but within this crate we can still match exhaustively on it
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I am not sure of what you want here. Something like this ?
match (self, source) {
(Self::ImageRgb8(p1), Self::ImageRgb8(p2)) => p1.clone_from(p2),
(Self::ImageRgba8(p1), Self::ImageRgba8(p2)) => p1.clone_from(p2),
// other formats...
(this, Self::ImageRgb8(p)) => *this = Self::ImageRgb8(p.clone()),
(this, Self::ImageRgba8(p)) => this = Self::ImageRgba8(p.clone()),
// other formats...
}
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sorry, I didn't read closely. It's fine as is
0f874cf
to
eb457ab
Compare
I license past and future contributions under the dual MIT/Apache-2.0 license,
allowing licensees to choose either at their option.