Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit a11aad6

Browse filesBrowse files
coolreader18youknowone
authored andcommitted
Switch to const-initialized thread_local variables where appropriate
1 parent d7113e1 commit a11aad6
Copy full SHA for a11aad6

File tree

4 files changed

+13
-4
lines changed
Filter options

4 files changed

+13
-4
lines changed

‎common/src/static_cell.rs

Copy file name to clipboardExpand all lines: common/src/static_cell.rs
+3-1Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,9 @@ mod non_threading {
5656
$($(#[$attr])*
5757
$vis static $name: $crate::static_cell::StaticCell<$t> = {
5858
::std::thread_local! {
59-
$vis static $name: $crate::lock::OnceCell<&'static $t> = $crate::lock::OnceCell::new();
59+
$vis static $name: $crate::lock::OnceCell<&'static $t> = const {
60+
$crate::lock::OnceCell::new()
61+
};
6062
}
6163
$crate::static_cell::StaticCell::_from_local_key(&$name)
6264
};)+

‎common/src/str.rs

Copy file name to clipboardExpand all lines: common/src/str.rs
+4-1Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -486,7 +486,10 @@ pub mod levenshtein {
486486

487487
pub fn levenshtein_distance(a: &str, b: &str, max_cost: usize) -> usize {
488488
thread_local! {
489-
static BUFFER: RefCell<[usize; MAX_STRING_SIZE]> = const { RefCell::new([0usize; MAX_STRING_SIZE]) };
489+
#[allow(clippy::declare_interior_mutable_const)]
490+
static BUFFER: RefCell<[usize; MAX_STRING_SIZE]> = const {
491+
RefCell::new([0usize; MAX_STRING_SIZE])
492+
};
490493
}
491494

492495
if a == b {

‎vm/src/stdlib/thread.rs

Copy file name to clipboardExpand all lines: vm/src/stdlib/thread.rs
+3-1Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -355,7 +355,9 @@ pub(crate) mod _thread {
355355
Err(vm.new_exception_empty(vm.ctx.exceptions.system_exit.to_owned()))
356356
}
357357

358-
thread_local!(static SENTINELS: RefCell<Vec<PyRef<Lock>>> = RefCell::default());
358+
thread_local! {
359+
static SENTINELS: RefCell<Vec<PyRef<Lock>>> = const { RefCell::new(Vec::new()) };
360+
}
359361

360362
#[pyfunction]
361363
fn _set_sentinel(vm: &VirtualMachine) -> PyRef<Lock> {

‎wasm/lib/src/vm_class.rs

Copy file name to clipboardExpand all lines: wasm/lib/src/vm_class.rs
+3-1Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,9 @@ pub fn add_init_func(f: fn(&mut VirtualMachine)) {
8686
// https://rustwasm.github.io/2018/10/24/multithreading-rust-and-wasm.html#atomic-instructions
8787
thread_local! {
8888
static STORED_VMS: RefCell<HashMap<String, Rc<StoredVirtualMachine>>> = RefCell::default();
89-
static VM_INIT_FUNCS: RefCell<Vec<fn(&mut VirtualMachine)>> = RefCell::default();
89+
static VM_INIT_FUNCS: RefCell<Vec<fn(&mut VirtualMachine)>> = const {
90+
RefCell::new(Vec::new())
91+
};
9092
}
9193

9294
pub fn get_vm_id(vm: &VirtualMachine) -> &str {

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.