Skip to content

Commit 8cc373b

Browse files
committed
add comments
1 parent 02dd628 commit 8cc373b

File tree

1 file changed

+7
-2
lines changed

1 file changed

+7
-2
lines changed

arrow-string/src/predicate.rs

+7-2
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ use arrow_array::{ArrayAccessor, BooleanArray};
1919
use arrow_schema::ArrowError;
2020
use memchr::memchr2;
2121
use regex::{Regex, RegexBuilder};
22+
use std::iter::zip;
2223

2324
/// A string based predicate
2425
pub enum Predicate<'a> {
@@ -130,19 +131,23 @@ impl<'a> Predicate<'a> {
130131
}
131132
}
132133

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

144+
/// This is faster than `str::ends_with` for small strings.
145+
/// See <https://github.com/apache/arrow-rs/issues/6107> for more details.
141146
fn ends_with(haystack: &str, needle: &str, byte_eq_kernel: impl Fn((&u8, &u8)) -> bool) -> bool {
142147
if needle.len() > haystack.len() {
143148
false
144149
} else {
145-
std::iter::zip(
150+
zip(
146151
haystack.as_bytes().iter().rev(),
147152
needle.as_bytes().iter().rev(),
148153
)

0 commit comments

Comments
 (0)