From 8d3b4b57bfce99b7103017d1b5ce9e9bfe2ebb9a Mon Sep 17 00:00:00 2001 From: Alex Gaynor Date: Sun, 21 Jan 2024 05:40:11 -0500 Subject: [PATCH] Avoid allocating a Vec -- directly create a list (#10217) --- src/rust/src/x509/verify.rs | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/src/rust/src/x509/verify.rs b/src/rust/src/x509/verify.rs index 74f28e46b..8cd9cfdf9 100644 --- a/src/rust/src/x509/verify.rs +++ b/src/rust/src/x509/verify.rs @@ -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, intermediates: Vec>, - ) -> CryptographyResult>> { + ) -> CryptographyResult<&'p pyo3::types::PyList> { let policy = self.as_policy(); let store = self.store.get(); @@ -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) } }