# HG changeset patch # User Yuya Nishihara # Date 2019-09-15 08:02:31 # Node ID b3dda04e851b1970573503ebbc301f7feecfc9ea # Parent 7d6758f2d50c1d54d6266eb2f36d0724152e53c3 rust-cpython: drop self.borrow_mut() in favor of PySharedRef wrapper diff --git a/rust/hg-cpython/src/dirstate/dirs_multiset.rs b/rust/hg-cpython/src/dirstate/dirs_multiset.rs --- a/rust/hg-cpython/src/dirstate/dirs_multiset.rs +++ b/rust/hg-cpython/src/dirstate/dirs_multiset.rs @@ -66,14 +66,14 @@ py_class!(pub class Dirs |py| { } def addpath(&self, path: PyObject) -> PyResult { - self.borrow_mut(py)?.add_path( + self.inner_shared(py).borrow_mut()?.add_path( HgPath::new(path.extract::(py)?.data(py)), ); Ok(py.None()) } def delpath(&self, path: PyObject) -> PyResult { - self.borrow_mut(py)?.delete_path( + self.inner_shared(py).borrow_mut()?.delete_path( HgPath::new(path.extract::(py)?.data(py)), ) .and(Ok(py.None())) diff --git a/rust/hg-cpython/src/dirstate/dirstate_map.rs b/rust/hg-cpython/src/dirstate/dirstate_map.rs --- a/rust/hg-cpython/src/dirstate/dirstate_map.rs +++ b/rust/hg-cpython/src/dirstate/dirstate_map.rs @@ -54,7 +54,7 @@ py_class!(pub class DirstateMap |py| { } def clear(&self) -> PyResult { - self.borrow_mut(py)?.clear(); + self.inner_shared(py).borrow_mut()?.clear(); Ok(py.None()) } @@ -89,7 +89,7 @@ py_class!(pub class DirstateMap |py| { size: PyObject, mtime: PyObject ) -> PyResult { - self.borrow_mut(py)?.add_file( + self.inner_shared(py).borrow_mut()?.add_file( HgPath::new(f.extract::(py)?.data(py)), oldstate.extract::(py)?.data(py)[0] .try_into() @@ -116,7 +116,7 @@ py_class!(pub class DirstateMap |py| { oldstate: PyObject, size: PyObject ) -> PyResult { - self.borrow_mut(py)? + self.inner_shared(py).borrow_mut()? .remove_file( HgPath::new(f.extract::(py)?.data(py)), oldstate.extract::(py)?.data(py)[0] @@ -140,7 +140,7 @@ py_class!(pub class DirstateMap |py| { f: PyObject, oldstate: PyObject ) -> PyResult { - self.borrow_mut(py)? + self.inner_shared(py).borrow_mut()? .drop_file( HgPath::new(f.extract::(py)?.data(py)), oldstate.extract::(py)?.data(py)[0] @@ -171,7 +171,7 @@ py_class!(pub class DirstateMap |py| { )) }) .collect(); - self.borrow_mut(py)? + self.inner_shared(py).borrow_mut()? .clear_ambiguous_times(files?, now.extract(py)?); Ok(py.None()) } @@ -206,20 +206,20 @@ py_class!(pub class DirstateMap |py| { def hastrackeddir(&self, d: PyObject) -> PyResult { let d = d.extract::(py)?; - Ok(self.borrow_mut(py)? + Ok(self.inner_shared(py).borrow_mut()? .has_tracked_dir(HgPath::new(d.data(py))) .to_py_object(py)) } def hasdir(&self, d: PyObject) -> PyResult { let d = d.extract::(py)?; - Ok(self.borrow_mut(py)? + Ok(self.inner_shared(py).borrow_mut()? .has_dir(HgPath::new(d.data(py))) .to_py_object(py)) } def parents(&self, st: PyObject) -> PyResult { - self.borrow_mut(py)? + self.inner_shared(py).borrow_mut()? .parents(st.extract::(py)?.data(py)) .and_then(|d| { Ok((PyBytes::new(py, &d.p1), PyBytes::new(py, &d.p2)) @@ -237,13 +237,13 @@ py_class!(pub class DirstateMap |py| { let p1 = extract_node_id(py, &p1)?; let p2 = extract_node_id(py, &p2)?; - self.borrow_mut(py)? + self.inner_shared(py).borrow_mut()? .set_parents(&DirstateParents { p1, p2 }); Ok(py.None()) } def read(&self, st: PyObject) -> PyResult> { - match self.borrow_mut(py)? + match self.inner_shared(py).borrow_mut()? .read(st.extract::(py)?.data(py)) { Ok(Some(parents)) => Ok(Some( @@ -270,7 +270,7 @@ py_class!(pub class DirstateMap |py| { p2: extract_node_id(py, &p2)?, }; - match self.borrow_mut(py)?.pack(parents, now) { + match self.inner_shared(py).borrow_mut()?.pack(parents, now) { Ok(packed) => Ok(PyBytes::new(py, &packed)), Err(_) => Err(PyErr::new::( py, @@ -281,7 +281,9 @@ py_class!(pub class DirstateMap |py| { def filefoldmapasdict(&self) -> PyResult { let dict = PyDict::new(py); - for (key, value) in self.borrow_mut(py)?.build_file_fold_map().iter() { + for (key, value) in + self.inner_shared(py).borrow_mut()?.build_file_fold_map().iter() + { dict.set_item(py, key.as_ref().to_vec(), value.as_ref().to_vec())?; } Ok(dict) @@ -350,7 +352,7 @@ py_class!(pub class DirstateMap |py| { def getdirs(&self) -> PyResult { // TODO don't copy, share the reference - self.borrow_mut(py)?.set_dirs(); + self.inner_shared(py).borrow_mut()?.set_dirs(); Dirs::from_inner( py, DirsMultiset::from_dirstate( @@ -361,7 +363,7 @@ py_class!(pub class DirstateMap |py| { } def getalldirs(&self) -> PyResult { // TODO don't copy, share the reference - self.borrow_mut(py)?.set_all_dirs(); + self.inner_shared(py).borrow_mut()?.set_all_dirs(); Dirs::from_inner( py, DirsMultiset::from_dirstate( @@ -434,7 +436,7 @@ py_class!(pub class DirstateMap |py| { ) -> PyResult { let key = key.extract::(py)?; let value = value.extract::(py)?; - self.borrow_mut(py)?.copy_map.insert( + self.inner_shared(py).borrow_mut()?.copy_map.insert( HgPathBuf::from_bytes(key.data(py)), HgPathBuf::from_bytes(value.data(py)), ); @@ -447,7 +449,8 @@ py_class!(pub class DirstateMap |py| { ) -> PyResult> { let key = key.extract::(py)?; match self - .borrow_mut(py)? + .inner_shared(py) + .borrow_mut()? .copy_map .remove(HgPath::new(key.data(py))) { diff --git a/rust/hg-cpython/src/ref_sharing.rs b/rust/hg-cpython/src/ref_sharing.rs --- a/rust/hg-cpython/src/ref_sharing.rs +++ b/rust/hg-cpython/src/ref_sharing.rs @@ -310,15 +310,6 @@ macro_rules! py_shared_ref { let data = self.$data_member(py); unsafe { PySharedRef::new(py, owner, data) } } - - // TODO: remove this function in favor of $shared_accessor(py) - fn borrow_mut<'a>( - &'a self, - py: Python<'a>, - ) -> PyResult> - { - self.$shared_accessor(py).borrow_mut() - } } }; }