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:
Max Brunsfeld 2016-11-14 12:15:24 -08:00
parent 11e767bd81
commit 535879a2bd
25 changed files with 268 additions and 263 deletions

View file

@ -10,7 +10,7 @@ extern "C" {
typedef struct {
const TSParseAction *actions;
size_t action_count;
uint32_t action_count;
bool is_reusable;
bool depends_on_lookahead;
} TableEntry;
@ -22,7 +22,7 @@ TSSymbolMetadata ts_language_symbol_metadata(const TSLanguage *, TSSymbol);
static inline const TSParseAction *ts_language_actions(const TSLanguage *self,
TSStateId state,
TSSymbol symbol,
size_t *count) {
uint32_t *count) {
TableEntry entry;
ts_language_table_entry(self, state, symbol, &entry);
*count = entry.action_count;
@ -35,7 +35,7 @@ static inline TSStateId ts_language_next_state(const TSLanguage *self,
if (symbol == ts_builtin_sym_error) {
return 0;
} else if (symbol < self->token_count) {
size_t count;
uint32_t count;
const TSParseAction *actions = ts_language_actions(self, state, symbol, &count);
if (count > 0) {
TSParseAction action = actions[count - 1];