Avoid invoking a function pointer with JsStatic

The previous codegen wasn't enough to convince LLVM that the function pointer
was a constant value and could be aggressively inlined, so this updates the
`JsStatic` internals slightly to guarantee to LLVM that the function pointer is
constant and no dynamic dispatch is needed after all
This commit is contained in:
Alex Crichton 2018-04-21 13:14:33 -07:00
parent 947386ee57
commit 4436c0eae6
2 changed files with 5 additions and 3 deletions

View File

@ -779,8 +779,10 @@ impl ToTokens for ast::ImportStatic {
}
}
static mut _VAL: ::wasm_bindgen::__rt::core::cell::UnsafeCell<Option<#ty>> =
::wasm_bindgen::__rt::core::cell::UnsafeCell::new(None);
::wasm_bindgen::JsStatic {
__inner: ::wasm_bindgen::__rt::core::cell::UnsafeCell::new(None),
__inner: unsafe { &_VAL },
__init: init,
}
};

View File

@ -303,9 +303,9 @@ impl Drop for JsValue {
///
/// This type implements `Deref` to the inner type so it's typically used as if
/// it were `&T`.
pub struct JsStatic<T> {
pub struct JsStatic<T: 'static> {
#[doc(hidden)]
pub __inner: UnsafeCell<Option<T>>,
pub __inner: &'static UnsafeCell<Option<T>>,
#[doc(hidden)]
pub __init: fn() -> T,
}