about summary refs log tree commit diff
diff options
context:
space:
mode:
authorbors <bors@rust-lang.org>2016-10-30 20:30:38 -0700
committerGitHub <noreply@github.com>2016-10-30 20:30:38 -0700
commit8f1fc865333482e709e96ec578135eb8bfbee930 (patch)
treef318b31a1a16e8062c60a61f4f586f34b4eabeb1
parentbfc9b29acc8bfdeee96e3d3cb466d6b7b411a7a7 (diff)
parent8ec0b3a12a0e6afd391315554fee07292958fff8 (diff)
Auto merge of #37489 - nagisa:unnecessary-clone, r=eddyb
Do not clone Mir unnecessarily

r? @eddyb
-rw-r--r--src/librustc/mir/mod.rs3
-rw-r--r--src/librustc_trans/mir/block.rs9
2 files changed, 7 insertions, 5 deletions
diff --git a/src/librustc/mir/mod.rs b/src/librustc/mir/mod.rs
index 6129d1b3d4c..9d82006ac9f 100644
--- a/src/librustc/mir/mod.rs
+++ b/src/librustc/mir/mod.rs
@@ -63,7 +63,8 @@ macro_rules! newtype_index {
 }
 
 /// Lowered representation of a single function.
-#[derive(Clone, RustcEncodable, RustcDecodable, Debug)]
+// Do not implement clone for Mir, its easy to do so accidently and its kind of expensive.
+#[derive(RustcEncodable, RustcDecodable, Debug)]
 pub struct Mir<'tcx> {
     /// List of basic blocks. References to basic block use a newtyped index type `BasicBlock`
     /// that indexes into this vector.
diff --git a/src/librustc_trans/mir/block.rs b/src/librustc_trans/mir/block.rs
index 6d4b01b1d69..8bf27b4babf 100644
--- a/src/librustc_trans/mir/block.rs
+++ b/src/librustc_trans/mir/block.rs
@@ -37,13 +37,14 @@ use super::analyze::CleanupKind;
 use super::constant::Const;
 use super::lvalue::{LvalueRef};
 use super::operand::OperandRef;
-use super::operand::OperandValue::*;
+use super::operand::OperandValue::{Pair, Ref, Immediate};
+
+use std::cell::Ref as CellRef;
 
 impl<'bcx, 'tcx> MirContext<'bcx, 'tcx> {
     pub fn trans_block(&mut self, bb: mir::BasicBlock) {
         let mut bcx = self.bcx(bb);
-        let mir = self.mir.clone();
-        let data = &mir[bb];
+        let data = &CellRef::clone(&self.mir)[bb];
 
         debug!("trans_block({:?}={:?})", bb, data);
 
@@ -228,7 +229,7 @@ impl<'bcx, 'tcx> MirContext<'bcx, 'tcx> {
             }
 
             mir::TerminatorKind::Drop { ref location, target, unwind } => {
-                let ty = location.ty(&mir, bcx.tcx()).to_ty(bcx.tcx());
+                let ty = location.ty(&self.mir, bcx.tcx()).to_ty(bcx.tcx());
                 let ty = bcx.monomorphize(&ty);
 
                 // Double check for necessity to drop