##// END OF EJS Templates
rust-index: cache the head nodeids python list...
Raphaël Gomès -
r52156:5b4995b4 default
parent child Browse files
Show More
@@ -97,6 +97,7 b' py_class!(pub class Index |py| {'
97 // Holds a reference to the mmap'ed persistent index data
97 // Holds a reference to the mmap'ed persistent index data
98 data index_mmap: RefCell<Option<PyBuffer>>;
98 data index_mmap: RefCell<Option<PyBuffer>>;
99 data head_revs_py_list: RefCell<Option<PyList>>;
99 data head_revs_py_list: RefCell<Option<PyList>>;
100 data head_node_ids_py_list: RefCell<Option<PyList>>;
100
101
101 def __new__(
102 def __new__(
102 _cls,
103 _cls,
@@ -259,6 +260,7 b' py_class!(pub class Index |py| {'
259 self.docket(py).borrow_mut().take();
260 self.docket(py).borrow_mut().take();
260 self.nodemap_mmap(py).borrow_mut().take();
261 self.nodemap_mmap(py).borrow_mut().take();
261 self.head_revs_py_list(py).borrow_mut().take();
262 self.head_revs_py_list(py).borrow_mut().take();
263 self.head_node_ids_py_list(py).borrow_mut().take();
262 self.index(py).borrow().clear_caches();
264 self.index(py).borrow().clear_caches();
263 Ok(py.None())
265 Ok(py.None())
264 }
266 }
@@ -630,6 +632,7 b' impl Index {'
630 RefCell::new(None),
632 RefCell::new(None),
631 RefCell::new(Some(buf)),
633 RefCell::new(Some(buf)),
632 RefCell::new(None),
634 RefCell::new(None),
635 RefCell::new(None),
633 )
636 )
634 }
637 }
635
638
@@ -801,7 +804,8 b' impl Index {'
801 })
804 })
802 .collect();
805 .collect();
803
806
804 self.cache_new_heads_py_list(head_revs, py);
807 self.cache_new_heads_py_list(&head_revs, py);
808 self.cache_new_heads_node_ids_py_list(&head_revs, py);
805
809
806 Ok(PyList::new(py, &res).into_object())
810 Ok(PyList::new(py, &res).into_object())
807 }
811 }
@@ -811,7 +815,7 b' impl Index {'
811 if let Some(new_heads) =
815 if let Some(new_heads) =
812 index.head_revs_shortcut().map_err(|e| graph_error(py, e))?
816 index.head_revs_shortcut().map_err(|e| graph_error(py, e))?
813 {
817 {
814 self.cache_new_heads_py_list(new_heads, py);
818 self.cache_new_heads_py_list(&new_heads, py);
815 }
819 }
816
820
817 Ok(self
821 Ok(self
@@ -835,7 +839,7 b' impl Index {'
835 .head_revs_filtered(&filtered_revs, true)
839 .head_revs_filtered(&filtered_revs, true)
836 .map_err(|e| graph_error(py, e))?
840 .map_err(|e| graph_error(py, e))?
837 {
841 {
838 self.cache_new_heads_py_list(new_heads, py);
842 self.cache_new_heads_py_list(&new_heads, py);
839 }
843 }
840
844
841 Ok(self
845 Ok(self
@@ -847,9 +851,34 b' impl Index {'
847 .into_object())
851 .into_object())
848 }
852 }
849
853
854 fn cache_new_heads_node_ids_py_list(
855 &self,
856 new_heads: &[Revision],
857 py: Python<'_>,
858 ) -> PyList {
859 let index = self.index(py).borrow();
860 let as_vec: Vec<PyObject> = new_heads
861 .iter()
862 .map(|r| {
863 PyBytes::new(
864 py,
865 index
866 .node(*r)
867 .expect("rev should have been in the index")
868 .as_bytes(),
869 )
870 .into_object()
871 })
872 .collect();
873 let new_heads_py_list = PyList::new(py, &as_vec);
874 *self.head_node_ids_py_list(py).borrow_mut() =
875 Some(new_heads_py_list.clone_ref(py));
876 new_heads_py_list
877 }
878
850 fn cache_new_heads_py_list(
879 fn cache_new_heads_py_list(
851 &self,
880 &self,
852 new_heads: Vec<Revision>,
881 new_heads: &[Revision],
853 py: Python<'_>,
882 py: Python<'_>,
854 ) -> PyList {
883 ) -> PyList {
855 let as_vec: Vec<PyObject> = new_heads
884 let as_vec: Vec<PyObject> = new_heads
General Comments 0
You need to be logged in to leave comments. Login now