query: Allow configurable match limit
The default is now a whopping 64K matches, which "should be enough for everyone". You can use the new `ts_query_cursor_set_match_limit` function to set this to a lower limit, such as the previous default of 32.
This commit is contained in:
parent
78010722a4
commit
cd96552448
5 changed files with 106 additions and 23 deletions
|
|
@ -726,15 +726,27 @@ extern "C" {
|
|||
pub fn ts_query_cursor_exec(arg1: *mut TSQueryCursor, arg2: *const TSQuery, arg3: TSNode);
|
||||
}
|
||||
extern "C" {
|
||||
#[doc = " Check if this cursor has exceeded its maximum number of in-progress"]
|
||||
#[doc = " matches."]
|
||||
#[doc = " Manage the maximum number of in-progress matches allowed by this query"]
|
||||
#[doc = " cursor."]
|
||||
#[doc = ""]
|
||||
#[doc = " Currently, query cursors have a fixed capacity for storing lists"]
|
||||
#[doc = " of in-progress captures. If this capacity is exceeded, then the"]
|
||||
#[doc = " earliest-starting match will silently be dropped to make room for"]
|
||||
#[doc = " further matches."]
|
||||
#[doc = " Query cursors have a maximum capacity for storing lists of in-progress"]
|
||||
#[doc = " captures. If this capacity is exceeded, then the earliest-starting match will"]
|
||||
#[doc = " silently be dropped to make room for further matches."]
|
||||
#[doc = ""]
|
||||
#[doc = " By default, this limit is 65,536 pending matches, which is effectively"]
|
||||
#[doc = " unlimited for most queries and syntax trees. You can optionally set this to a"]
|
||||
#[doc = " lower number if you want to have (and check) a tighter bound on query"]
|
||||
#[doc = " complexity."]
|
||||
#[doc = ""]
|
||||
#[doc = " If you update the match limit, it must be > 0 and <= 65536."]
|
||||
pub fn ts_query_cursor_did_exceed_match_limit(arg1: *const TSQueryCursor) -> bool;
|
||||
}
|
||||
extern "C" {
|
||||
pub fn ts_query_cursor_match_limit(arg1: *const TSQueryCursor) -> u32;
|
||||
}
|
||||
extern "C" {
|
||||
pub fn ts_query_cursor_set_match_limit(arg1: *mut TSQueryCursor, arg2: u32);
|
||||
}
|
||||
extern "C" {
|
||||
#[doc = " Set the range of bytes or (row, column) positions in which the query"]
|
||||
#[doc = " will be executed."]
|
||||
|
|
|
|||
|
|
@ -1598,6 +1598,19 @@ impl<'a> QueryCursor {
|
|||
QueryCursor(unsafe { NonNull::new_unchecked(ffi::ts_query_cursor_new()) })
|
||||
}
|
||||
|
||||
/// Return the maximum number of in-progress matches for this cursor.
|
||||
pub fn match_limit(&self) -> u32 {
|
||||
unsafe { ffi::ts_query_cursor_match_limit(self.0.as_ptr()) }
|
||||
}
|
||||
|
||||
/// Set the maximum number of in-progress matches for this cursor. The limit must be > 0 and
|
||||
/// <= 65536.
|
||||
pub fn set_match_limit(&mut self, limit: u32) {
|
||||
unsafe {
|
||||
ffi::ts_query_cursor_set_match_limit(self.0.as_ptr(), limit);
|
||||
}
|
||||
}
|
||||
|
||||
/// Check if, on its last execution, this cursor exceeded its maximum number of
|
||||
/// in-progress matches.
|
||||
pub fn did_exceed_match_limit(&self) -> bool {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue