[Mesa-dev] [PATCH 02/12] glcpp: Avoid unnecessary strcmp()

Ian Romanick idr at freedesktop.org
Wed Jan 18 22:48:54 UTC 2017


This patch is

Reviewed-by: Ian Romanick <ian.d.romanick at intel.com>

I'd also accept a follow-up patch that fixes the formatting of
multi-line comments in this function (file?) by putting the closing */
on its own line. :)

On 01/07/2017 11:02 AM, Vladislav Egorov wrote:
> strcmp() is slow. Initiate comparison with "__LINE__" or "__FILE__"
> only if the identifier starts with '_', which is rare.
> ---
>  src/compiler/glsl/glcpp/glcpp-parse.y | 14 +++++++++-----
>  1 file changed, 9 insertions(+), 5 deletions(-)
> 
> diff --git a/src/compiler/glsl/glcpp/glcpp-parse.y b/src/compiler/glsl/glcpp/glcpp-parse.y
> index d5aa27e..4780c9f 100644
> --- a/src/compiler/glsl/glcpp/glcpp-parse.y
> +++ b/src/compiler/glsl/glcpp/glcpp-parse.y
> @@ -1834,11 +1834,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 (strcmp(identifier, "__FILE__") == 0)
> -      return _token_list_create_with_one_integer(parser, node->token->location.source);
> +   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);
> +   }
>  
>     /* Look up this identifier in the hash table. */
>     entry = _mesa_hash_table_search(parser->defines, identifier);
> 



More information about the mesa-dev mailing list