From e2ca55c918080a6468ebce449f8219c1d99e182e Mon Sep 17 00:00:00 2001 From: Max Brunsfeld Date: Tue, 6 Sep 2016 10:23:07 -0700 Subject: [PATCH] Avoid unnecessary TSInput calls when resetting lexer within an existing chunk --- src/runtime/lexer.c | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/src/runtime/lexer.c b/src/runtime/lexer.c index 85b207b6..243fa78a 100644 --- a/src/runtime/lexer.c +++ b/src/runtime/lexer.c @@ -95,9 +95,12 @@ static inline void ts_lexer__reset(TSLexer *self, TSLength position) { self->token_start_position = position; self->current_position = position; - self->chunk = 0; - self->chunk_start = 0; - self->chunk_size = 0; + if (self->chunk && (position.bytes < self->chunk_start || position.bytes >= self->chunk_start + self->chunk_size)) { + self->chunk = 0; + self->chunk_start = 0; + self->chunk_size = 0; + } + self->lookahead_size = 0; self->lookahead = 0; }