-
Notifications
You must be signed in to change notification settings - Fork 12.9k
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
Possible Vec::truncate improvement #76089
Comments
See #74172. |
This doesn't just improve The previous change results in an additional branch but we could still improve this if we could prevent that. |
#78884 and #74172 both attempted to fix this, but due to inlining rules it is more complex than it appears to be. Quoting scottmcm:
|
#80857 added a comment to the code with an explanation of why we're doing this. Should this be closed now? For the reasons outlined above, changing this is not planned. |
Shouldn't this be reviewed again, as |
The docs of Vec::truncate say:
"If len is greater than the vector's current length, this has no effect."
And indeed if you look at the source code:
https://doc.rust-lang.org/nightly/src/alloc/vec.rs.html#740-742
There's:
But isn't it better to use
len >= self.len
instead?The text was updated successfully, but these errors were encountered: