You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Finds consecutive push or push_str operations to a String. These can be combined into a write! macro call.
Categories
Kind: perf
What is the advantage of the recommended code over the original code
More performant since the String will pre-allocate
More concise
Drawbacks
None.
Example
letmut s = String::new();
s.push('h');
s.push_str(ello);
s.push(' ');
s.push_str("world");
Could be written as:
letmut s = String::new();write!(&mut s, "h{} world", ello);
The text was updated successfully, but these errors were encountered:
camsteffen
added
A-lint
Area: New lints
E-medium
Call for participation: Medium difficulty level problem and requires some initial experience.
labels
Mar 17, 2021
camsteffen
changed the title
New Lint: Consective String push
New Lint: Consecutive String push
Mar 17, 2021
Hmm you're right. I tried fiddling with the bench and got the same results. Going to close this as it seems like write! is not really advisable in this case.
What it does
Finds consecutive
push
orpush_str
operations to aString
. These can be combined into awrite!
macro call.Categories
What is the advantage of the recommended code over the original code
String
will pre-allocateDrawbacks
None.
Example
Could be written as:
The text was updated successfully, but these errors were encountered: