Represent byte, char and tree counts as 32 bit numbers
The parser spends the majority of its time allocating and freeing trees and stack nodes. Also, the memory footprint of the AST is a significant concern when using tree-sitter with large files. This library is already unlikely to work very well with source files larger than 4GB, so representing rows, columns, byte lengths and child indices as unsigned 32 bit integers seems like the right choice.
This commit is contained in:
parent
11e767bd81
commit
535879a2bd
25 changed files with 268 additions and 263 deletions
|
|
@ -17,13 +17,13 @@ extern TSStateId TS_TREE_STATE_NONE;
|
|||
typedef struct Tree {
|
||||
struct {
|
||||
struct Tree *parent;
|
||||
size_t index;
|
||||
uint32_t index;
|
||||
Length offset;
|
||||
} context;
|
||||
|
||||
size_t child_count;
|
||||
size_t visible_child_count;
|
||||
size_t named_child_count;
|
||||
uint32_t child_count;
|
||||
uint32_t visible_child_count;
|
||||
uint32_t named_child_count;
|
||||
union {
|
||||
struct Tree **children;
|
||||
int32_t lookahead_char;
|
||||
|
|
@ -53,7 +53,7 @@ typedef struct Tree {
|
|||
typedef struct {
|
||||
Tree *tree;
|
||||
Length position;
|
||||
size_t child_index;
|
||||
uint32_t child_index;
|
||||
} TreePathEntry;
|
||||
|
||||
typedef Array(Tree *) TreeArray;
|
||||
|
|
@ -62,10 +62,10 @@ typedef Array(TreePathEntry) TreePath;
|
|||
|
||||
bool ts_tree_array_copy(TreeArray, TreeArray *);
|
||||
void ts_tree_array_delete(TreeArray *);
|
||||
size_t ts_tree_array_essential_count(const TreeArray *);
|
||||
uint32_t ts_tree_array_essential_count(const TreeArray *);
|
||||
|
||||
Tree *ts_tree_make_leaf(TSSymbol, Length, Length, TSSymbolMetadata);
|
||||
Tree *ts_tree_make_node(TSSymbol, size_t, Tree **, TSSymbolMetadata);
|
||||
Tree *ts_tree_make_node(TSSymbol, uint32_t, Tree **, TSSymbolMetadata);
|
||||
Tree *ts_tree_make_copy(Tree *child);
|
||||
Tree *ts_tree_make_error_node(TreeArray *);
|
||||
Tree *ts_tree_make_error(Length, Length, char);
|
||||
|
|
@ -74,19 +74,15 @@ void ts_tree_release(Tree *tree);
|
|||
bool ts_tree_eq(const Tree *tree1, const Tree *tree2);
|
||||
int ts_tree_compare(const Tree *tree1, const Tree *tree2);
|
||||
|
||||
size_t ts_tree_start_column(const Tree *self);
|
||||
size_t ts_tree_end_column(const Tree *self);
|
||||
void ts_tree_set_children(Tree *, size_t, Tree **);
|
||||
uint32_t ts_tree_start_column(const Tree *self);
|
||||
uint32_t ts_tree_end_column(const Tree *self);
|
||||
void ts_tree_set_children(Tree *, uint32_t, Tree **);
|
||||
void ts_tree_assign_parents(Tree *, TreePath *);
|
||||
void ts_tree_edit(Tree *, const TSInputEdit *edit);
|
||||
char *ts_tree_string(const Tree *, const TSLanguage *, bool include_all);
|
||||
void ts_tree_print_dot_graph(const Tree *, const TSLanguage *, FILE *);
|
||||
|
||||
static inline size_t ts_tree_total_chars(const Tree *self) {
|
||||
return self->padding.chars + self->size.chars;
|
||||
}
|
||||
|
||||
static inline size_t ts_tree_total_bytes(const Tree *self) {
|
||||
static inline uint32_t ts_tree_total_bytes(const Tree *self) {
|
||||
return self->padding.bytes + self->size.bytes;
|
||||
}
|
||||
|
||||
|
|
@ -100,7 +96,7 @@ static inline TSPoint ts_tree_total_extent(const Tree *self) {
|
|||
|
||||
static inline bool ts_tree_is_fragile(const Tree *tree) {
|
||||
return tree->fragile_left || tree->fragile_right ||
|
||||
ts_tree_total_chars(tree) == 0;
|
||||
ts_tree_total_bytes(tree) == 0;
|
||||
}
|
||||
|
||||
#ifdef __cplusplus
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue