Improve tree queries' ability to handle large numbers of nested matches (#624)
* query: Acquire capture lists lazily, allow more concurrent states * Fix some static analysis warnings
This commit is contained in:
parent
7b39420de3
commit
462c86903f
2 changed files with 165 additions and 88 deletions
|
|
@ -339,7 +339,7 @@ fn test_query_matches_with_nesting_and_no_fields() {
|
|||
}
|
||||
|
||||
#[test]
|
||||
fn test_query_matches_with_many() {
|
||||
fn test_query_matches_with_many_results() {
|
||||
allocations::record(|| {
|
||||
let language = get_language("javascript");
|
||||
let query = Query::new(language, "(array (identifier) @element)").unwrap();
|
||||
|
|
@ -353,6 +353,47 @@ fn test_query_matches_with_many() {
|
|||
});
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_query_matches_with_many_overlapping_results() {
|
||||
allocations::record(|| {
|
||||
let language = get_language("javascript");
|
||||
let query = Query::new(
|
||||
language,
|
||||
r#"
|
||||
(call_expression
|
||||
function: (member_expression
|
||||
property: (property_identifier) @method))
|
||||
(call_expression
|
||||
function: (identifier) @function)
|
||||
((identifier) @constant
|
||||
(#match? @constant "[A-Z\\d_]+"))
|
||||
"#
|
||||
).unwrap();
|
||||
|
||||
let count = 80;
|
||||
|
||||
// Deeply nested chained function calls:
|
||||
// a
|
||||
// .foo(bar(BAZ))
|
||||
// .foo(bar(BAZ))
|
||||
// .foo(bar(BAZ))
|
||||
// ...
|
||||
let mut source = "a".to_string();
|
||||
source += &"\n .foo(bar(BAZ))".repeat(count);
|
||||
|
||||
assert_query_matches(
|
||||
language,
|
||||
&query,
|
||||
&source,
|
||||
&[
|
||||
(0, vec![("method", "foo")]),
|
||||
(1, vec![("function", "bar")]),
|
||||
(2, vec![("constant", "BAZ")])
|
||||
].iter().cloned().cycle().take(3 * count).collect::<Vec<_>>(),
|
||||
);
|
||||
});
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_query_matches_capturing_error_nodes() {
|
||||
allocations::record(|| {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue