-
-
Notifications
You must be signed in to change notification settings - Fork 2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(rust): Speed up starts_with for small prefixes (#19904)
- Loading branch information
1 parent
132c64d
commit 5b3a8f9
Showing
4 changed files
with
60 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
25 changes: 25 additions & 0 deletions
25
crates/polars-ops/src/chunked_array/strings/starts_with.rs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
use arrow::array::View; | ||
use arrow::buffer::Buffer; | ||
use polars_utils::slice::SliceAble; | ||
|
||
/// Checks if the string starts with the prefix | ||
/// When the prefix is smaller than View::MAX_INLINE_SIZE then this will be very fast | ||
pub(crate) fn starts_with_str(view: View, prefix: &str, buffers: &[Buffer<u8>]) -> bool { | ||
unsafe { | ||
if view.length <= View::MAX_INLINE_SIZE { | ||
view.get_inlined_slice_unchecked() | ||
.starts_with(prefix.as_bytes()) | ||
} else { | ||
let starts = view | ||
.prefix | ||
.to_le_bytes() | ||
.starts_with(prefix.as_bytes().slice_unchecked(0..4)); | ||
if starts { | ||
return view | ||
.get_slice_unchecked(buffers) | ||
.starts_with(prefix.as_bytes()); | ||
} | ||
false | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters