wasm: Use Ord::max where possible instead of a custom function

This commit is contained in:
Brian Carroll 2022-07-07 20:32:32 +01:00
parent a55461d0f8
commit a6faf875f8
No known key found for this signature in database
GPG key ID: 9CF4E3BF9C4722C7
2 changed files with 3 additions and 14 deletions

View file

@ -205,19 +205,12 @@ impl<T: Wasm32Sized, E: Wasm32Sized> Wasm32Result for RocResult<T, E> {
build_wrapper_body_stack_memory(
code_builder,
main_function_index,
max2(T::ACTUAL_WIDTH, E::ACTUAL_WIDTH) + max2(T::ALIGN_OF_WASM, E::ALIGN_OF_WASM),
Ord::max(T::ACTUAL_WIDTH, E::ACTUAL_WIDTH)
+ Ord::max(T::ALIGN_OF_WASM, E::ALIGN_OF_WASM),
)
}
}
fn max2(a: usize, b: usize) -> usize {
if a > b {
a
} else {
b
}
}
impl<T: Wasm32Result> Wasm32Result for &'_ T {
build_wrapper_body_primitive!(i32_store, Align::Bytes4);
}

View file

@ -99,11 +99,7 @@ impl<T: FromWasmerMemory + Wasm32Sized, E: FromWasmerMemory + Wasm32Sized> FromW
for RocResult<T, E>
{
fn decode(memory: &wasmer::Memory, offset: u32) -> Self {
let tag_offset = if T::ACTUAL_WIDTH > E::ACTUAL_WIDTH {
T::ACTUAL_WIDTH
} else {
E::ACTUAL_WIDTH
};
let tag_offset = Ord::max(T::ACTUAL_WIDTH, E::ACTUAL_WIDTH);
let tag = <u8 as FromWasmerMemory>::decode(memory, offset + tag_offset as u32);
if tag == 1 {
let value = <T as FromWasmerMemory>::decode(memory, offset);