From d3878b1b19f39a71f72899d2096059359d0d0f45 Mon Sep 17 00:00:00 2001 From: Ritchie Vink Date: Fri, 1 Nov 2024 13:17:30 +0100 Subject: [PATCH] perf: Use faster iteration in 'starts_with'/'ends_with' (#19583) --- crates/polars-ops/src/chunked_array/binary/namespace.rs | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-) diff --git a/crates/polars-ops/src/chunked_array/binary/namespace.rs b/crates/polars-ops/src/chunked_array/binary/namespace.rs index 487f6a11f0df..b20f1d9e3e5a 100644 --- a/crates/polars-ops/src/chunked_array/binary/namespace.rs +++ b/crates/polars-ops/src/chunked_array/binary/namespace.rs @@ -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 {