comparison rust/hg-cpython/src/dirstate/non_normal_entries.rs @ 44327:71e13cfd6154 stable

rust-dirstatemap: add `NonNormalEntries` class This fix introduces the same encapsulation as the `copymap`. There is no easy way of doing this any better for now. `hg up -r null && time HGRCPATH= HGMODULEPOLICY=rust+c hg up tip` on Mozilla Central, (not super recent, but it doesn't matter): Before: 7:44,08 total After: 1:03,23 total Pretty brutal regression! This is a graft on stable of cf1f8660e568 Differential Revision: https://phab.mercurial-scm.org/D8111
author Raphaël Gomès <rgomes@octobus.net>
date Wed, 12 Feb 2020 23:23:59 +0100
parents
children 8ac5726d695d
comparison
equal deleted inserted replaced
44326:58c74a517a00 44327:71e13cfd6154
1 // non_normal_other_parent_entries.rs
2 //
3 // Copyright 2020 Raphaël Gomès <rgomes@octobus.net>
4 //
5 // This software may be used and distributed according to the terms of the
6 // GNU General Public License version 2 or any later version.
7
8 use cpython::{
9 exc::NotImplementedError, CompareOp, ObjectProtocol, PyErr, PyList,
10 PyObject, PyResult, PyString, Python, PythonObject, ToPyObject,
11 };
12
13 use crate::dirstate::DirstateMap;
14
15 py_class!(pub class NonNormalEntries |py| {
16 data dmap: DirstateMap;
17
18 def __contains__(&self, key: PyObject) -> PyResult<bool> {
19 self.dmap(py).non_normal_entries_contains(py, key)
20 }
21 def remove(&self, key: PyObject) -> PyResult<PyObject> {
22 self.dmap(py).non_normal_entries_remove(py, key)
23 }
24 def union(&self, other: PyObject) -> PyResult<PyList> {
25 self.dmap(py).non_normal_entries_union(py, other)
26 }
27 def __richcmp__(&self, other: PyObject, op: CompareOp) -> PyResult<bool> {
28 match op {
29 CompareOp::Eq => self.is_equal_to(py, other),
30 CompareOp::Ne => Ok(!self.is_equal_to(py, other)?),
31 _ => Err(PyErr::new::<NotImplementedError, _>(py, ""))
32 }
33 }
34 def __repr__(&self) -> PyResult<PyString> {
35 self.dmap(py).non_normal_entries_display(py)
36 }
37 });
38
39 impl NonNormalEntries {
40 pub fn from_inner(py: Python, dm: DirstateMap) -> PyResult<Self> {
41 Self::create_instance(py, dm)
42 }
43
44 fn is_equal_to(&self, py: Python, other: PyObject) -> PyResult<bool> {
45 for item in other.iter(py)? {
46 if !self.dmap(py).non_normal_entries_contains(py, item?)? {
47 return Ok(false);
48 }
49 }
50 Ok(true)
51 }
52 }