mirror of
https://github.com/RustPython/RustPython.git
synced 2026-06-02 19:39:49 +09:00
Switch to const-initialized thread_local variables where appropriate
This commit is contained in:
@@ -56,7 +56,9 @@ mod non_threading {
|
||||
$($(#[$attr])*
|
||||
$vis static $name: $crate::static_cell::StaticCell<$t> = {
|
||||
::std::thread_local! {
|
||||
$vis static $name: $crate::lock::OnceCell<&'static $t> = $crate::lock::OnceCell::new();
|
||||
$vis static $name: $crate::lock::OnceCell<&'static $t> = const {
|
||||
$crate::lock::OnceCell::new()
|
||||
};
|
||||
}
|
||||
$crate::static_cell::StaticCell::_from_local_key(&$name)
|
||||
};)+
|
||||
|
||||
@@ -486,7 +486,10 @@ pub mod levenshtein {
|
||||
|
||||
pub fn levenshtein_distance(a: &str, b: &str, max_cost: usize) -> usize {
|
||||
thread_local! {
|
||||
static BUFFER: RefCell<[usize; MAX_STRING_SIZE]> = const { RefCell::new([0usize; MAX_STRING_SIZE]) };
|
||||
#[allow(clippy::declare_interior_mutable_const)]
|
||||
static BUFFER: RefCell<[usize; MAX_STRING_SIZE]> = const {
|
||||
RefCell::new([0usize; MAX_STRING_SIZE])
|
||||
};
|
||||
}
|
||||
|
||||
if a == b {
|
||||
|
||||
@@ -355,7 +355,9 @@ pub(crate) mod _thread {
|
||||
Err(vm.new_exception_empty(vm.ctx.exceptions.system_exit.to_owned()))
|
||||
}
|
||||
|
||||
thread_local!(static SENTINELS: RefCell<Vec<PyRef<Lock>>> = RefCell::default());
|
||||
thread_local! {
|
||||
static SENTINELS: RefCell<Vec<PyRef<Lock>>> = const { RefCell::new(Vec::new()) };
|
||||
}
|
||||
|
||||
#[pyfunction]
|
||||
fn _set_sentinel(vm: &VirtualMachine) -> PyRef<Lock> {
|
||||
|
||||
@@ -86,7 +86,9 @@ pub fn add_init_func(f: fn(&mut VirtualMachine)) {
|
||||
// https://rustwasm.github.io/2018/10/24/multithreading-rust-and-wasm.html#atomic-instructions
|
||||
thread_local! {
|
||||
static STORED_VMS: RefCell<HashMap<String, Rc<StoredVirtualMachine>>> = RefCell::default();
|
||||
static VM_INIT_FUNCS: RefCell<Vec<fn(&mut VirtualMachine)>> = RefCell::default();
|
||||
static VM_INIT_FUNCS: RefCell<Vec<fn(&mut VirtualMachine)>> = const {
|
||||
RefCell::new(Vec::new())
|
||||
};
|
||||
}
|
||||
|
||||
pub fn get_vm_id(vm: &VirtualMachine) -> &str {
|
||||
|
||||
Reference in New Issue
Block a user