Skip to content

Commit

Permalink
perf: Use faster iteration in 'starts_with'/'ends_with' (#19583)
Browse files Browse the repository at this point in the history
  • Loading branch information
ritchie46 authored Nov 1, 2024
1 parent 78f56c2 commit d3878b1
Showing 1 changed file with 2 additions and 6 deletions.
8 changes: 2 additions & 6 deletions crates/polars-ops/src/chunked_array/binary/namespace.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,18 +34,14 @@ pub trait BinaryNameSpaceImpl: AsBinary {
fn ends_with(&self, sub: &[u8]) -> BooleanChunked {
let ca = self.as_binary();
let f = |s: &[u8]| s.ends_with(sub);
let mut out: BooleanChunked = ca.into_iter().map(|opt_s| opt_s.map(f)).collect();
out.rename(ca.name().clone());
out
ca.apply_nonnull_values_generic(DataType::Boolean, f)
}

/// Check if strings starts with a substring
fn starts_with(&self, sub: &[u8]) -> BooleanChunked {
let ca = self.as_binary();
let f = |s: &[u8]| s.starts_with(sub);
let mut out: BooleanChunked = ca.into_iter().map(|opt_s| opt_s.map(f)).collect();
out.rename(ca.name().clone());
out
ca.apply_nonnull_values_generic(DataType::Boolean, f)
}

fn starts_with_chunked(&self, prefix: &BinaryChunked) -> BooleanChunked {
Expand Down

0 comments on commit d3878b1

Please sign in to comment.