From 9fcab12fa25cde2d24164b0642d1b3a54f817d60 Mon Sep 17 00:00:00 2001 From: depetrol Date: Fri, 18 Oct 2024 12:09:59 -0700 Subject: [PATCH] bring back token reuse --- core/lf_token.c | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/core/lf_token.c b/core/lf_token.c index 397f118c9..351212df9 100644 --- a/core/lf_token.c +++ b/core/lf_token.c @@ -237,6 +237,7 @@ lf_token_t* _lf_new_token(token_type_t* type, void* value, size_t length) { } lf_token_t* _lf_get_token(token_template_t* tmplt) { + LF_CRITICAL_SECTION_ENTER(GLOBAL_ENVIRONMENT); if (tmplt->token != NULL) { if (tmplt->token->ref_count == 1) { LF_PRINT_DEBUG("_lf_get_token: Reusing template token: %p with ref_count %zu", (void*)tmplt->token, @@ -244,15 +245,13 @@ lf_token_t* _lf_get_token(token_template_t* tmplt) { // Free any previous value in the token. _lf_free_token_value(tmplt->token); return tmplt->token; - } else { - // Liberate the token. - _lf_done_using(tmplt->token); } } + LF_CRITICAL_SECTION_EXIT(GLOBAL_ENVIRONMENT); // If we get here, we need a new token. - tmplt->token = _lf_new_token((token_type_t*)tmplt, NULL, 0); - tmplt->token->ref_count = 1; - return tmplt->token; + lf_token_t* result = _lf_new_token((token_type_t*)tmplt, NULL, 0); + result->ref_count = 1; + return result; } void _lf_initialize_template(token_template_t* tmplt, size_t element_size) {