Estimate resulting size.
This commit is contained in:
parent
3f10ba6666
commit
bcc426c6dc
|
@ -170,12 +170,14 @@ impl Validator {
|
||||||
) -> Result<isa::Instructions, Error> {
|
) -> Result<isa::Instructions, Error> {
|
||||||
let (params, result_ty) = module.require_function_type(func.type_ref())?;
|
let (params, result_ty) = module.require_function_type(func.type_ref())?;
|
||||||
|
|
||||||
|
let ins_size_estimate = body.code().elements().len();
|
||||||
let mut context = FunctionValidationContext::new(
|
let mut context = FunctionValidationContext::new(
|
||||||
&module,
|
&module,
|
||||||
Locals::new(params, body.locals()),
|
Locals::new(params, body.locals()),
|
||||||
DEFAULT_VALUE_STACK_LIMIT,
|
DEFAULT_VALUE_STACK_LIMIT,
|
||||||
DEFAULT_FRAME_STACK_LIMIT,
|
DEFAULT_FRAME_STACK_LIMIT,
|
||||||
result_ty,
|
result_ty,
|
||||||
|
ins_size_estimate,
|
||||||
);
|
);
|
||||||
|
|
||||||
let end_label = context.sink.new_label();
|
let end_label = context.sink.new_label();
|
||||||
|
@ -1319,6 +1321,7 @@ impl<'a> FunctionValidationContext<'a> {
|
||||||
value_stack_limit: usize,
|
value_stack_limit: usize,
|
||||||
frame_stack_limit: usize,
|
frame_stack_limit: usize,
|
||||||
return_type: BlockType,
|
return_type: BlockType,
|
||||||
|
size_estimate: usize,
|
||||||
) -> Self {
|
) -> Self {
|
||||||
FunctionValidationContext {
|
FunctionValidationContext {
|
||||||
module: module,
|
module: module,
|
||||||
|
@ -1327,7 +1330,7 @@ impl<'a> FunctionValidationContext<'a> {
|
||||||
value_stack: StackWithLimit::with_limit(value_stack_limit),
|
value_stack: StackWithLimit::with_limit(value_stack_limit),
|
||||||
frame_stack: StackWithLimit::with_limit(frame_stack_limit),
|
frame_stack: StackWithLimit::with_limit(frame_stack_limit),
|
||||||
return_type: return_type,
|
return_type: return_type,
|
||||||
sink: Sink::new(),
|
sink: Sink::with_instruction_capacity(size_estimate),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1563,10 +1566,9 @@ struct Sink {
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Sink {
|
impl Sink {
|
||||||
// TODO: Default size estimate?
|
fn with_instruction_capacity(capacity: usize) -> Sink {
|
||||||
fn new() -> Sink {
|
|
||||||
Sink {
|
Sink {
|
||||||
ins: Vec::new(),
|
ins: Vec::with_capacity(estimate),
|
||||||
labels: Vec::new(),
|
labels: Vec::new(),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue