Skip to content

Commit 68af85d

Browse files
committed
Ensure that various Into/From ABI methods are inlined
1 parent 908fc61 commit 68af85d

File tree

3 files changed

+24
-0
lines changed

3 files changed

+24
-0
lines changed

src/convert/impls.rs

+9
Original file line numberDiff line numberDiff line change
@@ -275,6 +275,7 @@ impl OptionFromWasmAbi for char {
275275
impl<T> IntoWasmAbi for *const T {
276276
type Abi = u32;
277277

278+
#[inline]
278279
fn into_abi(self) -> u32 {
279280
self as u32
280281
}
@@ -283,6 +284,7 @@ impl<T> IntoWasmAbi for *const T {
283284
impl<T> FromWasmAbi for *const T {
284285
type Abi = u32;
285286

287+
#[inline]
286288
unsafe fn from_abi(js: u32) -> *const T {
287289
js as *const T
288290
}
@@ -291,6 +293,7 @@ impl<T> FromWasmAbi for *const T {
291293
impl<T> IntoWasmAbi for *mut T {
292294
type Abi = u32;
293295

296+
#[inline]
294297
fn into_abi(self) -> u32 {
295298
self as u32
296299
}
@@ -299,6 +302,7 @@ impl<T> IntoWasmAbi for *mut T {
299302
impl<T> FromWasmAbi for *mut T {
300303
type Abi = u32;
301304

305+
#[inline]
302306
unsafe fn from_abi(js: u32) -> *mut T {
303307
js as *mut T
304308
}
@@ -346,6 +350,7 @@ impl RefFromWasmAbi for JsValue {
346350
impl<T: OptionIntoWasmAbi> IntoWasmAbi for Option<T> {
347351
type Abi = T::Abi;
348352

353+
#[inline]
349354
fn into_abi(self) -> T::Abi {
350355
match self {
351356
None => T::none(),
@@ -357,6 +362,7 @@ impl<T: OptionIntoWasmAbi> IntoWasmAbi for Option<T> {
357362
impl<T: OptionFromWasmAbi> FromWasmAbi for Option<T> {
358363
type Abi = T::Abi;
359364

365+
#[inline]
360366
unsafe fn from_abi(js: T::Abi) -> Self {
361367
if T::is_none(&js) {
362368
None
@@ -369,6 +375,7 @@ impl<T: OptionFromWasmAbi> FromWasmAbi for Option<T> {
369375
impl<T: IntoWasmAbi> IntoWasmAbi for Clamped<T> {
370376
type Abi = T::Abi;
371377

378+
#[inline]
372379
fn into_abi(self) -> Self::Abi {
373380
self.0.into_abi()
374381
}
@@ -377,6 +384,7 @@ impl<T: IntoWasmAbi> IntoWasmAbi for Clamped<T> {
377384
impl<T: FromWasmAbi> FromWasmAbi for Clamped<T> {
378385
type Abi = T::Abi;
379386

387+
#[inline]
380388
unsafe fn from_abi(js: T::Abi) -> Self {
381389
Clamped(T::from_abi(js))
382390
}
@@ -394,6 +402,7 @@ impl IntoWasmAbi for () {
394402
impl<T: IntoWasmAbi> ReturnWasmAbi for Result<T, JsValue> {
395403
type Abi = T::Abi;
396404

405+
#[inline]
397406
fn return_abi(self) -> Self::Abi {
398407
match self {
399408
Ok(v) => v.into_abi(),

src/convert/slices.rs

+13
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ macro_rules! vectors {
4545
}
4646

4747
impl OptionIntoWasmAbi for Box<[$t]> {
48+
#[inline]
4849
fn none() -> WasmSlice { null_slice() }
4950
}
5051

@@ -60,6 +61,7 @@ macro_rules! vectors {
6061
}
6162

6263
impl OptionFromWasmAbi for Box<[$t]> {
64+
#[inline]
6365
fn is_none(slice: &WasmSlice) -> bool { slice.ptr == 0 }
6466
}
6567
}
@@ -77,6 +79,7 @@ macro_rules! vectors {
7779
}
7880

7981
impl<'a> OptionIntoWasmAbi for &'a [$t] {
82+
#[inline]
8083
fn none() -> WasmSlice { null_slice() }
8184
}
8285

@@ -90,6 +93,7 @@ macro_rules! vectors {
9093
}
9194

9295
impl<'a> OptionIntoWasmAbi for &'a mut [$t] {
96+
#[inline]
9397
fn none() -> WasmSlice { null_slice() }
9498
}
9599

@@ -144,24 +148,28 @@ if_std! {
144148
impl<T> IntoWasmAbi for Vec<T> where Box<[T]>: IntoWasmAbi<Abi = WasmSlice> {
145149
type Abi = <Box<[T]> as IntoWasmAbi>::Abi;
146150

151+
#[inline]
147152
fn into_abi(self) -> Self::Abi {
148153
self.into_boxed_slice().into_abi()
149154
}
150155
}
151156

152157
impl<T> OptionIntoWasmAbi for Vec<T> where Box<[T]>: IntoWasmAbi<Abi = WasmSlice> {
158+
#[inline]
153159
fn none() -> WasmSlice { null_slice() }
154160
}
155161

156162
impl<T> FromWasmAbi for Vec<T> where Box<[T]>: FromWasmAbi<Abi = WasmSlice> {
157163
type Abi = <Box<[T]> as FromWasmAbi>::Abi;
158164

165+
#[inline]
159166
unsafe fn from_abi(js: Self::Abi) -> Self {
160167
<Box<[T]>>::from_abi(js).into()
161168
}
162169
}
163170

164171
impl<T> OptionFromWasmAbi for Vec<T> where Box<[T]>: FromWasmAbi<Abi = WasmSlice> {
172+
#[inline]
165173
fn is_none(abi: &WasmSlice) -> bool { abi.ptr == 0 }
166174
}
167175

@@ -177,6 +185,7 @@ if_std! {
177185
}
178186

179187
impl OptionIntoWasmAbi for String {
188+
#[inline]
180189
fn none() -> Self::Abi { null_slice() }
181190
}
182191

@@ -190,6 +199,7 @@ if_std! {
190199
}
191200

192201
impl OptionFromWasmAbi for String {
202+
#[inline]
193203
fn is_none(slice: &WasmSlice) -> bool { slice.ptr == 0 }
194204
}
195205
}
@@ -206,6 +216,7 @@ impl<'a> IntoWasmAbi for &'a str {
206216
}
207217

208218
impl<'a> OptionIntoWasmAbi for &'a str {
219+
#[inline]
209220
fn none() -> Self::Abi {
210221
null_slice()
211222
}
@@ -240,6 +251,7 @@ if_std! {
240251
}
241252

242253
impl OptionIntoWasmAbi for Box<[JsValue]> {
254+
#[inline]
243255
fn none() -> WasmSlice { null_slice() }
244256
}
245257

@@ -255,6 +267,7 @@ if_std! {
255267
}
256268

257269
impl OptionFromWasmAbi for Box<[JsValue]> {
270+
#[inline]
258271
fn is_none(slice: &WasmSlice) -> bool { slice.ptr == 0 }
259272
}
260273
}

src/convert/traits.rs

+2
Original file line numberDiff line numberDiff line change
@@ -121,6 +121,8 @@ pub trait ReturnWasmAbi: WasmDescribe {
121121

122122
impl<T: IntoWasmAbi> ReturnWasmAbi for T {
123123
type Abi = T::Abi;
124+
125+
#[inline]
124126
fn return_abi(self) -> Self::Abi {
125127
self.into_abi()
126128
}

0 commit comments

Comments
 (0)