Skip to content

Commit 3c3699b

Browse files
authored
perf: hoist out common subexpressions in satisfies_text_predicates
This commit stores the result of text predicates evaluation in a separate variable to ensure that they're computed just once. As is, it is possible for e.g. #match predicates to match node against a regex twice.
1 parent 6304009 commit 3c3699b

File tree

1 file changed

+9
-6
lines changed

1 file changed

+9
-6
lines changed

lib/binding_rust/lib.rs

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2551,10 +2551,11 @@ impl<'tree> QueryMatch<'_, 'tree> {
25512551
let mut text2 = text_provider.text(node2);
25522552
let text1 = node_text1.get_text(&mut text1);
25532553
let text2 = node_text2.get_text(&mut text2);
2554-
if (text1 == text2) != *is_positive && *match_all_nodes {
2554+
let is_positive_match = text1 == text2;
2555+
if is_positive_match != *is_positive && *match_all_nodes {
25552556
return false;
25562557
}
2557-
if (text1 == text2) == *is_positive && !*match_all_nodes {
2558+
if is_positive_match == *is_positive && !*match_all_nodes {
25582559
return true;
25592560
}
25602561
}
@@ -2565,10 +2566,11 @@ impl<'tree> QueryMatch<'_, 'tree> {
25652566
for node in nodes {
25662567
let mut text = text_provider.text(node);
25672568
let text = node_text1.get_text(&mut text);
2568-
if (text == s.as_bytes()) != *is_positive && *match_all_nodes {
2569+
let is_positive_match = text == s.as_bytes();
2570+
if is_positive_match != *is_positive && *match_all_nodes {
25692571
return false;
25702572
}
2571-
if (text == s.as_bytes()) == *is_positive && !*match_all_nodes {
2573+
if is_positive_match == *is_positive && !*match_all_nodes {
25722574
return true;
25732575
}
25742576
}
@@ -2579,10 +2581,11 @@ impl<'tree> QueryMatch<'_, 'tree> {
25792581
for node in nodes {
25802582
let mut text = text_provider.text(node);
25812583
let text = node_text1.get_text(&mut text);
2582-
if (r.is_match(text)) != *is_positive && *match_all_nodes {
2584+
let is_positive_match = r.is_match(text);
2585+
if is_positive_match != *is_positive && *match_all_nodes {
25832586
return false;
25842587
}
2585-
if (r.is_match(text)) == *is_positive && !*match_all_nodes {
2588+
if is_positive_match == *is_positive && !*match_all_nodes {
25862589
return true;
25872590
}
25882591
}

0 commit comments

Comments
 (0)