replace static Once and two mut statics with one static OnceLock

This commit is contained in:
Bennet Bleßmann
2024-07-06 22:48:04 +02:00
parent 0284a2092d
commit a2a50586aa

View File

@@ -60,6 +60,7 @@ use std::env;
use std::io::Read; use std::io::Read;
use std::path::PathBuf; use std::path::PathBuf;
use std::sync::atomic::AtomicBool; use std::sync::atomic::AtomicBool;
use std::sync::OnceLock;
use self::config::MachineConfig; use self::config::MachineConfig;
use self::parsed_results::*; use self::parsed_results::*;
@@ -1261,34 +1262,26 @@ impl Machine {
#[inline(always)] #[inline(always)]
fn run_cleaners(&mut self) -> bool { fn run_cleaners(&mut self) -> bool {
use std::sync::Once; static CLEANER_INIT: OnceLock<(usize, usize)> = OnceLock::new();
static CLEANER_INIT: Once = Once::new(); let (r_c_w_h, r_c_wo_h) = *CLEANER_INIT.get_or_init(|| {
static mut RCWH: usize = 0;
static mut RCWOH: usize = 0;
let (r_c_w_h, r_c_wo_h) = unsafe {
CLEANER_INIT.call_once(|| {
let r_c_w_h_atom = atom!("run_cleaners_with_handling"); let r_c_w_h_atom = atom!("run_cleaners_with_handling");
let r_c_wo_h_atom = atom!("run_cleaners_without_handling"); let r_c_wo_h_atom = atom!("run_cleaners_without_handling");
let iso_ext = atom!("iso_ext"); let iso_ext = atom!("iso_ext");
RCWH = self let r_c_w_h = self
.indices .indices
.get_predicate_code_index(r_c_w_h_atom, 0, iso_ext) .get_predicate_code_index(r_c_w_h_atom, 0, iso_ext)
.and_then(|item| item.local()) .and_then(|item| item.local())
.unwrap(); .unwrap();
RCWOH = self let r_c_wo_h = self
.indices .indices
.get_predicate_code_index(r_c_wo_h_atom, 1, iso_ext) .get_predicate_code_index(r_c_wo_h_atom, 1, iso_ext)
.and_then(|item| item.local()) .and_then(|item| item.local())
.unwrap(); .unwrap();
(r_c_w_h, r_c_wo_h)
}); });
(RCWH, RCWOH)
};
if let Some(&(_, b_cutoff, prev_block)) = self.machine_st.cont_pts.last() { if let Some(&(_, b_cutoff, prev_block)) = self.machine_st.cont_pts.last() {
if self.machine_st.b < b_cutoff { if self.machine_st.b < b_cutoff {
let (idx, arity) = if self.machine_st.effective_block() > prev_block { let (idx, arity) = if self.machine_st.effective_block() > prev_block {