-
Notifications
You must be signed in to change notification settings - Fork 23
Closed
Description
Currently the Query class maintains the state of both a TSQuery and TSQueryCursor (c.f. here). It has methods that work with both of them (i.e. here).
Splitting it into two separate classes has the following advantages:
- Split the logic of compiling the query and executing the query. So query compilation must be done less often.
- Currently the query class uses
Arena.ofShared()but the tree-sitter documentation mentions that aTSQueryCursorshall only be accessed by a single thread. Allocating the cursor by an arena that can be accessed by multiple threads makes it more error prone. - Consumers of the library can have access to the low level
TSQueryCursormethods (e.g.ts_query_cursor_next_match). They must not use theQuery::findMatcheslogic if they do not desire it. - The default lifetime of the native memory of the query matches can be bound to the new
QueryCursorclass instead of theQueryclass. This way and application can keep the sameQueryinstance for its entire runtime without leaking memory.
However the change would imply breaking API changes:
- The methods of the
Queryclass that currently set properties of aTSQueryCursorwould need to be moved to the newQueryCursorclass - The
Query::findMatchesmethods would need anQueryCursoras an additional argument.
Marcono1234
Metadata
Metadata
Assignees
Labels
No labels