refactor(tvix/glue): clone less
Prepare the NixAttr to return without an intermediate Vec<(String, NixString)>, and without into_iter(), and send off the unmoved Derivation struct to known_paths without having to clone it. Change-Id: Icdb9f78938e998a27d0313c5d9ab15b93af5821d Reviewed-on: https://cl.tvl.fyi/c/depot/+/11531 Tested-by: BuildkiteCI Autosubmit: flokli <flokli@flokli.de> Reviewed-by: edef <edef@edef.eu>
This commit is contained in:
parent
26b77b2cf3
commit
98b85b4580
1 changed files with 26 additions and 28 deletions
|
@ -474,38 +474,36 @@ pub(crate) mod derivation_builtins {
|
||||||
.calculate_derivation_path(name)
|
.calculate_derivation_path(name)
|
||||||
.map_err(DerivationError::InvalidDerivation)?;
|
.map_err(DerivationError::InvalidDerivation)?;
|
||||||
|
|
||||||
// TODO: avoid cloning
|
// Assemble the attrset to return from this builtin.
|
||||||
known_paths.add_derivation(drv_path.clone(), drv.clone());
|
let out = Value::Attrs(Box::new(NixAttrs::from_iter(
|
||||||
|
drv.outputs
|
||||||
let mut new_attrs: Vec<(String, NixString)> = drv
|
.iter()
|
||||||
.outputs
|
.map(|(name, output)| {
|
||||||
.into_iter()
|
(
|
||||||
.map(|(name, output)| {
|
name.clone(),
|
||||||
(
|
NixString::new_context_from(
|
||||||
name.clone(),
|
NixContextElement::Single {
|
||||||
|
name: name.clone(),
|
||||||
|
derivation: drv_path.to_absolute_path(),
|
||||||
|
}
|
||||||
|
.into(),
|
||||||
|
output.path.as_ref().unwrap().to_absolute_path(),
|
||||||
|
),
|
||||||
|
)
|
||||||
|
})
|
||||||
|
.chain(std::iter::once((
|
||||||
|
"drvPath".to_owned(),
|
||||||
NixString::new_context_from(
|
NixString::new_context_from(
|
||||||
NixContextElement::Single {
|
NixContextElement::Derivation(drv_path.to_absolute_path()).into(),
|
||||||
name,
|
drv_path.to_absolute_path(),
|
||||||
derivation: drv_path.to_absolute_path(),
|
|
||||||
}
|
|
||||||
.into(),
|
|
||||||
output.path.unwrap().to_absolute_path(),
|
|
||||||
),
|
),
|
||||||
)
|
))),
|
||||||
})
|
)));
|
||||||
.collect();
|
|
||||||
|
|
||||||
new_attrs.push((
|
// Register the Derivation in known_paths.
|
||||||
"drvPath".to_string(),
|
known_paths.add_derivation(drv_path, drv);
|
||||||
NixString::new_context_from(
|
|
||||||
NixContextElement::Derivation(drv_path.to_absolute_path()).into(),
|
|
||||||
drv_path.to_absolute_path(),
|
|
||||||
),
|
|
||||||
));
|
|
||||||
|
|
||||||
Ok(Value::Attrs(Box::new(NixAttrs::from_iter(
|
Ok(out)
|
||||||
new_attrs.into_iter(),
|
|
||||||
))))
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#[builtin("toFile")]
|
#[builtin("toFile")]
|
||||||
|
|
Loading…
Reference in a new issue