From fe12fe0e6367dd45293af25795ba85b924080e3c Mon Sep 17 00:00:00 2001 From: Dan Gohman Date: Fri, 1 Sep 2017 10:12:23 -0700 Subject: [PATCH] Avoid unneeded calls to .as_slice(). --- lib/cretonne/src/regalloc/solver.rs | 6 ++--- lib/frontend/src/frontend.rs | 3 +-- lib/wasm/src/code_translator.rs | 37 ++++++++++------------------- lib/wasm/src/sections_translator.rs | 2 +- 4 files changed, 17 insertions(+), 31 deletions(-) diff --git a/lib/cretonne/src/regalloc/solver.rs b/lib/cretonne/src/regalloc/solver.rs index b99da23d43..c9215f4ebb 100644 --- a/lib/cretonne/src/regalloc/solver.rs +++ b/lib/cretonne/src/regalloc/solver.rs @@ -649,7 +649,7 @@ impl Solver { |v| v.from != v.to, )); - dbg!("collect_moves: {}", DisplayList(self.moves.as_slice())); + dbg!("collect_moves: {}", DisplayList(&self.moves)); } /// Try to schedule a sequence of `regmove` instructions that will shuffle registers into @@ -751,8 +751,8 @@ impl fmt::Display for Solver { " assignments: {}", DisplayList(self.assignments.as_slice()) )?; - writeln!(f, " vars: {}", DisplayList(self.vars.as_slice()))?; - writeln!(f, " moves: {}", DisplayList(self.moves.as_slice()))?; + writeln!(f, " vars: {}", DisplayList(&self.vars))?; + writeln!(f, " moves: {}", DisplayList(&self.moves))?; writeln!(f, "}}") } } diff --git a/lib/frontend/src/frontend.rs b/lib/frontend/src/frontend.rs index c896e13f8e..c32a824158 100644 --- a/lib/frontend/src/frontend.rs +++ b/lib/frontend/src/frontend.rs @@ -141,8 +141,7 @@ impl<'short, 'long, Variable> InstBuilderBase<'short> for FuncInstBuilder<'short } _ => panic!("should not happen"), }; - self.builder - .ebb_args_adjustement(dest_ebb, args_types.as_slice()); + self.builder.ebb_args_adjustement(dest_ebb, &args_types); self.builder.declare_successor(dest_ebb, inst); } None => { diff --git a/lib/wasm/src/code_translator.rs b/lib/wasm/src/code_translator.rs index 34c68bf813..751f528f63 100644 --- a/lib/wasm/src/code_translator.rs +++ b/lib/wasm/src/code_translator.rs @@ -75,7 +75,7 @@ impl ControlStackFrame { match *self { ControlStackFrame::If { ref return_values, .. } | ControlStackFrame::Block { ref return_values, .. } | - ControlStackFrame::Loop { ref return_values, .. } => return_values.as_slice(), + ControlStackFrame::Loop { ref return_values, .. } => &return_values, } } fn following_code(&self) -> Ebb { @@ -264,7 +264,7 @@ pub fn translate_function_body( if !builder.is_filled() && (!builder.is_unreachable() || !builder.is_pristine()) { let cut_index = stack.len() - sig.return_types.len(); let return_vals = stack.split_off(cut_index); - builder.ins().return_(return_vals.as_slice()); + builder.ins().return_(&return_vals); } // Because the function has an implicit block as body, we need to explicitely close it. let frame = control_stack.pop().unwrap(); @@ -276,7 +276,7 @@ pub fn translate_function_body( stack.extend_from_slice(builder.ebb_args(frame.following_code())); let cut_index = stack.len() - sig.return_types.len(); let return_vals = stack.split_off(cut_index); - builder.ins().return_(return_vals.as_slice()); + builder.ins().return_(&return_vals); } } Ok((func, func_imports)) @@ -418,7 +418,7 @@ fn translate_operator( }; let cut_index = stack.len() - return_values.len(); let jump_args = stack.split_off(cut_index); - builder.ins().jump(destination, jump_args.as_slice()); + builder.ins().jump(destination, &jump_args); // We change the target of the branch instruction let else_ebb = builder.create_ebb(); builder.change_jump_destination(branch_inst, else_ebb); @@ -430,10 +430,7 @@ fn translate_operator( if !builder.is_unreachable() || !builder.is_pristine() { let cut_index = stack.len() - frame.return_values().len(); let jump_args = stack.split_off(cut_index); - builder.ins().jump( - frame.following_code(), - jump_args.as_slice(), - ); + builder.ins().jump(frame.following_code(), &jump_args); } builder.switch_to_block(frame.following_code(), frame.return_values()); builder.seal_block(frame.following_code()); @@ -475,10 +472,7 @@ fn translate_operator( let cut_index = stack.len() - frame.return_values().len(); stack.split_off(cut_index) }; - builder.ins().jump( - frame.br_destination(), - jump_args.as_slice(), - ); + builder.ins().jump(frame.br_destination(), &jump_args); // We signal that all the code that follows until the next End is unreachable frame.set_reachable(); state.real_unreachable_stack_depth = 1 + relative_depth as usize; @@ -493,11 +487,7 @@ fn translate_operator( let cut_index = stack.len() - frame.return_values().len(); stack.split_off(cut_index) }; - builder.ins().brnz( - val, - frame.br_destination(), - jump_args.as_slice(), - ); + builder.ins().brnz(val, frame.br_destination(), &jump_args); // The values returned by the branch are still available for the reachable // code that comes after it frame.set_reachable(); @@ -561,7 +551,7 @@ fn translate_operator( builder.ins().br_table(val, jt); let default_ebb = control_stack[control_stack.len() - 1 - (default as usize)] .br_destination(); - builder.ins().jump(default_ebb, jump_args.as_slice()); + builder.ins().jump(default_ebb, &jump_args); stack.extend_from_slice(&jump_args); for (depth, dest_ebb) in dest_ebbs { builder.switch_to_block(dest_ebb, &[]); @@ -569,7 +559,7 @@ fn translate_operator( let i = control_stack.len() - 1 - depth; let frame = &mut control_stack[i]; let real_dest_ebb = frame.br_destination(); - builder.ins().jump(real_dest_ebb, jump_args.as_slice()); + builder.ins().jump(real_dest_ebb, &jump_args); frame.set_reachable(); } state.real_unreachable_stack_depth = 1 + min_depth as usize; @@ -579,7 +569,7 @@ fn translate_operator( let return_count = sig.return_types.len(); let cut_index = stack.len() - return_count; let return_args = stack.split_off(cut_index); - builder.ins().return_(return_args.as_slice()); + builder.ins().return_(&return_args); state.real_unreachable_stack_depth = 1; } /************************************ Calls **************************************** @@ -599,10 +589,7 @@ fn translate_operator( exports, signatures, ); - let call_inst = builder.ins().call( - internal_function_index, - call_args.as_slice(), - ); + let call_inst = builder.ins().call(internal_function_index, &call_args); let ret_values = builder.inst_results(call_inst); for val in ret_values { stack.push(*val); @@ -621,7 +608,7 @@ fn translate_operator( let cut_index = stack.len() - args_num; let call_args = stack.split_off(cut_index); let ret_values = - runtime.translate_call_indirect(builder, sigref, index_val, call_args.as_slice()); + runtime.translate_call_indirect(builder, sigref, index_val, &call_args); for val in ret_values { stack.push(*val); } diff --git a/lib/wasm/src/sections_translator.rs b/lib/wasm/src/sections_translator.rs index 3abb6f232a..6c97d928f7 100644 --- a/lib/wasm/src/sections_translator.rs +++ b/lib/wasm/src/sections_translator.rs @@ -369,7 +369,7 @@ pub fn parse_elements_section( ParserState::ElementSectionEntryBody(ref elements) => { let elems: Vec = elements.iter().map(|&x| x as FunctionIndex).collect(); - runtime.declare_table_elements(table_index, offset, elems.as_slice()) + runtime.declare_table_elements(table_index, offset, &elems) } ref s => return Err(SectionParsingError::WrongSectionContent(format!("{:?}", s))), };