Mercurial > hg
changeset 51263:5b4995b40db0
rust-index: cache the head nodeids python list
Same optimization as before, but for the nodeids this time.
author | Raphaël Gomès <rgomes@octobus.net> |
---|---|
date | Wed, 06 Dec 2023 11:04:18 +0100 |
parents | f20c4b307a5a |
children | 47a34afda7ad |
files | rust/hg-cpython/src/revlog.rs |
diffstat | 1 files changed, 33 insertions(+), 4 deletions(-) [+] |
line wrap: on
line diff
--- a/rust/hg-cpython/src/revlog.rs Tue Dec 05 14:50:05 2023 +0100 +++ b/rust/hg-cpython/src/revlog.rs Wed Dec 06 11:04:18 2023 +0100 @@ -97,6 +97,7 @@ // Holds a reference to the mmap'ed persistent index data data index_mmap: RefCell<Option<PyBuffer>>; data head_revs_py_list: RefCell<Option<PyList>>; + data head_node_ids_py_list: RefCell<Option<PyList>>; def __new__( _cls, @@ -259,6 +260,7 @@ self.docket(py).borrow_mut().take(); self.nodemap_mmap(py).borrow_mut().take(); self.head_revs_py_list(py).borrow_mut().take(); + self.head_node_ids_py_list(py).borrow_mut().take(); self.index(py).borrow().clear_caches(); Ok(py.None()) } @@ -630,6 +632,7 @@ RefCell::new(None), RefCell::new(Some(buf)), RefCell::new(None), + RefCell::new(None), ) } @@ -801,7 +804,8 @@ }) .collect(); - self.cache_new_heads_py_list(head_revs, py); + self.cache_new_heads_py_list(&head_revs, py); + self.cache_new_heads_node_ids_py_list(&head_revs, py); Ok(PyList::new(py, &res).into_object()) } @@ -811,7 +815,7 @@ if let Some(new_heads) = index.head_revs_shortcut().map_err(|e| graph_error(py, e))? { - self.cache_new_heads_py_list(new_heads, py); + self.cache_new_heads_py_list(&new_heads, py); } Ok(self @@ -835,7 +839,7 @@ .head_revs_filtered(&filtered_revs, true) .map_err(|e| graph_error(py, e))? { - self.cache_new_heads_py_list(new_heads, py); + self.cache_new_heads_py_list(&new_heads, py); } Ok(self @@ -847,9 +851,34 @@ .into_object()) } + fn cache_new_heads_node_ids_py_list( + &self, + new_heads: &[Revision], + py: Python<'_>, + ) -> PyList { + let index = self.index(py).borrow(); + let as_vec: Vec<PyObject> = new_heads + .iter() + .map(|r| { + PyBytes::new( + py, + index + .node(*r) + .expect("rev should have been in the index") + .as_bytes(), + ) + .into_object() + }) + .collect(); + let new_heads_py_list = PyList::new(py, &as_vec); + *self.head_node_ids_py_list(py).borrow_mut() = + Some(new_heads_py_list.clone_ref(py)); + new_heads_py_list + } + fn cache_new_heads_py_list( &self, - new_heads: Vec<Revision>, + new_heads: &[Revision], py: Python<'_>, ) -> PyList { let as_vec: Vec<PyObject> = new_heads