replace vec<u32> with box<[u32]>

This commit is contained in:
NikVolf
2018-01-22 16:40:27 +03:00
parent 8056481dc8
commit 9275b253ca
6 changed files with 9 additions and 9 deletions

View File

@ -229,9 +229,7 @@ pub type NameMap = IndexMap<String>;
#[cfg(test)]
mod tests {
use std::io::Cursor;
use super::*;
use super::super::{deserialize_file, Section};
// A helper funtion for the tests. Serialize a section, deserialize it,
// and make sure it matches the original.

View File

@ -113,7 +113,7 @@ pub enum Opcode {
End,
Br(u32),
BrIf(u32),
BrTable(Vec<u32>, u32),
BrTable(Box<[u32]>, u32),
Return,
Call(u32),
@ -340,7 +340,7 @@ impl Deserialize for Opcode {
.map(Into::into)
.collect();
BrTable(t1, VarUint32::deserialize(reader)?.into())
BrTable(t1.into_boxed_slice(), VarUint32::deserialize(reader)?.into())
},
0x0f => Return,
0x10 => Call(VarUint32::deserialize(reader)?.into()),
@ -633,7 +633,7 @@ impl Serialize for Opcode {
BrTable(table, default) => op!(writer, 0x0e, {
let list_writer = CountedListWriter::<VarUint32, _>(
table.len(),
table.into_iter().map(Into::into),
table.into_iter().map(|x| VarUint32::from(*x)),
);
list_writer.serialize(writer)?;
VarUint32::from(default).serialize(writer)?;

View File

@ -402,7 +402,7 @@ impl Interpreter {
}
}
fn run_br_table<'a>(context: &mut FunctionContext, table: &Vec<u32>, default: u32) -> Result<InstructionOutcome<'a>, Error> {
fn run_br_table<'a>(context: &mut FunctionContext, table: &[u32], default: u32) -> Result<InstructionOutcome<'a>, Error> {
let index: u32 = context.value_stack_mut().pop_as()?;
Ok(InstructionOutcome::Branch(table.get(index as usize).cloned().unwrap_or(default) as usize))
}

View File

@ -392,7 +392,9 @@ fn brtable() {
Opcode::Block(BlockType::NoResult), // block1
Opcode::Block(BlockType::NoResult), // block0
Opcode::GetLocal(0), // [arg]
Opcode::BrTable(vec![0, 1, 2], 3), // br_table
Opcode::BrTable(
vec![0, 1, 2].into_boxed_slice(), 3),
// br_table
Opcode::End, // end (block0)
Opcode::I32Const(0), // [0]
Opcode::Return, // return 0

View File

@ -497,7 +497,7 @@ impl Validator {
Ok(InstructionOutcome::ValidateNextInstruction)
}
fn validate_br_table(context: &mut FunctionValidationContext, table: &Vec<u32>, default: u32) -> Result<InstructionOutcome, Error> {
fn validate_br_table(context: &mut FunctionValidationContext, table: &[u32], default: u32) -> Result<InstructionOutcome, Error> {
let mut required_block_type = None;
{

View File

@ -501,7 +501,7 @@ impl Validator {
Ok(InstructionOutcome::ValidateNextInstruction)
}
fn validate_br_table(context: &mut FunctionValidationContext, table: &Vec<u32>, default: u32) -> Result<InstructionOutcome, Error> {
fn validate_br_table(context: &mut FunctionValidationContext, table: &[u32], default: u32) -> Result<InstructionOutcome, Error> {
let mut required_block_type = None;
{