mirror of
https://github.com/rustwasm/wasm-bindgen.git
synced 2024-12-14 12:02:23 +03:00
Ensure that various Into/From ABI methods are inlined
This commit is contained in:
parent
908fc614c0
commit
68af85d001
@ -275,6 +275,7 @@ impl OptionFromWasmAbi for char {
|
||||
impl<T> IntoWasmAbi for *const T {
|
||||
type Abi = u32;
|
||||
|
||||
#[inline]
|
||||
fn into_abi(self) -> u32 {
|
||||
self as u32
|
||||
}
|
||||
@ -283,6 +284,7 @@ impl<T> IntoWasmAbi for *const T {
|
||||
impl<T> FromWasmAbi for *const T {
|
||||
type Abi = u32;
|
||||
|
||||
#[inline]
|
||||
unsafe fn from_abi(js: u32) -> *const T {
|
||||
js as *const T
|
||||
}
|
||||
@ -291,6 +293,7 @@ impl<T> FromWasmAbi for *const T {
|
||||
impl<T> IntoWasmAbi for *mut T {
|
||||
type Abi = u32;
|
||||
|
||||
#[inline]
|
||||
fn into_abi(self) -> u32 {
|
||||
self as u32
|
||||
}
|
||||
@ -299,6 +302,7 @@ impl<T> IntoWasmAbi for *mut T {
|
||||
impl<T> FromWasmAbi for *mut T {
|
||||
type Abi = u32;
|
||||
|
||||
#[inline]
|
||||
unsafe fn from_abi(js: u32) -> *mut T {
|
||||
js as *mut T
|
||||
}
|
||||
@ -346,6 +350,7 @@ impl RefFromWasmAbi for JsValue {
|
||||
impl<T: OptionIntoWasmAbi> IntoWasmAbi for Option<T> {
|
||||
type Abi = T::Abi;
|
||||
|
||||
#[inline]
|
||||
fn into_abi(self) -> T::Abi {
|
||||
match self {
|
||||
None => T::none(),
|
||||
@ -357,6 +362,7 @@ impl<T: OptionIntoWasmAbi> IntoWasmAbi for Option<T> {
|
||||
impl<T: OptionFromWasmAbi> FromWasmAbi for Option<T> {
|
||||
type Abi = T::Abi;
|
||||
|
||||
#[inline]
|
||||
unsafe fn from_abi(js: T::Abi) -> Self {
|
||||
if T::is_none(&js) {
|
||||
None
|
||||
@ -369,6 +375,7 @@ impl<T: OptionFromWasmAbi> FromWasmAbi for Option<T> {
|
||||
impl<T: IntoWasmAbi> IntoWasmAbi for Clamped<T> {
|
||||
type Abi = T::Abi;
|
||||
|
||||
#[inline]
|
||||
fn into_abi(self) -> Self::Abi {
|
||||
self.0.into_abi()
|
||||
}
|
||||
@ -377,6 +384,7 @@ impl<T: IntoWasmAbi> IntoWasmAbi for Clamped<T> {
|
||||
impl<T: FromWasmAbi> FromWasmAbi for Clamped<T> {
|
||||
type Abi = T::Abi;
|
||||
|
||||
#[inline]
|
||||
unsafe fn from_abi(js: T::Abi) -> Self {
|
||||
Clamped(T::from_abi(js))
|
||||
}
|
||||
@ -394,6 +402,7 @@ impl IntoWasmAbi for () {
|
||||
impl<T: IntoWasmAbi> ReturnWasmAbi for Result<T, JsValue> {
|
||||
type Abi = T::Abi;
|
||||
|
||||
#[inline]
|
||||
fn return_abi(self) -> Self::Abi {
|
||||
match self {
|
||||
Ok(v) => v.into_abi(),
|
||||
|
@ -45,6 +45,7 @@ macro_rules! vectors {
|
||||
}
|
||||
|
||||
impl OptionIntoWasmAbi for Box<[$t]> {
|
||||
#[inline]
|
||||
fn none() -> WasmSlice { null_slice() }
|
||||
}
|
||||
|
||||
@ -60,6 +61,7 @@ macro_rules! vectors {
|
||||
}
|
||||
|
||||
impl OptionFromWasmAbi for Box<[$t]> {
|
||||
#[inline]
|
||||
fn is_none(slice: &WasmSlice) -> bool { slice.ptr == 0 }
|
||||
}
|
||||
}
|
||||
@ -77,6 +79,7 @@ macro_rules! vectors {
|
||||
}
|
||||
|
||||
impl<'a> OptionIntoWasmAbi for &'a [$t] {
|
||||
#[inline]
|
||||
fn none() -> WasmSlice { null_slice() }
|
||||
}
|
||||
|
||||
@ -90,6 +93,7 @@ macro_rules! vectors {
|
||||
}
|
||||
|
||||
impl<'a> OptionIntoWasmAbi for &'a mut [$t] {
|
||||
#[inline]
|
||||
fn none() -> WasmSlice { null_slice() }
|
||||
}
|
||||
|
||||
@ -144,24 +148,28 @@ if_std! {
|
||||
impl<T> IntoWasmAbi for Vec<T> where Box<[T]>: IntoWasmAbi<Abi = WasmSlice> {
|
||||
type Abi = <Box<[T]> as IntoWasmAbi>::Abi;
|
||||
|
||||
#[inline]
|
||||
fn into_abi(self) -> Self::Abi {
|
||||
self.into_boxed_slice().into_abi()
|
||||
}
|
||||
}
|
||||
|
||||
impl<T> OptionIntoWasmAbi for Vec<T> where Box<[T]>: IntoWasmAbi<Abi = WasmSlice> {
|
||||
#[inline]
|
||||
fn none() -> WasmSlice { null_slice() }
|
||||
}
|
||||
|
||||
impl<T> FromWasmAbi for Vec<T> where Box<[T]>: FromWasmAbi<Abi = WasmSlice> {
|
||||
type Abi = <Box<[T]> as FromWasmAbi>::Abi;
|
||||
|
||||
#[inline]
|
||||
unsafe fn from_abi(js: Self::Abi) -> Self {
|
||||
<Box<[T]>>::from_abi(js).into()
|
||||
}
|
||||
}
|
||||
|
||||
impl<T> OptionFromWasmAbi for Vec<T> where Box<[T]>: FromWasmAbi<Abi = WasmSlice> {
|
||||
#[inline]
|
||||
fn is_none(abi: &WasmSlice) -> bool { abi.ptr == 0 }
|
||||
}
|
||||
|
||||
@ -177,6 +185,7 @@ if_std! {
|
||||
}
|
||||
|
||||
impl OptionIntoWasmAbi for String {
|
||||
#[inline]
|
||||
fn none() -> Self::Abi { null_slice() }
|
||||
}
|
||||
|
||||
@ -190,6 +199,7 @@ if_std! {
|
||||
}
|
||||
|
||||
impl OptionFromWasmAbi for String {
|
||||
#[inline]
|
||||
fn is_none(slice: &WasmSlice) -> bool { slice.ptr == 0 }
|
||||
}
|
||||
}
|
||||
@ -206,6 +216,7 @@ impl<'a> IntoWasmAbi for &'a str {
|
||||
}
|
||||
|
||||
impl<'a> OptionIntoWasmAbi for &'a str {
|
||||
#[inline]
|
||||
fn none() -> Self::Abi {
|
||||
null_slice()
|
||||
}
|
||||
@ -240,6 +251,7 @@ if_std! {
|
||||
}
|
||||
|
||||
impl OptionIntoWasmAbi for Box<[JsValue]> {
|
||||
#[inline]
|
||||
fn none() -> WasmSlice { null_slice() }
|
||||
}
|
||||
|
||||
@ -255,6 +267,7 @@ if_std! {
|
||||
}
|
||||
|
||||
impl OptionFromWasmAbi for Box<[JsValue]> {
|
||||
#[inline]
|
||||
fn is_none(slice: &WasmSlice) -> bool { slice.ptr == 0 }
|
||||
}
|
||||
}
|
||||
|
@ -121,6 +121,8 @@ pub trait ReturnWasmAbi: WasmDescribe {
|
||||
|
||||
impl<T: IntoWasmAbi> ReturnWasmAbi for T {
|
||||
type Abi = T::Abi;
|
||||
|
||||
#[inline]
|
||||
fn return_abi(self) -> Self::Abi {
|
||||
self.into_abi()
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user