[dice] Optimize iteration handling in dice::execute_steps
To avoid unnecessary vector collect in the process.
Bug: 267575445
Test: atest diced_utils_test diced_sample_inputs_test \
diced_test diced_vendor_test
Change-Id: I5b78dad7394e6ca88e238ef5806dd574da083657
diff --git a/diced/src/utils.rs b/diced/src/utils.rs
index 3cb4ba2..da39f8f 100644
--- a/diced/src/utils.rs
+++ b/diced/src/utils.rs
@@ -153,7 +153,7 @@
(cdi_attest, cdi_seal, bcc)
}
- fn execute_step(self, input_values: &dyn dice::InputValues) -> Result<Self> {
+ fn execute_step(self, input_values: InputValues) -> Result<Self> {
let ResidentArtifacts { cdi_attest, cdi_seal, bcc } = self;
let (cdi_attest, cdi_seal, bcc) = dice::OpenDiceCborContext::new()
@@ -165,7 +165,7 @@
format!("Trying to convert cdi_seal. (length: {})", cdi_seal.len())
})?,
&bcc,
- input_values,
+ &input_values,
)
.context("In ResidentArtifacts::execute_step:")?;
Ok(ResidentArtifacts { cdi_attest, cdi_seal, bcc })
@@ -173,13 +173,14 @@
/// Iterate through the iterator of dice input values performing one
/// BCC main flow step on each element.
- pub fn execute_steps<'a, Iter>(self, input_values: Iter) -> Result<Self>
+ pub fn execute_steps<'a, T, I>(self, input_values: I) -> Result<Self>
where
- Iter: IntoIterator<Item = &'a dyn dice::InputValues>,
+ T: Into<InputValues<'a>>,
+ I: IntoIterator<Item = T>,
{
input_values
.into_iter()
- .try_fold(self, |acc, input_values| acc.execute_step(input_values))
+ .try_fold(self, |acc, input| acc.execute_step(input.into()))
.context("In ResidentArtifacts::execute_step:")
}
}