Conversation
With that, MatchPattern does not have to be mutably borrowed to do matching anymore. It removes one obstacle for allowing SyntaxSet to be used by multiple threads, while still keeping regex compilation lazy.
|
I've run As you can see, the results are not very reliable. |
trishume
left a comment
There was a problem hiding this comment.
Looks good thanks for doing this! Definitely a good step towards multithreading. I'm okay to merge this into master, the benchmarks don't show any noticeable regression, on the few benchmarks of files large enough that highlighting time matters.
| } else { | ||
| None | ||
| let regex = match_pat.regex(); | ||
| let matched = regex.search_with_param( |
There was a problem hiding this comment.
You can return a Cow out of the if statement to avoid the duplication of the search.
There was a problem hiding this comment.
Ah nice, I'll try that.
There was a problem hiding this comment.
Hm, doesn't work because Regex is not Clone:
error[E0277]: the trait bound `onig::Regex: std::clone::Clone` is not satisfied
--> src/parsing/parser.rs:405:14
|
405 | (Cow::Borrowed(match_pat.regex()), true)
| ^^^^^^^^^^^^^ the trait `std::clone::Clone` is not implemented for `onig::Regex`
|
= note: required because of the requirements on the impl of `std::borrow::ToOwned` for `onig::Regex`
= note: required by `std::borrow::Cow::Borrowed`
The following works, but not sure if it's worth it?:
let do_search = |regex: &Regex, regions: &mut Region| {
regex.search_with_param(
line,
start,
line.len(),
SearchOptions::SEARCH_OPTION_NONE,
Some(regions),
MatchParam::default(),
)
};
let (matched, can_cache) = if match_pat.has_captures && captures.is_some() {
let &(ref region, ref s) = captures.unwrap();
let regex = match_pat.regex_with_refs(region, s);
(do_search(®ex, regions), false)
} else {
(do_search(match_pat.regex(), regions), true)
};There was a problem hiding this comment.
Oh darn. Apparently what we need is a ✨ supercow ✨ but it would be kind of dumb to add that library just for this instance.
That closure solution looks fine to me although I'm also fine with merging as is, don't have a strong preference between them, up to you.
There was a problem hiding this comment.
Lol 😆. Ok, I'll merge it like this.
With that,
MatchPatterndoes not have to be mutably borrowed to do matching anymore.It removes one obstacle for allowing
SyntaxSetto be used by multiple threads, while still keeping regex compilation lazy.This is one of the prerequisites for #182. I've created the PR against master so that we can benchmark the impact more directly. But I can integrate it into #182 if you prefer to not put it into master just yet.