Resolve lints and format
This commit is contained in:
@@ -34,10 +34,10 @@ impl From<Atom> for PartialString {
|
||||
}
|
||||
}
|
||||
|
||||
impl Into<Atom> for PartialString {
|
||||
impl From<PartialString> for Atom {
|
||||
#[inline]
|
||||
fn into(self: Self) -> Atom {
|
||||
self.0
|
||||
fn from(val: PartialString) -> Self {
|
||||
val.0
|
||||
}
|
||||
}
|
||||
|
||||
@@ -45,7 +45,7 @@ impl PartialString {
|
||||
#[inline]
|
||||
pub(super) fn new<'a>(src: &'a str, atom_tbl: &AtomTable) -> Option<(Self, &'a str)> {
|
||||
let terminator_idx = scan_for_terminator(src.chars());
|
||||
let pstr = PartialString(AtomTable::build_with(&atom_tbl, &src[..terminator_idx]));
|
||||
let pstr = PartialString(AtomTable::build_with(atom_tbl, &src[..terminator_idx]));
|
||||
Some(if terminator_idx < src.as_bytes().len() {
|
||||
(pstr, &src[terminator_idx + 1..])
|
||||
} else {
|
||||
@@ -154,13 +154,13 @@ impl<'a> HeapPStrIter<'a> {
|
||||
let s = &s[result.prefix_len..];
|
||||
|
||||
if s.len() >= t.len() {
|
||||
if (&*s).starts_with(&*t) {
|
||||
if s.starts_with(&*t) {
|
||||
result.prefix_len += t.len();
|
||||
result.offset += t.len();
|
||||
} else {
|
||||
return None;
|
||||
}
|
||||
} else if t.starts_with(&s) {
|
||||
} else if t.starts_with(s) {
|
||||
result.prefix_len += s.len();
|
||||
result.offset += s.len();
|
||||
|
||||
@@ -218,10 +218,11 @@ impl<'a> HeapPStrIter<'a> {
|
||||
self.brent_st.hare = orig_hare;
|
||||
}
|
||||
|
||||
#[allow(clippy::inherent_to_string)]
|
||||
pub fn to_string(&mut self) -> String {
|
||||
let mut buf = String::with_capacity(32);
|
||||
|
||||
while let Some(iteratee) = self.next() {
|
||||
for iteratee in self.by_ref() {
|
||||
match iteratee {
|
||||
PStrIteratee::Char(_, c) => {
|
||||
buf.push(c);
|
||||
@@ -334,14 +335,10 @@ impl<'a> HeapPStrIter<'a> {
|
||||
heap_bound_deref(self.heap, self.heap[h]),
|
||||
);
|
||||
|
||||
return if let Some(c) = value.as_char() {
|
||||
Some(PStrIterStep {
|
||||
return value.as_char().map(|c| PStrIterStep {
|
||||
iteratee: PStrIteratee::Char(curr_hare, c),
|
||||
next_hare: h+1,
|
||||
})
|
||||
} else {
|
||||
None
|
||||
};
|
||||
});
|
||||
}
|
||||
(HeapCellValueTag::Str, s) => {
|
||||
let (name, arity) = cell_as_atom_cell!(self.heap[s])
|
||||
@@ -353,14 +350,10 @@ impl<'a> HeapPStrIter<'a> {
|
||||
heap_bound_deref(self.heap, self.heap[s+1]),
|
||||
);
|
||||
|
||||
if let Some(c) = value.as_char() {
|
||||
Some(PStrIterStep {
|
||||
value.as_char().map(|c| PStrIterStep {
|
||||
iteratee: PStrIteratee::Char(curr_hare, c),
|
||||
next_hare: s+2,
|
||||
})
|
||||
} else {
|
||||
None
|
||||
}
|
||||
} else {
|
||||
None
|
||||
};
|
||||
@@ -405,10 +398,7 @@ impl<'a> HeapPStrIter<'a> {
|
||||
|
||||
match self.brent_st.step(next_hare) {
|
||||
Some(cycle_result) => {
|
||||
debug_assert!(match cycle_result {
|
||||
CycleSearchResult::Cyclic(..) => true,
|
||||
_ => false,
|
||||
});
|
||||
debug_assert!(matches!(cycle_result, CycleSearchResult::Cyclic(..)));
|
||||
|
||||
self.walk_hare_to_cycle_end();
|
||||
self.stepper = HeapPStrIter::post_cycle_discovery_stepper;
|
||||
@@ -550,11 +540,7 @@ pub enum PStrCmpResult {
|
||||
impl PStrCmpResult {
|
||||
#[inline]
|
||||
pub fn is_second_iter(&self) -> bool {
|
||||
if let PStrCmpResult::SecondIterContinuable(_) = self {
|
||||
true
|
||||
} else {
|
||||
false
|
||||
}
|
||||
matches!(self, PStrCmpResult::SecondIterContinuable(_))
|
||||
}
|
||||
}
|
||||
|
||||
@@ -600,8 +586,8 @@ pub fn compare_pstr_prefixes<'a>(
|
||||
return PStrCmpResult::Ordered(c1.cmp(&c2));
|
||||
}
|
||||
|
||||
cycle_detection_step(i1, i2, &step_1);
|
||||
let both_cyclic = cycle_detection_step(i2, i1, &step_2);
|
||||
cycle_detection_step(i1, i2, step_1);
|
||||
let both_cyclic = cycle_detection_step(i2, i1, step_2);
|
||||
|
||||
r1 = step(i1, i1.brent_st.hare);
|
||||
r2 = step(i2, i2.brent_st.hare);
|
||||
@@ -623,15 +609,15 @@ pub fn compare_pstr_prefixes<'a>(
|
||||
if n1 < pstr_atom.len() {
|
||||
step_2.iteratee = PStrIteratee::PStrSegment(f2, pstr_atom, n1);
|
||||
|
||||
let c1_result = cycle_detection_step(i1, i2, &step_1);
|
||||
let c1_result = cycle_detection_step(i1, i2, step_1);
|
||||
r1 = step(i1, i1.brent_st.hare);
|
||||
|
||||
if !c1_result {
|
||||
continue;
|
||||
}
|
||||
} else {
|
||||
cycle_detection_step(i1, i2, &step_1);
|
||||
let both_cyclic = cycle_detection_step(i2, i1, &step_2);
|
||||
cycle_detection_step(i1, i2, step_1);
|
||||
let both_cyclic = cycle_detection_step(i2, i1, step_2);
|
||||
|
||||
r1 = step(i1, i1.brent_st.hare);
|
||||
r2 = step(i2, i2.brent_st.hare);
|
||||
@@ -641,7 +627,7 @@ pub fn compare_pstr_prefixes<'a>(
|
||||
}
|
||||
}
|
||||
} else {
|
||||
let c2_result = cycle_detection_step(i2, i1, &step_2);
|
||||
let c2_result = cycle_detection_step(i2, i1, step_2);
|
||||
r2 = step(i2, i2.brent_st.hare);
|
||||
|
||||
if !c2_result {
|
||||
@@ -662,15 +648,15 @@ pub fn compare_pstr_prefixes<'a>(
|
||||
if n1 < pstr_atom.len() {
|
||||
step_1.iteratee = PStrIteratee::PStrSegment(f1, pstr_atom, n1);
|
||||
|
||||
let c2_result = cycle_detection_step(i2, i1, &step_2);
|
||||
let c2_result = cycle_detection_step(i2, i1, step_2);
|
||||
r2 = step(i2, step_2.next_hare);
|
||||
|
||||
if !c2_result {
|
||||
continue;
|
||||
}
|
||||
} else {
|
||||
cycle_detection_step(i1, i2, &step_1);
|
||||
let both_cyclic = cycle_detection_step(i2, i1, &step_2);
|
||||
cycle_detection_step(i1, i2, step_1);
|
||||
let both_cyclic = cycle_detection_step(i2, i1, step_2);
|
||||
|
||||
r1 = step(i1, i1.brent_st.hare);
|
||||
r2 = step(i2, i2.brent_st.hare);
|
||||
@@ -680,7 +666,7 @@ pub fn compare_pstr_prefixes<'a>(
|
||||
}
|
||||
}
|
||||
} else {
|
||||
let c1_result = cycle_detection_step(i1, i2, &step_1);
|
||||
let c1_result = cycle_detection_step(i1, i2, step_1);
|
||||
r1 = step(i1, i1.brent_st.hare);
|
||||
|
||||
if !c1_result {
|
||||
@@ -693,8 +679,8 @@ pub fn compare_pstr_prefixes<'a>(
|
||||
PStrIteratee::PStrSegment(f2, pstr2_atom, n2),
|
||||
) => {
|
||||
if pstr1_atom == pstr2_atom && n1 == n2 {
|
||||
cycle_detection_step(i1, i2, &step_1);
|
||||
let both_cyclic = cycle_detection_step(i2, i1, &step_2);
|
||||
cycle_detection_step(i1, i2, step_1);
|
||||
let both_cyclic = cycle_detection_step(i2, i1, step_2);
|
||||
|
||||
r1 = step(i1, i1.brent_st.hare);
|
||||
r2 = step(i2, i2.brent_st.hare);
|
||||
@@ -713,9 +699,9 @@ pub fn compare_pstr_prefixes<'a>(
|
||||
let str2 = pstr2.as_str_from(n2);
|
||||
|
||||
match str1.len().cmp(&str2.len()) {
|
||||
Ordering::Equal if &*str1 == &*str2 => {
|
||||
cycle_detection_step(i1, i2, &step_1);
|
||||
let both_cyclic = cycle_detection_step(i2, i1, &step_2);
|
||||
Ordering::Equal if *str1 == *str2 => {
|
||||
cycle_detection_step(i1, i2, step_1);
|
||||
let both_cyclic = cycle_detection_step(i2, i1, step_2);
|
||||
|
||||
r1 = step(i1, i1.brent_st.hare);
|
||||
r2 = step(i2, i2.brent_st.hare);
|
||||
@@ -727,7 +713,7 @@ pub fn compare_pstr_prefixes<'a>(
|
||||
Ordering::Less if str2.starts_with(&*str1) => {
|
||||
step_2.iteratee =
|
||||
PStrIteratee::PStrSegment(f2, pstr2_atom, n2 + str1.len());
|
||||
let c1_result = cycle_detection_step(i1, i2, &step_1);
|
||||
let c1_result = cycle_detection_step(i1, i2, step_1);
|
||||
r1 = step(i1, i1.brent_st.hare);
|
||||
|
||||
if !c1_result {
|
||||
@@ -737,7 +723,7 @@ pub fn compare_pstr_prefixes<'a>(
|
||||
Ordering::Greater if str1.starts_with(&*str2) => {
|
||||
step_1.iteratee =
|
||||
PStrIteratee::PStrSegment(f1, pstr1_atom, n1 + str2.len());
|
||||
let c2_result = cycle_detection_step(i2, i1, &step_2);
|
||||
let c2_result = cycle_detection_step(i2, i1, step_2);
|
||||
r2 = step(i2, i2.brent_st.hare);
|
||||
|
||||
if !c2_result {
|
||||
@@ -786,12 +772,10 @@ pub fn compare_pstr_prefixes<'a>(
|
||||
} else {
|
||||
PStrCmpResult::FirstIterContinuable(r1.unwrap().iteratee)
|
||||
}
|
||||
} else if i1.is_continuable() && i2.is_continuable() {
|
||||
PStrCmpResult::Ordered(Ordering::Equal)
|
||||
} else {
|
||||
if i1.is_continuable() && i2.is_continuable() {
|
||||
PStrCmpResult::Ordered(Ordering::Equal)
|
||||
} else {
|
||||
PStrCmpResult::Unordered
|
||||
}
|
||||
PStrCmpResult::Unordered
|
||||
}
|
||||
}
|
||||
|
||||
@@ -885,7 +869,7 @@ mod test {
|
||||
{
|
||||
let mut iter = HeapPStrIter::new(&wam.machine_st.heap, 0);
|
||||
|
||||
while let Some(_) = iter.next() {}
|
||||
for _ in iter.by_ref() {}
|
||||
|
||||
assert!(!iter.at_string_terminator());
|
||||
}
|
||||
@@ -1009,7 +993,7 @@ mod test {
|
||||
|
||||
unify!(wam.machine_st, cstr_var_cell, heap_loc_as_cell!(1));
|
||||
|
||||
assert_eq!(wam.machine_st.fail, false);
|
||||
assert!(!wam.machine_st.fail);
|
||||
|
||||
assert_eq!(wam.machine_st.heap[2], char_as_cell!('a'),);
|
||||
|
||||
@@ -1032,7 +1016,7 @@ mod test {
|
||||
|
||||
unify!(wam.machine_st, cstr_var_cell, heap_loc_as_cell!(1));
|
||||
|
||||
assert_eq!(wam.machine_st.fail, false);
|
||||
assert!(!wam.machine_st.fail);
|
||||
|
||||
// test "abc" = [X,b,Z].
|
||||
|
||||
@@ -1054,7 +1038,7 @@ mod test {
|
||||
|
||||
unify!(wam.machine_st, cstr_var_cell, heap_loc_as_cell!(1));
|
||||
|
||||
assert_eq!(wam.machine_st.fail, false);
|
||||
assert!(!wam.machine_st.fail);
|
||||
|
||||
assert_eq!(wam.machine_st.heap[2], char_as_cell!('a'),);
|
||||
|
||||
@@ -1075,7 +1059,7 @@ mod test {
|
||||
|
||||
print_heap_terms(wam.machine_st.heap.iter(), 0);
|
||||
|
||||
assert_eq!(wam.machine_st.fail, false);
|
||||
assert!(!wam.machine_st.fail);
|
||||
|
||||
assert_eq!(wam.machine_st.heap[2], pstr_loc_as_cell!(5));
|
||||
assert_eq!(wam.machine_st.heap[3], pstr_loc_as_cell!(1));
|
||||
@@ -1107,7 +1091,7 @@ mod test {
|
||||
|
||||
// assert!(iter.next().is_none());
|
||||
|
||||
while let Some(_) = iter.next() {}
|
||||
for _ in iter {}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user