From: Mark Thom Date: Mon, 11 Apr 2022 01:46:34 +0000 (-0600) Subject: stop detecting cycles in compare_pstr_to_string X-Git-Tag: v0.9.1~60 X-Git-Url: https://git.sagredo.dev/?a=commitdiff_plain;h=468088fd6b37dcbd42b5af179a55eff5700379f6;p=scryer-prolog.git stop detecting cycles in compare_pstr_to_string --- diff --git a/src/machine/partial_string.rs b/src/machine/partial_string.rs index 7cf96c7d..b4b3714a 100644 --- a/src/machine/partial_string.rs +++ b/src/machine/partial_string.rs @@ -109,6 +109,12 @@ impl<'a> HeapPStrIter<'a> { self.brent_st.num_steps() } + #[inline] + pub fn chars(mut self) -> PStrCharsIter<'a> { + let item = self.next(); + PStrCharsIter { iter: self, item } + } + pub fn compare_pstr_to_string(&mut self, s: &str) -> Option { let mut result = PStrPrefixCmpResult { focus: self.brent_st.hare, @@ -116,7 +122,10 @@ impl<'a> HeapPStrIter<'a> { prefix_len: 0, }; - while let Some(iteratee) = self.next() { + while let Some(PStrIterStep { iteratee, next_hare }) = self.step(self.brent_st.hare) { + self.brent_st.hare = next_hare; + self.focus = self.heap[next_hare]; + result.focus = iteratee.focus(); result.offset = iteratee.offset(); @@ -164,12 +173,6 @@ impl<'a> HeapPStrIter<'a> { Some(result) } - #[inline] - pub fn chars(mut self) -> PStrCharsIter<'a> { - let item = self.next(); - PStrCharsIter { iter: self, item } - } - fn walk_hare_to_cycle_end(&mut self) { // walk_hare_to_cycle_end assumes a cycle has been found, // so it is always safe to unwrap self.step()