Skip to content

Commit

Permalink
add comments
Browse files Browse the repository at this point in the history
  • Loading branch information
samuelcolvin committed Jul 28, 2024
1 parent 02dd628 commit 8cc373b
Showing 1 changed file with 7 additions and 2 deletions.
9 changes: 7 additions & 2 deletions arrow-string/src/predicate.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ use arrow_array::{ArrayAccessor, BooleanArray};
use arrow_schema::ArrowError;
use memchr::memchr2;
use regex::{Regex, RegexBuilder};
use std::iter::zip;

/// A string based predicate
pub enum Predicate<'a> {
Expand Down Expand Up @@ -130,19 +131,23 @@ impl<'a> Predicate<'a> {
}
}

/// This is faster than `str::starts_with` for small strings.
/// See <https://github.com/apache/arrow-rs/issues/6107> for more details.
fn starts_with(haystack: &str, needle: &str, byte_eq_kernel: impl Fn((&u8, &u8)) -> bool) -> bool {
if needle.len() > haystack.len() {
false
} else {
std::iter::zip(haystack.as_bytes(), needle.as_bytes()).all(byte_eq_kernel)
zip(haystack.as_bytes(), needle.as_bytes()).all(byte_eq_kernel)
}
}

/// This is faster than `str::ends_with` for small strings.
/// See <https://github.com/apache/arrow-rs/issues/6107> for more details.
fn ends_with(haystack: &str, needle: &str, byte_eq_kernel: impl Fn((&u8, &u8)) -> bool) -> bool {
if needle.len() > haystack.len() {
false
} else {
std::iter::zip(
zip(
haystack.as_bytes().iter().rev(),
needle.as_bytes().iter().rev(),
)
Expand Down

0 comments on commit 8cc373b

Please sign in to comment.