Skip to content

Commit

Permalink
remove _lf_get_token
Browse files Browse the repository at this point in the history
  • Loading branch information
Depetrol committed Oct 17, 2024
1 parent c4764fb commit 76394dd
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 32 deletions.
23 changes: 2 additions & 21 deletions core/lf_token.c
Original file line number Diff line number Diff line change
Expand Up @@ -236,25 +236,6 @@ lf_token_t* _lf_new_token(token_type_t* type, void* value, size_t length) {
return result;
}

lf_token_t* _lf_get_token(token_template_t* tmplt) {
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);
}
}
// 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;
}

void _lf_initialize_template(token_template_t* tmplt, size_t element_size) {
assert(tmplt != NULL);
LF_CRITICAL_SECTION_ENTER(GLOBAL_ENVIRONMENT);
Expand Down Expand Up @@ -285,8 +266,8 @@ lf_token_t* _lf_initialize_token_with_value(token_template_t* tmplt, void* value
assert(tmplt != NULL);
LF_PRINT_DEBUG("_lf_initialize_token_with_value: template %p, value %p", (void*)tmplt, value);

lf_token_t* result = _lf_get_token(tmplt);
result->value = value;
lf_token_t* result = _lf_new_token((token_type_t*)tmplt, value, 0);
result->ref_count = 1;
// Count allocations to issue a warning if this is never freed.
#if !defined NDEBUG
LF_CRITICAL_SECTION_ENTER(GLOBAL_ENVIRONMENT);
Expand Down
11 changes: 0 additions & 11 deletions include/core/lf_token.h
Original file line number Diff line number Diff line change
Expand Up @@ -233,17 +233,6 @@ token_freed _lf_free_token(lf_token_t* token);
*/
lf_token_t* _lf_new_token(token_type_t* type, void* value, size_t length);

/**
* Get a token for the specified template.
* If the template already has a token and the reference count is 1,
* then return that token. Otherwise, create a new token,
* make it the new template, and dissociate or free the
* previous template token.
* @param tmplt The template. // template is a C++ keyword.
* @return A new or recycled lf_token_t struct.
*/
lf_token_t* _lf_get_token(token_template_t* tmplt);

/**
* Initialize the specified template to contain a token that is an
* array with the specified element size. If the template already has
Expand Down

0 comments on commit 76394dd

Please sign in to comment.