glcpp: Avoid unnecessary strcmp()

strcmp() is slow. Initiate comparison with "__LINE__" or "__FILE__"
only if the identifier starts with '_', which is rare.

Reviewed-by: Ian Romanick <ian.d.romanick@intel.com>
Reviewed-by: Timothy Arceri <tarceri@itsqueeze.com>
This commit is contained in:
Vladislav Egorov 2017-05-21 22:49:15 +02:00 committed by Timothy Arceri
parent 1575a8146a
commit b8e792ee25
1 changed files with 8 additions and 4 deletions

View File

@ -1829,11 +1829,15 @@ _glcpp_parser_expand_node(glcpp_parser_t *parser, token_node_t *node,
/* Special handling for __LINE__ and __FILE__, (not through
* the hash table). */
if (strcmp(identifier, "__LINE__") == 0)
return _token_list_create_with_one_integer(parser, node->token->location.first_line);
if (*identifier == '_') {
if (strcmp(identifier, "__LINE__") == 0)
return _token_list_create_with_one_integer(parser,
node->token->location.first_line);
if (strcmp(identifier, "__FILE__") == 0)
return _token_list_create_with_one_integer(parser, node->token->location.source);
if (strcmp(identifier, "__FILE__") == 0)
return _token_list_create_with_one_integer(parser,
node->token->location.source);
}
/* Look up this identifier in the hash table. */
entry = _mesa_hash_table_search(parser->defines, identifier);