Check once for cancellation at the beginning of a parse

This commit is contained in:
Max Brunsfeld 2019-08-19 17:11:39 -07:00
parent ec7756faa0
commit ef87ed6130

View file

@ -1290,15 +1290,18 @@ static bool ts_parser__advance(
}
for (;;) {
// If a cancellation flag or a timeout was provided, then check every
// time a fixed number of parse actions has been processed.
if (++self->operation_count == OP_COUNT_PER_TIMEOUT_CHECK) {
self->operation_count = 0;
if (
(self->cancellation_flag && atomic_load(self->cancellation_flag)) ||
(!clock_is_null(self->end_clock) && clock_is_gt(clock_now(), self->end_clock))
) {
ts_subtree_release(&self->tree_pool, lookahead);
return false;
}
}
if (
self->operation_count == 0 &&
((self->cancellation_flag && atomic_load(self->cancellation_flag)) ||
(!clock_is_null(self->end_clock) && clock_is_gt(clock_now(), self->end_clock)))
) {
ts_subtree_release(&self->tree_pool, lookahead);
return false;
}
StackVersion last_reduction_version = STACK_VERSION_NONE;