changeset 44362:c089a0947f3e

rust-dirstatemap: directly return `non_normal` and `other_entries` This cleans up the interface which I previously thought needed to be uglier than in reality. No performance difference, simple refactoring. Differential Revision: https://phab.mercurial-scm.org/D8121
author Raphaël Gomès <rgomes@octobus.net>
date Fri, 14 Feb 2020 15:03:26 +0100
parents 27a78ea30b48
children f7459da77f23
files rust/hg-core/src/dirstate/dirstate_map.rs rust/hg-cpython/src/dirstate/dirstate_map.rs
diffstat 2 files changed, 12 insertions(+), 44 deletions(-) [+]
line wrap: on
line diff
--- a/rust/hg-core/src/dirstate/dirstate_map.rs	Thu Dec 26 14:12:45 2019 -0800
+++ b/rust/hg-core/src/dirstate/dirstate_map.rs	Fri Feb 14 15:03:26 2020 +0100
@@ -100,16 +100,12 @@
         if entry.state != EntryState::Normal || entry.mtime == MTIME_UNSET {
             self.get_non_normal_other_parent_entries()
                 .0
-                .as_mut()
-                .unwrap()
                 .insert(filename.to_owned());
         }
 
         if entry.size == SIZE_FROM_OTHER_PARENT {
             self.get_non_normal_other_parent_entries()
                 .1
-                .as_mut()
-                .unwrap()
                 .insert(filename.to_owned());
         }
         Ok(())
@@ -152,8 +148,6 @@
         );
         self.get_non_normal_other_parent_entries()
             .0
-            .as_mut()
-            .unwrap()
             .insert(filename.to_owned());
         Ok(())
     }
@@ -182,8 +176,6 @@
         }
         self.get_non_normal_other_parent_entries()
             .0
-            .as_mut()
-            .unwrap()
             .remove(filename);
 
         Ok(exists)
@@ -211,8 +203,6 @@
             if changed {
                 self.get_non_normal_other_parent_entries()
                     .0
-                    .as_mut()
-                    .unwrap()
                     .insert(filename.to_owned());
             }
         }
@@ -224,8 +214,6 @@
     ) -> bool {
         self.get_non_normal_other_parent_entries()
             .0
-            .as_mut()
-            .unwrap()
             .remove(key.as_ref())
     }
     pub fn non_normal_entries_union(
@@ -234,8 +222,6 @@
     ) -> Vec<HgPathBuf> {
         self.get_non_normal_other_parent_entries()
             .0
-            .as_mut()
-            .unwrap()
             .union(&other)
             .map(|e| e.to_owned())
             .collect()
@@ -243,12 +229,12 @@
 
     pub fn get_non_normal_other_parent_entries(
         &mut self,
-    ) -> (
-        &mut Option<HashSet<HgPathBuf>>,
-        &mut Option<HashSet<HgPathBuf>>,
-    ) {
+    ) -> (&mut HashSet<HgPathBuf>, &mut HashSet<HgPathBuf>) {
         self.set_non_normal_other_parent_entries(false);
-        (&mut self.non_normal_set, &mut self.other_parent_set)
+        (
+            self.non_normal_set.as_mut().unwrap(),
+            self.other_parent_set.as_mut().unwrap(),
+        )
     }
 
     pub fn set_non_normal_other_parent_entries(&mut self, force: bool) {
@@ -440,22 +426,8 @@
         .unwrap();
 
         assert_eq!(1, map.len());
-        assert_eq!(
-            0,
-            map.get_non_normal_other_parent_entries()
-                .0
-                .as_ref()
-                .unwrap()
-                .len()
-        );
-        assert_eq!(
-            0,
-            map.get_non_normal_other_parent_entries()
-                .1
-                .as_ref()
-                .unwrap()
-                .len()
-        );
+        assert_eq!(0, map.get_non_normal_other_parent_entries().0.len());
+        assert_eq!(0, map.get_non_normal_other_parent_entries().1.len());
     }
 
     #[test]
@@ -487,7 +459,7 @@
         })
         .collect();
 
-        let non_normal = [
+        let mut non_normal = [
             b"f1", b"f2", b"f5", b"f6", b"f7", b"f8", b"f9", b"fa", b"fb",
         ]
         .iter()
@@ -499,8 +471,8 @@
         let entries = map.get_non_normal_other_parent_entries();
 
         assert_eq!(
-            (Some(non_normal), Some(other_parent)),
-            (entries.0.to_owned(), entries.1.to_owned())
+            (&mut non_normal, &mut other_parent),
+            (entries.0, entries.1)
         );
     }
 }
--- a/rust/hg-cpython/src/dirstate/dirstate_map.rs	Thu Dec 26 14:12:45 2019 -0800
+++ b/rust/hg-cpython/src/dirstate/dirstate_map.rs	Fri Feb 14 15:03:26 2020 +0100
@@ -175,8 +175,7 @@
         locals.set_item(
             py,
             "other_parent",
-            other_parent.as_ref()
-                .unwrap()
+            other_parent
                 .iter()
                 .map(|v| PyBytes::new(py, v.as_ref()))
                 .collect::<Vec<PyBytes>>()
@@ -196,8 +195,6 @@
             .inner(py)
             .borrow_mut()
             .get_non_normal_other_parent_entries().0
-            .as_ref()
-            .unwrap()
             .contains(HgPath::new(key.data(py))))
     }
 
@@ -211,8 +208,7 @@
                         .inner(py)
                         .borrow_mut()
                         .get_non_normal_other_parent_entries().0
-                        .as_ref()
-                        .unwrap().iter().map(|o| o))
+                        .iter().map(|o| o))
                 )
             )
     }