Skip to content

Commit

Permalink
Avoid allocating a Vec -- directly create a list (#10217)
Browse files Browse the repository at this point in the history
  • Loading branch information
alex authored Jan 21, 2024
1 parent 39e3011 commit 8d3b4b5
Showing 1 changed file with 8 additions and 4 deletions.
12 changes: 8 additions & 4 deletions src/rust/src/x509/verify.rs
Original file line number Diff line number Diff line change
Expand Up @@ -211,12 +211,12 @@ impl PyServerVerifier {
self.as_policy().max_chain_depth
}

fn verify(
fn verify<'p>(
&self,
py: pyo3::Python<'_>,
py: pyo3::Python<'p>,
leaf: pyo3::Py<PyCertificate>,
intermediates: Vec<pyo3::Py<PyCertificate>>,
) -> CryptographyResult<Vec<pyo3::Py<PyCertificate>>> {
) -> CryptographyResult<&'p pyo3::types::PyList> {
let policy = self.as_policy();
let store = self.store.get();

Expand All @@ -236,7 +236,11 @@ impl PyServerVerifier {
)
.map_err(|e| VerificationError::new_err(format!("validation failed: {e:?}")))?;

Ok(chain.iter().map(|c| c.extra().clone_ref(py)).collect())
let result = pyo3::types::PyList::empty(py);
for c in chain {
result.append(c.extra())?;
}
Ok(result)
}
}

Expand Down

0 comments on commit 8d3b4b5

Please sign in to comment.