[Mesa-dev] [PATCH 5/5] glcpp: Avoid unnecessary call to strlen

Ian Romanick idr at freedesktop.org
Thu Sep 14 01:32:44 UTC 2017


On 09/11/2017 01:21 PM, Thomas Helland wrote:
> @@ -621,12 +636,17 @@ u64vec4		KEYWORD_WITH_ALT(0, 0, 0, 0, yyextra->ARB_gpu_shader_int64_enable, U64V
>  [_a-zA-Z][_a-zA-Z0-9]*	{
>  			    struct _mesa_glsl_parse_state *state = yyextra;
>  			    void *ctx = state->linalloc;
> -			    if (state->es_shader && strlen(yytext) > 1024) {
> +			    if (state->es_shader && yyleng + 1 > 1024) {

Also... I don't think this is right.  Shouldn't this just be 'yylen > 1024'?

>  			       _mesa_glsl_error(yylloc, state,
>  			                        "Identifier `%s' exceeds 1024 characters",
>  			                        yytext);
>  			    } else {
> -			      yylval->identifier = linear_strdup(ctx, yytext);
> +			      /* We're not doing linear_strdup here, to avoid an implicit call
> +			       * on strlen() for the length of the string, as this is already
> +			       * found by flex and stored in yyleng
> +			       */
> +			      yylval->identifier = (char *) linear_alloc_child(ctx, yyleng + 1);
> +			      memcpy(yylval->identifier, yytext, yyleng + 1);
>  			    }
>  			    return classify_identifier(state, yytext);
>  			}


More information about the mesa-dev mailing list