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
copr: support more regexp functions #13480
Conversation
Signed-off-by: gengliqi <gengliqiii@gmail.com>
[REVIEW NOTIFICATION] This pull request has been approved by:
To complete the pull request process, please ask the reviewers in the list to review by filling The full list of commands accepted by this bot can be found here. Reviewer can indicate their review by submitting an approval review. |
Signed-off-by: gengliqi <gengliqiii@gmail.com>
Signed-off-by: gengliqi <gengliqiii@gmail.com>
Signed-off-by: gengliqi <gengliqiii@gmail.com>
Signed-off-by: gengliqi <gengliqiii@gmail.com>
Signed-off-by: gengliqi <gengliqiii@gmail.com>
} | ||
|
||
fn get_match_type<C: Collator>(match_type: &[u8]) -> Result<String> { | ||
let match_type = String::from_utf8(match_type.to_vec())?; |
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.
Better to iterate the &[u8]
directly and match each byte. Then, we can avoid this allocation.
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.
I use str::from_utf8
instead.
let count = expr.chars().count() as i64; | ||
if (pos < 1 || pos > count) && !(count == 0 && pos == 1) { | ||
return Err(box_err!("invalid regex pos: {}, count: {}", pos, count)); | ||
} | ||
let mut new_expr = String::new(); | ||
for (i, c) in expr.chars().enumerate() { | ||
if i as i64 >= pos - 1 { | ||
new_expr += &c.to_string(); | ||
} | ||
} | ||
expr = new_expr; |
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.
We can use str::char_indices
to get the byte index of the start. Then, use str::get_unchecked
to get a sub-str
.
Then, we don't iterate the string twice and don't create a new string.
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.
Good point! Addressed.
for (i, m) in regex.find_iter(&expr).enumerate() { | ||
if i as i64 == occurrence - 1 { |
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.
What about just .skip(occurrence - 1).next()
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.
I change to use nth
.
The suggestions above also apply to the other functions ( |
Signed-off-by: gengliqi <gengliqiii@gmail.com>
None => return Ok(None), | ||
}; | ||
|
||
let count = expr.chars().count() as i64; |
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.
chars().count()
also iterates over the whole string. I mean we can check pos >= 1
first, then if expr.char_indices().nth((pos - 1) as usize)
returns None
, we can also return error.
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.
Got it.
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.
Done.
Signed-off-by: gengliqi <gengliqiii@gmail.com>
Signed-off-by: gengliqi <gengliqiii@gmail.com>
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.
Looks fine according to the test case.
Signed-off-by: gengliqi <gengliqiii@gmail.com>
/merge |
@gengliqi: It seems you want to merge this PR, I will help you trigger all the tests: /run-all-tests You only need to trigger If you have any questions about the PR merge process, please refer to pr process. Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the ti-community-infra/tichi repository. |
This pull request has been accepted and is ready to merge. Commit hash: a9d9062
|
Signed-off-by: gengliqi gengliqiii@gmail.com
What is changed and how it works?
Issue Number: Close #13483
What's Changed:
Related changes
pingcap/docs
/pingcap/docs-cn
:Check List
Tests
Side effects
Release note