-
Notifications
You must be signed in to change notification settings - Fork 1.5k
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
Performance: Suggest String::new() over "".to_string() #2972
Comments
The lint should probably also catch
|
as well as |
Hm, interestingly, when looking in godbolt |
Probably because |
I vote for The suggestions of
Should this lint be written as |
We should just fix this in liballoc instead. |
That seems like a preferable solution. If the allocation is fixed, this could still be a style lint. |
For people who aren't aware: It appears that the issue has been fixed. This is my test result on an Intel Mac:
|
Thank you for the benchmarks! Even if this no longer affects performance, I think having a lint that suggest |
|
I was considering if this should be a |
I'd be curious what their rationale is. It's less clear, up until recently it was slower, and it's one character longer (even if that's probably an insignificant difference). I regularly have my code "broken" by new Clippy lints being introduced that I have to admit are correct, and then I have to fix them. The purpose of linters is to guide people to write better code; I think adjusting the linter to the questionable but maybe somewhat common choices of style is backwards. If one disagrees with the lint, it can still be turned off, so there's no real risk in warning by default. |
@rustbot claim |
From rust-lang/rust#52805 (comment).
String::new()
is faster than""::to_string()
Benchmark:
The text was updated successfully, but these errors were encountered: