Reblogged by rust@octodon.social ("Rust tips"):
mo8it@fosstodon.org ("Mo :ferris: :tux:") wrote:
#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::()` on an iterator instead:
https://doc.rust-lang.org/stable/std/path/struct.PathBuf.html#impl-FromIterator%3CP%3E-for-PathBuf