Mercurial > public > mercurial-scm > hg-stable
diff rust/hg-cpython/src/revlog.rs @ 47894:aa88fb60ecb4 stable
rust-nodemap: backed out mitigation for issue 6554
This is a backout of changeset 3fffb48539ee.
Issue 6554 is now considered solved, hence its mitigation
has to be removed, if only for its performance cost.
Differential Revision: https://phab.mercurial-scm.org/D11703
author | Georges Racinet <georges.racinet@octobus.net> |
---|---|
date | Tue, 19 Oct 2021 19:05:41 +0200 |
parents | 3fffb48539ee |
children | 455fce57e89e |
line wrap: on
line diff
--- a/rust/hg-cpython/src/revlog.rs Mon Oct 18 17:11:48 2021 +0200 +++ b/rust/hg-cpython/src/revlog.rs Tue Oct 19 19:05:41 2021 +0200 @@ -59,22 +59,12 @@ /// Return Revision if found, raises a bare `error.RevlogError` /// in case of ambiguity, same as C version does - def get_rev(&self, pynode: PyBytes) -> PyResult<Option<Revision>> { + def get_rev(&self, node: PyBytes) -> PyResult<Option<Revision>> { let opt = self.get_nodetree(py)?.borrow(); let nt = opt.as_ref().unwrap(); let idx = &*self.cindex(py).borrow(); - let node = node_from_py_bytes(py, &pynode)?; - match nt.find_bin(idx, node.into()) - { - Ok(None) => - // fallback to C implementation, remove once - // https://bz.mercurial-scm.org/show_bug.cgi?id=6554 - // is fixed (a simple backout should do) - self.call_cindex(py, "get_rev", &PyTuple::new(py, &[pynode.into_object()]), None)? - .extract(py), - Ok(Some(rev)) => Ok(Some(rev)), - Err(e) => Err(nodemap_error(py, e)), - } + let node = node_from_py_bytes(py, &node)?; + nt.find_bin(idx, node.into()).map_err(|e| nodemap_error(py, e)) } /// same as `get_rev()` but raises a bare `error.RevlogError` if node @@ -104,34 +94,27 @@ } } - def partialmatch(&self, pynode: PyObject) -> PyResult<Option<PyBytes>> { + def partialmatch(&self, node: PyObject) -> PyResult<Option<PyBytes>> { let opt = self.get_nodetree(py)?.borrow(); let nt = opt.as_ref().unwrap(); let idx = &*self.cindex(py).borrow(); let node_as_string = if cfg!(feature = "python3-sys") { - pynode.cast_as::<PyString>(py)?.to_string(py)?.to_string() + node.cast_as::<PyString>(py)?.to_string(py)?.to_string() } else { - let node = pynode.extract::<PyBytes>(py)?; + let node = node.extract::<PyBytes>(py)?; String::from_utf8_lossy(node.data(py)).to_string() }; let prefix = NodePrefix::from_hex(&node_as_string).map_err(|_| PyErr::new::<ValueError, _>(py, "Invalid node or prefix"))?; - match nt.find_bin(idx, prefix) { - Ok(None) => - // fallback to C implementation, remove once - // https://bz.mercurial-scm.org/show_bug.cgi?id=6554 - // is fixed (a simple backout should do) - self.call_cindex( - py, "partialmatch", - &PyTuple::new(py, &[pynode]), None - )?.extract(py), - Ok(Some(rev)) => - Ok(Some(PyBytes::new(py, idx.node(rev).unwrap().as_bytes()))), - Err(e) => Err(nodemap_error(py, e)), - } + nt.find_bin(idx, prefix) + // TODO make an inner API returning the node directly + .map(|opt| opt.map( + |rev| PyBytes::new(py, idx.node(rev).unwrap().as_bytes()))) + .map_err(|e| nodemap_error(py, e)) + } /// append an index entry