Skip to content

Commit 1f6eac5

Browse files
committed
query: Use uint32_t for capture list IDs
1 parent cd96552 commit 1f6eac5

File tree

2 files changed

+10
-16
lines changed

2 files changed

+10
-16
lines changed

lib/include/tree_sitter/api.h

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -801,16 +801,12 @@ void ts_query_cursor_exec(TSQueryCursor *, const TSQuery *, TSNode);
801801
* Manage the maximum number of in-progress matches allowed by this query
802802
* cursor.
803803
*
804-
* Query cursors have a maximum capacity for storing lists of in-progress
805-
* captures. If this capacity is exceeded, then the earliest-starting match will
806-
* silently be dropped to make room for further matches.
807-
*
808-
* By default, this limit is 65,536 pending matches, which is effectively
809-
* unlimited for most queries and syntax trees. You can optionally set this to a
810-
* lower number if you want to have (and check) a tighter bound on query
811-
* complexity.
812-
*
813-
* If you update the match limit, it must be > 0 and <= 65536.
804+
* Query cursors have an optional maximum capacity for storing lists of
805+
* in-progress captures. If this capacity is exceeded, then the
806+
* earliest-starting match will silently be dropped to make room for further
807+
* matches. This maximum capacity is optional — by default, query cursors allow
808+
* any number of pending matches, dynamically allocating new space for them as
809+
* needed as the query is executed.
814810
*/
815811
bool ts_query_cursor_did_exceed_match_limit(const TSQueryCursor *);
816812
uint32_t ts_query_cursor_match_limit(const TSQueryCursor *);

lib/src/query.c

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -152,10 +152,10 @@ typedef struct {
152152
*/
153153
typedef struct {
154154
uint32_t id;
155+
uint32_t capture_list_id;
155156
uint16_t start_depth;
156157
uint16_t step_index;
157158
uint16_t pattern_index;
158-
uint16_t capture_list_id;
159159
uint16_t consumed_capture_count: 12;
160160
bool seeking_immediate_match: 1;
161161
bool has_in_progress_alternatives: 1;
@@ -183,7 +183,7 @@ typedef struct {
183183
// use. We reuse those existing-but-unused capture lists before trying to
184184
// allocate any new ones. We use an invalid value (UINT32_MAX) for a capture
185185
// list's length to indicate that it's not in use.
186-
uint16_t free_capture_list_count;
186+
uint32_t free_capture_list_count;
187187
} CaptureListPool;
188188

189189
/*
@@ -367,9 +367,7 @@ static CaptureListPool capture_list_pool_new(void) {
367367
return (CaptureListPool) {
368368
.list = array_new(),
369369
.empty_list = array_new(),
370-
// The maximum maxmimum is 64K, since we use `uint16_t` as our capture list
371-
// index type.
372-
.max_capture_list_count = 65536,
370+
.max_capture_list_count = UINT32_MAX,
373371
.free_capture_list_count = 0,
374372
};
375373
}
@@ -2318,7 +2316,7 @@ uint32_t ts_query_cursor_match_limit(const TSQueryCursor *self) {
23182316
}
23192317

23202318
void ts_query_cursor_set_match_limit(TSQueryCursor *self, uint32_t limit) {
2321-
assert(limit > 0 && limit <= 65536);
2319+
assert(limit > 0);
23222320
self->capture_list_pool.max_capture_list_count = limit;
23232321
}
23242322

0 commit comments

Comments
 (0)