Skip to content

Commit 3348ece

Browse files
committed
rustfmt src/anyref.rs
1 parent 450c923 commit 3348ece

File tree

1 file changed

+28
-35
lines changed

1 file changed

+28
-35
lines changed

src/anyref.rs

Lines changed: 28 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
1-
use std::slice;
2-
use std::vec::Vec;
3-
use std::ptr;
41
use std::alloc::{self, Layout};
52
use std::mem;
3+
use std::ptr;
4+
use std::slice;
5+
use std::vec::Vec;
66

77
use crate::JsValue;
88

@@ -34,9 +34,7 @@ impl Slab {
3434
if ret == self.data.len() {
3535
if self.data.len() == self.data.capacity() {
3636
let extra = 128;
37-
let r = unsafe {
38-
__wbindgen_anyref_table_grow(extra)
39-
};
37+
let r = unsafe { __wbindgen_anyref_table_grow(extra) };
4038
if r == -1 {
4139
internal_error("table grow failure")
4240
}
@@ -59,16 +57,8 @@ impl Slab {
5957
if ptr.is_null() {
6058
internal_error("allocation failure");
6159
}
62-
ptr::copy_nonoverlapping(
63-
self.data.as_ptr(),
64-
ptr,
65-
self.data.len(),
66-
);
67-
let new_vec = Vec::from_raw_parts(
68-
ptr,
69-
self.data.len(),
70-
new_cap,
71-
);
60+
ptr::copy_nonoverlapping(self.data.as_ptr(), ptr, self.data.len());
61+
let new_vec = Vec::from_raw_parts(ptr, self.data.len(), new_cap);
7262
let mut old = mem::replace(&mut self.data, new_vec);
7363
old.set_len(0);
7464
}
@@ -149,19 +139,19 @@ fn internal_error(msg: &str) -> ! {
149139
// implementation that will be replaced once #55518 lands on stable.
150140
#[cfg(target_feature = "atomics")]
151141
mod tl {
152-
use std::*; // hack to get `thread_local!` to work
153142
use super::Slab;
154143
use std::cell::Cell;
144+
use std::*; // hack to get `thread_local!` to work
155145

156146
thread_local!(pub static HEAP_SLAB: Cell<Slab> = Cell::new(Slab::new()));
157147
}
158148

159149
#[cfg(not(target_feature = "atomics"))]
160150
mod tl {
151+
use super::Slab;
161152
use std::alloc::{self, Layout};
162153
use std::cell::Cell;
163154
use std::ptr;
164-
use super::Slab;
165155

166156
pub struct HeapSlab;
167157
pub static HEAP_SLAB: HeapSlab = HeapSlab;
@@ -186,34 +176,38 @@ mod tl {
186176
}
187177

188178
#[no_mangle]
189-
pub extern fn __wbindgen_anyref_table_alloc() -> usize {
190-
tl::HEAP_SLAB.try_with(|slot| {
191-
let mut slab = slot.replace(Slab::new());
192-
let ret = slab.alloc();
193-
slot.replace(slab);
194-
ret
195-
}).unwrap_or_else(|_| internal_error("tls access failure"))
179+
pub extern "C" fn __wbindgen_anyref_table_alloc() -> usize {
180+
tl::HEAP_SLAB
181+
.try_with(|slot| {
182+
let mut slab = slot.replace(Slab::new());
183+
let ret = slab.alloc();
184+
slot.replace(slab);
185+
ret
186+
})
187+
.unwrap_or_else(|_| internal_error("tls access failure"))
196188
}
197189

198190
#[no_mangle]
199-
pub extern fn __wbindgen_anyref_table_dealloc(idx: usize) {
191+
pub extern "C" fn __wbindgen_anyref_table_dealloc(idx: usize) {
200192
if idx < super::JSIDX_RESERVED as usize {
201-
return
193+
return;
202194
}
203195
// clear this value from the table so while the table slot is un-allocated
204196
// we don't keep around a strong reference to a potentially large object
205197
unsafe {
206198
__wbindgen_anyref_table_set_null(idx);
207199
}
208-
tl::HEAP_SLAB.try_with(|slot| {
209-
let mut slab = slot.replace(Slab::new());
210-
slab.dealloc(idx);
211-
slot.replace(slab);
212-
}).unwrap_or_else(|_| internal_error("tls access failure"))
200+
tl::HEAP_SLAB
201+
.try_with(|slot| {
202+
let mut slab = slot.replace(Slab::new());
203+
slab.dealloc(idx);
204+
slot.replace(slab);
205+
})
206+
.unwrap_or_else(|_| internal_error("tls access failure"))
213207
}
214208

215209
#[no_mangle]
216-
pub unsafe extern fn __wbindgen_drop_anyref_slice(ptr: *mut JsValue, len: usize) {
210+
pub unsafe extern "C" fn __wbindgen_drop_anyref_slice(ptr: *mut JsValue, len: usize) {
217211
for slot in slice::from_raw_parts_mut(ptr, len) {
218212
__wbindgen_anyref_table_dealloc(slot.idx as usize);
219213
}
@@ -235,5 +229,4 @@ pub unsafe extern "C" fn __wbindgen_anyref_heap_live_count_impl() -> u32 {
235229

236230
// see comment in module above this in `link_mem_intrinsics`
237231
#[inline(never)]
238-
pub fn link_intrinsics() {
239-
}
232+
pub fn link_intrinsics() {}

0 commit comments

Comments
 (0)