mirror of
https://github.com/mii443/wasmer.git
synced 2025-12-07 13:18:20 +00:00
feat(api) Avoid string allocations in FromToNativeWasmType.
When `from_native` or `to_native` fail, panic with a `&'static str` instead of a `String`. Since this string is always created, it's better to avoid this allocation for every call.
This commit is contained in:
10
lib/api/src/externals/function.rs
vendored
10
lib/api/src/externals/function.rs
vendored
@@ -546,9 +546,8 @@ mod inner {
|
||||
|
||||
#[inline]
|
||||
fn from_native(native: Self::Native) -> Self {
|
||||
native.try_into().expect(&format!(
|
||||
"cannot convert {}{} to {}",
|
||||
native,
|
||||
native.try_into().expect(concat!(
|
||||
"out of range type conversion attempt (tried to convert `{}` to `{}`)",
|
||||
stringify!($native_type),
|
||||
stringify!($type),
|
||||
))
|
||||
@@ -556,9 +555,8 @@ mod inner {
|
||||
|
||||
#[inline]
|
||||
fn to_native(self) -> Self::Native {
|
||||
self.try_into().expect(&format!(
|
||||
"cannot convert {}{} to {}",
|
||||
self,
|
||||
self.try_into().expect(concat!(
|
||||
"out of range type conversion attempt (tried to convert `{}` to `{}`)",
|
||||
stringify!($type),
|
||||
stringify!($native_type),
|
||||
))
|
||||
|
||||
Reference in New Issue
Block a user