-
-
Notifications
You must be signed in to change notification settings - Fork 2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
perf(rust): re-use regex capture allocation (#10302) #10335
Merged
Merged
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
17c0a01
feat(rust): re-use regex capture allocation (#10302)
orlp 49e480c
fix(rust): set cfg("extract_groups") appropriately
orlp 8ab2e98
chore(rust): silence clippy
orlp 745aea6
fix(rust): set cfg appropriately, v2
orlp 61c50e4
chore(rust): silence clippy, v2
orlp 77eaeb8
chore(rust): cargo fmt
orlp File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
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 |
---|---|---|
@@ -1,5 +1,3 @@ | ||
use std::borrow::Cow; | ||
|
||
#[cfg(feature = "string_encoding")] | ||
use base64::engine::general_purpose; | ||
#[cfg(feature = "string_encoding")] | ||
|
@@ -15,11 +13,6 @@ use super::*; | |
#[cfg(feature = "binary_encoding")] | ||
use crate::chunked_array::binary::BinaryNameSpaceImpl; | ||
|
||
fn f_regex_extract<'a>(reg: &Regex, input: &'a str, group_index: usize) -> Option<Cow<'a, str>> { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yes, nice cleanup. Better to have the implementation separated from the dispatch. 👍 |
||
reg.captures(input) | ||
.and_then(|cap| cap.get(group_index).map(|m| Cow::Borrowed(m.as_str()))) | ||
} | ||
|
||
pub trait Utf8NameSpaceImpl: AsUtf8 { | ||
#[cfg(not(feature = "binary_encoding"))] | ||
fn hex_decode(&self) -> PolarsResult<Utf8Chunked> { | ||
|
@@ -298,8 +291,7 @@ pub trait Utf8NameSpaceImpl: AsUtf8 { | |
/// Extract the nth capture group from pattern | ||
fn extract(&self, pat: &str, group_index: usize) -> PolarsResult<Utf8Chunked> { | ||
let ca = self.as_utf8(); | ||
let reg = Regex::new(pat)?; | ||
Ok(ca.apply_on_opt(|e| e.and_then(|input| f_regex_extract(®, input, group_index)))) | ||
super::extract::extract_group(ca, pat, group_index) | ||
} | ||
|
||
/// Extract each successive non-overlapping regex match in an individual string as an array | ||
|
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, makes sense. The copy doesn't add much today, but will be correct once we added a validity to polars' struct type.