# HG changeset patch # User Simon Sapin # Date 2021-04-08 12:38:27 # Node ID c6ceb5f27f97ea3cb4d1e01fa811dbd1be3238f1 # Parent 441024b279a635f3bf9bd0e857c8e346abb48d98 rust: Remove use of `py.eval()` The previous Rust code allocated an intermediate `Vec`, converted that to a Python list, then used `eval` to run Python code that converts that list to a Python set. rust-cpython exposes Rust bindings for Python sets, let’s use that instead to construct a set directly. Differential Revision: https://phab.mercurial-scm.org/D10328 diff --git a/rust/hg-cpython/src/dirstate/dirstate_map.rs b/rust/hg-cpython/src/dirstate/dirstate_map.rs --- a/rust/hg-cpython/src/dirstate/dirstate_map.rs +++ b/rust/hg-cpython/src/dirstate/dirstate_map.rs @@ -14,8 +14,8 @@ use std::time::Duration; use cpython::{ exc, ObjectProtocol, PyBool, PyBytes, PyClone, PyDict, PyErr, PyList, - PyObject, PyResult, PyString, PyTuple, Python, PythonObject, ToPyObject, - UnsafePyLeaked, + PyObject, PyResult, PySet, PyString, PyTuple, Python, PythonObject, + ToPyObject, UnsafePyLeaked, }; use crate::{ @@ -175,18 +175,11 @@ py_class!(pub class DirstateMap |py| { let (_, other_parent) = inner_shared.get_non_normal_other_parent_entries(); - let locals = PyDict::new(py); - locals.set_item( - py, - "other_parent", - other_parent - .iter() - .map(|v| PyBytes::new(py, v.as_bytes())) - .collect::>() - .to_py_object(py), - )?; - - py.eval("set(other_parent)", None, Some(&locals)) + let set = PySet::empty(py)?; + for path in other_parent.iter() { + set.add(py, PyBytes::new(py, path.as_bytes()))?; + } + Ok(set.into_object()) } def non_normal_entries(&self) -> PyResult {