Skip to content

Split the bindings for TSQuery and TSQueryCursor into multiple classesΒ #66

@Emmeral

Description

@Emmeral

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:

  1. Split the logic of compiling the query and executing the query. So query compilation must be done less often.
  2. Currently the query class uses Arena.ofShared() but the tree-sitter documentation mentions that a TSQueryCursor shall 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.
  3. Consumers of the library can have access to the low level TSQueryCursor methods (e.g. ts_query_cursor_next_match). They must not use the Query::findMatches logic if they do not desire it.
  4. The default lifetime of the native memory of the query matches can be bound to the new QueryCursor class instead of the Query class. This way and application can keep the same Query instance for its entire runtime without leaking memory.

However the change would imply breaking API changes:

  • The methods of the Query class that currently set properties of a TSQueryCursor would need to be moved to the new QueryCursor class
  • The Query::findMatches methods would need an QueryCursor as an additional argument.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions