From 539a5b33787d204b535ce5cee059c8566adf6df4 Mon Sep 17 00:00:00 2001 From: Dan Gohman Date: Thu, 31 Aug 2017 14:56:27 -0700 Subject: [PATCH] Avoid a heap allocation for a block's undef_variables. --- lib/frontend/src/ssa.rs | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/lib/frontend/src/ssa.rs b/lib/frontend/src/ssa.rs index 603f81073d..c9f763cf7f 100644 --- a/lib/frontend/src/ssa.rs +++ b/lib/frontend/src/ssa.rs @@ -16,6 +16,7 @@ use std::u32; use cretonne::ir::types::{F32, F64}; use cretonne::ir::immediates::{Ieee32, Ieee64}; use std::collections::HashMap; +use std::mem; /// Structure containing the data relevant the construction of SSA for a given function. /// @@ -352,11 +353,11 @@ where BlockData::EbbBody { .. } => panic!("this should not happen"), BlockData::EbbHeader(ref mut data) => { assert!(!data.sealed); - ( - data.predecessors.clone(), - data.undef_variables.clone(), - data.ebb, - ) + // Extract the undef_variables data from the block so that we + // can iterate over it without borrowing the whole builder. + let mut undef_variables = Vec::new(); + mem::swap(&mut data.undef_variables, &mut undef_variables); + (data.predecessors.clone(), undef_variables, data.ebb) } }; @@ -375,12 +376,12 @@ where ); } - // Then we clear the undef_vars and mark the block as sealed. + // Then we mark the block as sealed. match self.blocks[block] { BlockData::EbbBody { .. } => panic!("this should not happen"), BlockData::EbbHeader(ref mut data) => { assert!(!data.sealed); - data.undef_variables.clear(); + assert!(data.undef_variables.is_empty()); data.sealed = true; } };