This is faster than `str::ends_with` for small strings. See for more details.
(haystack: &str, needle: &str, byte_eq_kernel: impl Fn((&u8, &u8)) -> bool)
| 218 | /// This is faster than `str::ends_with` for small strings. |
| 219 | /// See <https://github.com/apache/arrow-rs/issues/6107> for more details. |
| 220 | fn ends_with(haystack: &str, needle: &str, byte_eq_kernel: impl Fn((&u8, &u8)) -> bool) -> bool { |
| 221 | if needle.len() > haystack.len() { |
| 222 | false |
| 223 | } else { |
| 224 | zip( |
| 225 | haystack.as_bytes().iter().rev(), |
| 226 | needle.as_bytes().iter().rev(), |
| 227 | ) |
| 228 | .all(byte_eq_kernel) |
| 229 | } |
| 230 | } |
| 231 | |
| 232 | fn equals_kernel((n, h): (&u8, &u8)) -> bool { |
| 233 | n == h |