Skip to content

Commit

Permalink
Implement clone_from for State
Browse files Browse the repository at this point in the history
Data flow engine uses `clone_from` for domain values.  Providing an
implementation of `clone_from` will avoid some intermediate memory
allocations.
  • Loading branch information
tmiasko committed Nov 3, 2021
1 parent 473eaa4 commit 73f5b65
Showing 1 changed file with 14 additions and 1 deletion.
15 changes: 14 additions & 1 deletion compiler/rustc_const_eval/src/transform/check_consts/resolver.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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>,
Expand All @@ -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 {
Expand Down

0 comments on commit 73f5b65

Please sign in to comment.