Skip to content

Commit

Permalink
bring back token reuse
Browse files Browse the repository at this point in the history
  • Loading branch information
Depetrol committed Oct 18, 2024
1 parent 237b84d commit 9fcab12
Showing 1 changed file with 5 additions and 6 deletions.
11 changes: 5 additions & 6 deletions core/lf_token.c
Original file line number Diff line number Diff line change
Expand Up @@ -237,22 +237,21 @@ 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,
tmplt->token->ref_count);
// 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) {
Expand Down

0 comments on commit 9fcab12

Please sign in to comment.