mirror of
https://github.com/fluencelabs/parity-wasm
synced 2025-06-29 22:51:56 +00:00
replace vec<u32> with box<[u32]>
This commit is contained in:
@ -229,9 +229,7 @@ pub type NameMap = IndexMap<String>;
|
|||||||
|
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
mod tests {
|
mod tests {
|
||||||
use std::io::Cursor;
|
|
||||||
use super::*;
|
use super::*;
|
||||||
use super::super::{deserialize_file, Section};
|
|
||||||
|
|
||||||
// A helper funtion for the tests. Serialize a section, deserialize it,
|
// A helper funtion for the tests. Serialize a section, deserialize it,
|
||||||
// and make sure it matches the original.
|
// and make sure it matches the original.
|
||||||
|
@ -113,7 +113,7 @@ pub enum Opcode {
|
|||||||
End,
|
End,
|
||||||
Br(u32),
|
Br(u32),
|
||||||
BrIf(u32),
|
BrIf(u32),
|
||||||
BrTable(Vec<u32>, u32),
|
BrTable(Box<[u32]>, u32),
|
||||||
Return,
|
Return,
|
||||||
|
|
||||||
Call(u32),
|
Call(u32),
|
||||||
@ -340,7 +340,7 @@ impl Deserialize for Opcode {
|
|||||||
.map(Into::into)
|
.map(Into::into)
|
||||||
.collect();
|
.collect();
|
||||||
|
|
||||||
BrTable(t1, VarUint32::deserialize(reader)?.into())
|
BrTable(t1.into_boxed_slice(), VarUint32::deserialize(reader)?.into())
|
||||||
},
|
},
|
||||||
0x0f => Return,
|
0x0f => Return,
|
||||||
0x10 => Call(VarUint32::deserialize(reader)?.into()),
|
0x10 => Call(VarUint32::deserialize(reader)?.into()),
|
||||||
@ -633,7 +633,7 @@ impl Serialize for Opcode {
|
|||||||
BrTable(table, default) => op!(writer, 0x0e, {
|
BrTable(table, default) => op!(writer, 0x0e, {
|
||||||
let list_writer = CountedListWriter::<VarUint32, _>(
|
let list_writer = CountedListWriter::<VarUint32, _>(
|
||||||
table.len(),
|
table.len(),
|
||||||
table.into_iter().map(Into::into),
|
table.into_iter().map(|x| VarUint32::from(*x)),
|
||||||
);
|
);
|
||||||
list_writer.serialize(writer)?;
|
list_writer.serialize(writer)?;
|
||||||
VarUint32::from(default).serialize(writer)?;
|
VarUint32::from(default).serialize(writer)?;
|
||||||
|
@ -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()?;
|
let index: u32 = context.value_stack_mut().pop_as()?;
|
||||||
Ok(InstructionOutcome::Branch(table.get(index as usize).cloned().unwrap_or(default) as usize))
|
Ok(InstructionOutcome::Branch(table.get(index as usize).cloned().unwrap_or(default) as usize))
|
||||||
}
|
}
|
||||||
|
@ -392,7 +392,9 @@ fn brtable() {
|
|||||||
Opcode::Block(BlockType::NoResult), // block1
|
Opcode::Block(BlockType::NoResult), // block1
|
||||||
Opcode::Block(BlockType::NoResult), // block0
|
Opcode::Block(BlockType::NoResult), // block0
|
||||||
Opcode::GetLocal(0), // [arg]
|
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::End, // end (block0)
|
||||||
Opcode::I32Const(0), // [0]
|
Opcode::I32Const(0), // [0]
|
||||||
Opcode::Return, // return 0
|
Opcode::Return, // return 0
|
||||||
|
@ -497,7 +497,7 @@ impl Validator {
|
|||||||
Ok(InstructionOutcome::ValidateNextInstruction)
|
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;
|
let mut required_block_type = None;
|
||||||
|
|
||||||
{
|
{
|
||||||
|
@ -501,7 +501,7 @@ impl Validator {
|
|||||||
Ok(InstructionOutcome::ValidateNextInstruction)
|
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;
|
let mut required_block_type = None;
|
||||||
|
|
||||||
{
|
{
|
||||||
|
Reference in New Issue
Block a user