-
Notifications
You must be signed in to change notification settings - Fork 1.9k
Open
Labels
A-lintArea: New lintsArea: New lintsL-perfLint: Belongs in the perf lint groupLint: Belongs in the perf lint group
Description
PathBuf comes with inherent mutating methods like push, set_extension, etc. along with methods come from Deref<Target = Path> like join, with_extension, etc.
Each usage of the latter group of methods throws current PathBuf away and creates a new one:
let mut p: PathBuf;
// bad (in terms of performance)
p
.join("x") // &PathBuf -> PathBuf
.with_extension("txt"); // &PathBuf -> PathBuf
// good
p.push("x");
p.set_extension("txt");The lint to detect this situation may be under perf, but we might as well make it pedantic since the former code looks more clean and idiomatic.
Metadata
Metadata
Assignees
Labels
A-lintArea: New lintsArea: New lintsL-perfLint: Belongs in the perf lint groupLint: Belongs in the perf lint group