Mo :ferris: :tux: @ FOSDEM on Nostr: #RustLang lint idea and performance tip 🚀 Warn about a repeated call of ...
#RustLang lint idea and performance tip 🚀
Warn about a repeated call of `Path::join` ⚠️
This allocates a new `PathBuf` each time. Then `Path::join` is called on the new `PathBuf` because of the `Deref` implementation.
Instead, you should use extend like in the screenshot (preferably with a capacity hint).
You can also use `.collect::<PathBuf>()` on an iterator instead:
https://doc.rust-lang.org/stable/std/path/struct.PathBuf.html#impl-FromIterator%3CP%3E-for-PathBuf
Warn about a repeated call of `Path::join` ⚠️
This allocates a new `PathBuf` each time. Then `Path::join` is called on the new `PathBuf` because of the `Deref` implementation.
Instead, you should use extend like in the screenshot (preferably with a capacity hint).
You can also use `.collect::<PathBuf>()` on an iterator instead:
https://doc.rust-lang.org/stable/std/path/struct.PathBuf.html#impl-FromIterator%3CP%3E-for-PathBuf