-
Notifications
You must be signed in to change notification settings - Fork 52
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
improve clone impl as per https://github.com/Lokathor/tinyvec/issues/143 #144
Conversation
|
I wonder if a fast path for Edit: something like |
Best as I understand, this is improving the situation in some but not all situations. If this code is bad for a particular copy type, then it was previously also bad for that type. EDIT: but i'm not generally familiar with when clone_from vs clone is called. |
for (dst, src) in iter { | ||
dst.clone_from(src) | ||
} | ||
self.len = o.len; |
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.
Might want to take-and-drop all the elements from o.len..self.len
.
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.
Just remember to skip this part if o.len >= self.len
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.
If I follow you right, we'd want to have something like:
if o.len < self.len {
self[o.len..].iter_mut().for_each(|r| take(r));
}
immediately after the for loop?
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.
if let Some(to_drop) = self.data.get_mut(o.len() .. self.len()) {
to_drop.for_each(|x| take(x));
}
we don't have deref for the A so we have to keep using as_slice_mut and such
Clone
uses the naive (default) version of Clone::clone_from. #143