inline store & deref calls in '' (#1176)

This commit is contained in:
Mark Thom
2022-01-26 23:03:19 -07:00
parent 142ddcd57a
commit b3006f6fd8

View File

@@ -211,50 +211,56 @@ impl BrentAlgState {
impl MachineState { impl MachineState {
#[inline(always)] #[inline(always)]
pub fn brents_alg_step(&self, brent_st: &mut BrentAlgState) -> Option<CycleSearchResult> { pub fn brents_alg_step(&self, brent_st: &mut BrentAlgState) -> Option<CycleSearchResult> {
let deref_v = self.deref(self.heap[brent_st.hare]); loop {
let store_v = self.store(deref_v); let store_v = self.heap[brent_st.hare];
if let Some(var) = store_v.as_var() {
return Some(CycleSearchResult::PartialList(brent_st.num_steps(), var));
}
if store_v == empty_list_as_cell!() {
return Some(CycleSearchResult::ProperList(brent_st.num_steps()));
}
read_heap_cell!(store_v, read_heap_cell!(store_v,
(HeapCellValueTag::PStrLoc, h) => { (HeapCellValueTag::PStrLoc, h) => {
brent_st.add_pstr_chars_and_step(&self.heap, h) return brent_st.add_pstr_chars_and_step(&self.heap, h);
} }
(HeapCellValueTag::PStrOffset) => { (HeapCellValueTag::PStrOffset) => {
brent_st.add_pstr_chars_and_step(&self.heap, brent_st.hare) return brent_st.add_pstr_chars_and_step(&self.heap, brent_st.hare);
} }
(HeapCellValueTag::CStr, cstr_atom) => { (HeapCellValueTag::CStr, cstr_atom) => {
let cstr = PartialString::from(cstr_atom); let cstr = PartialString::from(cstr_atom);
brent_st.pstr_chars += cstr.as_str_from(0).chars().count(); brent_st.pstr_chars += cstr.as_str_from(0).chars().count();
Some(CycleSearchResult::ProperList(brent_st.num_steps())) return Some(CycleSearchResult::ProperList(brent_st.num_steps()));
} }
(HeapCellValueTag::Lis, h) => { (HeapCellValueTag::Lis, h) => {
brent_st.step(h+1) return brent_st.step(h+1);
} }
(HeapCellValueTag::Str, s) => { (HeapCellValueTag::Str, s) => {
let (name, arity) = cell_as_atom_cell!(self.heap[s]).get_name_and_arity(); let (name, arity) = cell_as_atom_cell!(self.heap[s]).get_name_and_arity();
if name == atom!(".") && arity == 2 { return if name == atom!(".") && arity == 2 {
brent_st.step(s+2) brent_st.step(s+2)
} else { } else {
Some(CycleSearchResult::NotList) Some(CycleSearchResult::NotList)
};
} }
} (HeapCellValueTag::Atom, (name, arity)) => {
(HeapCellValueTag::Atom, (_name, arity)) => {
debug_assert!(arity == 0); debug_assert!(arity == 0);
return if name == atom!("[]") {
Some(CycleSearchResult::ProperList(brent_st.num_steps()))
} else {
Some(CycleSearchResult::NotList) Some(CycleSearchResult::NotList)
};
}
(HeapCellValueTag::AttrVar | HeapCellValueTag::Var, h) => {
if brent_st.hare == h {
let r = store_v.as_var().unwrap();
return Some(CycleSearchResult::PartialList(brent_st.num_steps(), r));
}
brent_st.hare = h;
} }
_ => { _ => {
Some(CycleSearchResult::NotList) return Some(CycleSearchResult::NotList);
}
);
} }
)
} }
pub fn detect_cycles(&self, value: HeapCellValue) -> CycleSearchResult { pub fn detect_cycles(&self, value: HeapCellValue) -> CycleSearchResult {