Mercurial > hg
annotate 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 |
rev | line source |
---|---|
44327
71e13cfd6154
rust-dirstatemap: add `NonNormalEntries` class
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
1 // non_normal_other_parent_entries.rs |
71e13cfd6154
rust-dirstatemap: add `NonNormalEntries` class
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
2 // |
71e13cfd6154
rust-dirstatemap: add `NonNormalEntries` class
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
3 // Copyright 2020 Raphaël Gomès <rgomes@octobus.net> |
71e13cfd6154
rust-dirstatemap: add `NonNormalEntries` class
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
4 // |
71e13cfd6154
rust-dirstatemap: add `NonNormalEntries` class
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
5 // This software may be used and distributed according to the terms of the |
71e13cfd6154
rust-dirstatemap: add `NonNormalEntries` class
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
6 // GNU General Public License version 2 or any later version. |
71e13cfd6154
rust-dirstatemap: add `NonNormalEntries` class
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
7 |
71e13cfd6154
rust-dirstatemap: add `NonNormalEntries` class
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
8 use cpython::{ |
71e13cfd6154
rust-dirstatemap: add `NonNormalEntries` class
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
9 exc::NotImplementedError, CompareOp, ObjectProtocol, PyErr, PyList, |
71e13cfd6154
rust-dirstatemap: add `NonNormalEntries` class
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
10 PyObject, PyResult, PyString, Python, PythonObject, ToPyObject, |
71e13cfd6154
rust-dirstatemap: add `NonNormalEntries` class
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
11 }; |
71e13cfd6154
rust-dirstatemap: add `NonNormalEntries` class
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
12 |
71e13cfd6154
rust-dirstatemap: add `NonNormalEntries` class
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
13 use crate::dirstate::DirstateMap; |
71e13cfd6154
rust-dirstatemap: add `NonNormalEntries` class
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
14 |
71e13cfd6154
rust-dirstatemap: add `NonNormalEntries` class
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
15 py_class!(pub class NonNormalEntries |py| { |
71e13cfd6154
rust-dirstatemap: add `NonNormalEntries` class
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
16 data dmap: DirstateMap; |
71e13cfd6154
rust-dirstatemap: add `NonNormalEntries` class
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
17 |
71e13cfd6154
rust-dirstatemap: add `NonNormalEntries` class
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
18 def __contains__(&self, key: PyObject) -> PyResult<bool> { |
71e13cfd6154
rust-dirstatemap: add `NonNormalEntries` class
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
19 self.dmap(py).non_normal_entries_contains(py, key) |
71e13cfd6154
rust-dirstatemap: add `NonNormalEntries` class
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
20 } |
71e13cfd6154
rust-dirstatemap: add `NonNormalEntries` class
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
21 def remove(&self, key: PyObject) -> PyResult<PyObject> { |
71e13cfd6154
rust-dirstatemap: add `NonNormalEntries` class
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
22 self.dmap(py).non_normal_entries_remove(py, key) |
71e13cfd6154
rust-dirstatemap: add `NonNormalEntries` class
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
23 } |
71e13cfd6154
rust-dirstatemap: add `NonNormalEntries` class
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
24 def union(&self, other: PyObject) -> PyResult<PyList> { |
71e13cfd6154
rust-dirstatemap: add `NonNormalEntries` class
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
25 self.dmap(py).non_normal_entries_union(py, other) |
71e13cfd6154
rust-dirstatemap: add `NonNormalEntries` class
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
26 } |
71e13cfd6154
rust-dirstatemap: add `NonNormalEntries` class
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
27 def __richcmp__(&self, other: PyObject, op: CompareOp) -> PyResult<bool> { |
71e13cfd6154
rust-dirstatemap: add `NonNormalEntries` class
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
28 match op { |
71e13cfd6154
rust-dirstatemap: add `NonNormalEntries` class
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
29 CompareOp::Eq => self.is_equal_to(py, other), |
71e13cfd6154
rust-dirstatemap: add `NonNormalEntries` class
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
30 CompareOp::Ne => Ok(!self.is_equal_to(py, other)?), |
71e13cfd6154
rust-dirstatemap: add `NonNormalEntries` class
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
31 _ => Err(PyErr::new::<NotImplementedError, _>(py, "")) |
71e13cfd6154
rust-dirstatemap: add `NonNormalEntries` class
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
32 } |
71e13cfd6154
rust-dirstatemap: add `NonNormalEntries` class
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
33 } |
71e13cfd6154
rust-dirstatemap: add `NonNormalEntries` class
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
34 def __repr__(&self) -> PyResult<PyString> { |
71e13cfd6154
rust-dirstatemap: add `NonNormalEntries` class
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
35 self.dmap(py).non_normal_entries_display(py) |
71e13cfd6154
rust-dirstatemap: add `NonNormalEntries` class
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
36 } |
71e13cfd6154
rust-dirstatemap: add `NonNormalEntries` class
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
37 }); |
71e13cfd6154
rust-dirstatemap: add `NonNormalEntries` class
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
38 |
71e13cfd6154
rust-dirstatemap: add `NonNormalEntries` class
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
39 impl NonNormalEntries { |
71e13cfd6154
rust-dirstatemap: add `NonNormalEntries` class
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
40 pub fn from_inner(py: Python, dm: DirstateMap) -> PyResult<Self> { |
71e13cfd6154
rust-dirstatemap: add `NonNormalEntries` class
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
41 Self::create_instance(py, dm) |
71e13cfd6154
rust-dirstatemap: add `NonNormalEntries` class
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
42 } |
71e13cfd6154
rust-dirstatemap: add `NonNormalEntries` class
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
43 |
71e13cfd6154
rust-dirstatemap: add `NonNormalEntries` class
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
44 fn is_equal_to(&self, py: Python, other: PyObject) -> PyResult<bool> { |
71e13cfd6154
rust-dirstatemap: add `NonNormalEntries` class
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
45 for item in other.iter(py)? { |
71e13cfd6154
rust-dirstatemap: add `NonNormalEntries` class
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
46 if !self.dmap(py).non_normal_entries_contains(py, item?)? { |
71e13cfd6154
rust-dirstatemap: add `NonNormalEntries` class
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
47 return Ok(false); |
71e13cfd6154
rust-dirstatemap: add `NonNormalEntries` class
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
48 } |
71e13cfd6154
rust-dirstatemap: add `NonNormalEntries` class
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
49 } |
71e13cfd6154
rust-dirstatemap: add `NonNormalEntries` class
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
50 Ok(true) |
71e13cfd6154
rust-dirstatemap: add `NonNormalEntries` class
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
51 } |
71e13cfd6154
rust-dirstatemap: add `NonNormalEntries` class
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
52 } |