mo8it ,
@mo8it@fosstodon.org avatar

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

rust let mut sysroot_src = PathBuf::with_capacity(256); sysroot_src.extend([toolchain, "lib", "rustlib", "src", "rust", "library"]);

  • All
  • Subscribed
  • Moderated
  • Favorites
  • random
  • test
  • worldmews
  • mews
  • All magazines