Mercurial > hg
diff rust/hg-cpython/src/conversion.rs @ 43269:33fe96a5c522
rust-cpython: removed now useless py_set() conversion
In rust-cpython 0.3.0, HashSets implement the appropriate
ToPythonObject, we can therefore get rid of this hacky conversion.
There still remains an inefficiency in `MissingAncestors.bases()`:
we have to clone, because `to_py_object()` requires full ownership.
However:
- the only use case outside of unit tests used to be from
`setdiscovery.partialdiscovery` which is now fully implemented
in Rust.
- it's not worse than what `py_set()` used to do
Differential Revision: https://phab.mercurial-scm.org/D7120
author | Georges Racinet <georges.racinet@octobus.net> |
---|---|
date | Mon, 30 Sep 2019 16:31:53 -0400 |
parents | 060c030c9993 |
children | c7fb9b74e753 |
line wrap: on
line diff
--- a/rust/hg-cpython/src/conversion.rs Tue Oct 15 22:02:34 2019 -0400 +++ b/rust/hg-cpython/src/conversion.rs Mon Sep 30 16:31:53 2019 -0400 @@ -8,12 +8,8 @@ //! Bindings for the hg::ancestors module provided by the //! `hg-core` crate. From Python, this will be seen as `rustext.ancestor` -use cpython::{ - ObjectProtocol, PyDict, PyObject, PyResult, PyTuple, Python, PythonObject, - ToPyObject, -}; +use cpython::{ObjectProtocol, PyObject, PyResult, Python}; use hg::Revision; -use std::collections::HashSet; use std::iter::FromIterator; /// Utility function to convert a Python iterable into various collections @@ -30,21 +26,3 @@ .map(|r| r.and_then(|o| o.extract::<Revision>(py))) .collect() } - -/// Copy and convert an `HashSet<Revision>` in a Python set -/// -/// This will probably turn useless once `PySet` support lands in -/// `rust-cpython`. -/// -/// This builds a Python tuple, then calls Python's "set()" on it -pub fn py_set(py: Python, set: &HashSet<Revision>) -> PyResult<PyObject> { - let as_vec: Vec<PyObject> = set - .iter() - .map(|rev| rev.to_py_object(py).into_object()) - .collect(); - let as_pytuple = PyTuple::new(py, as_vec.as_slice()); - - let locals = PyDict::new(py); - locals.set_item(py, "obj", as_pytuple.to_py_object(py))?; - py.eval("set(obj)", None, Some(&locals)) -}