diff --git a/rust/sublist/src/lib.rs b/rust/sublist/src/lib.rs index ce403af..977d16e 100644 --- a/rust/sublist/src/lib.rs +++ b/rust/sublist/src/lib.rs @@ -8,13 +8,7 @@ pub enum Comparison { pub fn sublist(first: &[T], second: &[T]) -> Comparison { let is_sublist = |first: &[_], second: &[_]| { - second - .iter() - .enumerate() - .map(|(i, _)| &second[i..]) - .take_while(|suffix| first.len() <= suffix.len()) - .map(|suffix| &suffix[..first.len()]) - .any(|sublist| first == sublist) + first.is_empty() || second.windows(first.len()).any(|window| first == window) }; if first == second { Comparison::Equal