rust-pyo3: helper to build Python lists of revisions
It really seems that the PyO3 bindings will perform less copying
than their rust-cpython counterparts: instead of building a vector
with the results (first copy) then passing a reference to `PyList::new`,
(that therefore would have to copy again), we can pass an iterator
of the elements, as long as they have a single type (`PyRevision`) in
this case.
--- a/rust/hg-pyo3/src/revision.rs Mon Dec 23 00:17:03 2024 +0100
+++ b/rust/hg-pyo3/src/revision.rs Wed Dec 25 19:05:27 2024 +0100
@@ -1,4 +1,5 @@
use pyo3::prelude::*;
+use pyo3::types::PyList;
use hg::revlog::RevlogIndex;
use hg::{BaseRevision, Revision, UncheckedRevision};
@@ -105,3 +106,14 @@
})
.collect()
}
+
+#[allow(dead_code)]
+pub fn revs_py_list<U>(
+ py: Python<'_>,
+ revs: impl IntoIterator<Item = Revision, IntoIter = U>,
+) -> PyResult<Py<PyList>>
+where
+ U: ExactSizeIterator<Item = Revision>,
+{
+ Ok(PyList::new(py, revs.into_iter().map(PyRevision::from))?.unbind())
+}
--- a/rust/hg-pyo3/src/revlog/mod.rs Mon Dec 23 00:17:03 2024 +0100
+++ b/rust/hg-pyo3/src/revlog/mod.rs Wed Dec 25 19:05:27 2024 +0100
@@ -34,9 +34,8 @@
use crate::{
exceptions::{
- map_lock_error, map_try_lock_error,
- nodemap_error, rev_not_in_index, revlog_error_bare,
- revlog_error_from_msg,
+ map_lock_error, map_try_lock_error, nodemap_error, rev_not_in_index,
+ revlog_error_bare, revlog_error_from_msg,
},
node::{node_from_py_bytes, node_prefix_from_py_bytes, py_node_for_rev},
revision::{check_revision, PyRevision},