comparison rust/hg-cpython/src/dagops.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 326fdce22fb2
children f98f0e3ddaa1
comparison
equal deleted inserted replaced
43268:e88549a02f5e 43269:33fe96a5c522
8 //! Bindings for the `hg::dagops` module provided by the 8 //! Bindings for the `hg::dagops` module provided by the
9 //! `hg-core` package. 9 //! `hg-core` package.
10 //! 10 //!
11 //! From Python, this will be seen as `mercurial.rustext.dagop` 11 //! From Python, this will be seen as `mercurial.rustext.dagop`
12 use crate::{ 12 use crate::{
13 cindex::Index, 13 cindex::Index, conversion::rev_pyiter_collect, exceptions::GraphError,
14 conversion::{py_set, rev_pyiter_collect},
15 exceptions::GraphError,
16 }; 14 };
17 use cpython::{PyDict, PyModule, PyObject, PyResult, Python}; 15 use cpython::{PyDict, PyModule, PyObject, PyResult, Python};
18 use hg::dagops; 16 use hg::dagops;
19 use hg::Revision; 17 use hg::Revision;
20 use std::collections::HashSet; 18 use std::collections::HashSet;
24 /// This is the Rust counterpart for `mercurial.dagop.headrevs` 22 /// This is the Rust counterpart for `mercurial.dagop.headrevs`
25 pub fn headrevs( 23 pub fn headrevs(
26 py: Python, 24 py: Python,
27 index: PyObject, 25 index: PyObject,
28 revs: PyObject, 26 revs: PyObject,
29 ) -> PyResult<PyObject> { 27 ) -> PyResult<HashSet<Revision>> {
30 let mut as_set: HashSet<Revision> = rev_pyiter_collect(py, &revs)?; 28 let mut as_set: HashSet<Revision> = rev_pyiter_collect(py, &revs)?;
31 dagops::retain_heads(&Index::new(py, index)?, &mut as_set) 29 dagops::retain_heads(&Index::new(py, index)?, &mut as_set)
32 .map_err(|e| GraphError::pynew(py, e))?; 30 .map_err(|e| GraphError::pynew(py, e))?;
33 py_set(py, &as_set) 31 Ok(as_set)
34 } 32 }
35 33
36 /// Create the module, with `__package__` given from parent 34 /// Create the module, with `__package__` given from parent
37 pub fn init_module(py: Python, package: &str) -> PyResult<PyModule> { 35 pub fn init_module(py: Python, package: &str) -> PyResult<PyModule> {
38 let dotted_name = &format!("{}.dagop", package); 36 let dotted_name = &format!("{}.dagop", package);