mo8it , ![]()
#RustLang lint idea and performance tip 🚀
Warn about a repeated call of
Path::join
⚠️This allocates a new
PathBuf
each time. ThenPath::join
is called on the newPathBuf
because of theDeref
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