about summary refs log tree commit diff
diff options
context:
space:
mode:
authorTomasz Miąsko <tomasz.miasko@gmail.com>2021-11-03 00:00:00 +0000
committerTomasz Miąsko <tomasz.miasko@gmail.com>2021-11-03 00:00:00 +0000
commit73f5b6581891e24b9b5bd45e58fbec78582549a2 (patch)
tree30fcbb718d3cc4fe93374121ffbe48f01673c835
parent473eaa42e9365c47d129f72693b5d163a20cf369 (diff)
downloadrust-73f5b6581891e24b9b5bd45e58fbec78582549a2.tar.gz
rust-73f5b6581891e24b9b5bd45e58fbec78582549a2.zip
Implement `clone_from` for `State`
Data flow engine uses `clone_from` for domain values.  Providing an
implementation of `clone_from` will avoid some intermediate memory
allocations.
-rw-r--r--compiler/rustc_const_eval/src/transform/check_consts/resolver.rs15
1 files changed, 14 insertions, 1 deletions
diff --git a/compiler/rustc_const_eval/src/transform/check_consts/resolver.rs b/compiler/rustc_const_eval/src/transform/check_consts/resolver.rs
index 38576230883..5fabad6c5fa 100644
--- a/compiler/rustc_const_eval/src/transform/check_consts/resolver.rs
+++ b/compiler/rustc_const_eval/src/transform/check_consts/resolver.rs
@@ -256,7 +256,7 @@ where
     }
 }
 
-#[derive(Clone, Debug, PartialEq, Eq)]
+#[derive(Debug, PartialEq, Eq)]
 pub(super) struct State {
     /// Describes whether a local contains qualif.
     pub qualif: BitSet<Local>,
@@ -265,6 +265,19 @@ pub(super) struct State {
     pub borrow: BitSet<Local>,
 }
 
+impl Clone for State {
+    fn clone(&self) -> Self {
+        State { qualif: self.qualif.clone(), borrow: self.borrow.clone() }
+    }
+
+    // Data flow engine when possible uses `clone_from` for domain values.
+    // Providing an implementation will avoid some intermediate memory allocations.
+    fn clone_from(&mut self, other: &Self) {
+        self.qualif.clone_from(&other.qualif);
+        self.borrow.clone_from(&other.borrow);
+    }
+}
+
 impl State {
     #[inline]
     pub(super) fn contains(&self, local: Local) -> bool {