Skip to content

Commit d17455a

Browse files
committed
refactor(gctx): cow so includes dont need clone to own data
1 parent ecca268 commit d17455a

File tree

1 file changed

+7
-9
lines changed

1 file changed

+7
-9
lines changed

src/cargo/util/context/mod.rs

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1381,31 +1381,29 @@ impl GlobalContext {
13811381
cv: &mut CV,
13821382
remove: bool,
13831383
) -> CargoResult<Vec<(String, PathBuf, Definition)>> {
1384-
let abs = |path: &str, def: &Definition| -> (String, PathBuf, Definition) {
1385-
let abs_path = match def {
1384+
let abs = |path, def| -> (String, PathBuf, Definition) {
1385+
let abs_path = match &def {
13861386
Definition::Path(p) | Definition::Cli(Some(p)) => p.parent().unwrap().join(&path),
13871387
Definition::Environment(_) | Definition::Cli(None) | Definition::BuiltIn => {
13881388
self.cwd().join(&path)
13891389
}
13901390
};
1391-
(path.to_string(), abs_path, def.clone())
1391+
(path, abs_path, def)
13921392
};
13931393
let CV::Table(table, _def) = cv else {
13941394
unreachable!()
13951395
};
1396-
let owned;
13971396
let include = if remove {
1398-
owned = table.remove("include");
1399-
owned.as_ref()
1397+
table.remove("include").map(Cow::Owned)
14001398
} else {
1401-
table.get("include")
1399+
table.get("include").map(Cow::Borrowed)
14021400
};
1403-
let includes = match include {
1401+
let includes = match include.map(|c| c.into_owned()) {
14041402
Some(CV::String(s, def)) => {
14051403
vec![abs(s, def)]
14061404
}
14071405
Some(CV::List(list, _def)) => list
1408-
.iter()
1406+
.into_iter()
14091407
.map(|cv| match cv {
14101408
CV::String(s, def) => Ok(abs(s, def)),
14111409
other => bail!(

0 commit comments

Comments
 (0)