]> git.lizzy.rs Git - rust.git/commitdiff
Do not clone Mir unnecessarily
authorSimonas Kazlauskas <git@kazlauskas.me>
Mon, 31 Oct 2016 00:16:21 +0000 (02:16 +0200)
committerSimonas Kazlauskas <git@kazlauskas.me>
Mon, 31 Oct 2016 00:16:21 +0000 (02:16 +0200)
src/librustc/mir/mod.rs
src/librustc_trans/mir/block.rs

index 994316d05ec78c99c6d95294660f3d758b1894dd..f6ee5afaa123c3cae38f0d65b19754a5540d4052 100644 (file)
@@ -63,7 +63,8 @@ fn fmt(&self, fmt: &mut Formatter) -> fmt::Result {
 }
 
 /// 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.
index 6d4b01b1d693dc8148eb9cdcd1e41e1c16f88882..8bf27b4babfc2a054a2f0cbc7336548f4750efeb 100644 (file)
 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 @@ pub fn trans_block(&mut self, bb: mir::BasicBlock) {
             }
 
             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