[Mesa-dev] [PATCH 4/9] glcpp: Avoid unnecessary strcmp()

Erik Faye-Lund kusmabite at gmail.com
Mon May 22 10:33:55 UTC 2017


On Sun, May 21, 2017 at 10:49 PM, Thomas Helland
<thomashelland90 at gmail.com> wrote:
> From: Vladislav Egorov <vegorov180 at gmail.com>
>
> 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 at intel.com>
> ---
>  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 620ade6418..e84b6fb055 100644
> --- a/src/compiler/glsl/glcpp/glcpp-parse.y
> +++ b/src/compiler/glsl/glcpp/glcpp-parse.y
> @@ -1830,11 +1830,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)

I would even do:

if (strcmp(identifier + 1, "_LINE__") == 0)

...just because I don't like repeating checks. It should also be
*slightly* faster. Same for __FILE__, of course ;)


More information about the mesa-dev mailing list