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

Timothy Arceri tarceri at itsqueeze.com
Tue Aug 29 23:24:41 UTC 2017


On 30/08/17 05:56, Thomas Helland wrote:
> Length of the token was already calculated by flex and stored in yyleng,
> no need to implicitly call strlen() via linear_strdup().
> ---
>   src/compiler/glsl/glcpp/glcpp-lex.l | 3 ++-
>   1 file changed, 2 insertions(+), 1 deletion(-)
> 
> diff --git a/src/compiler/glsl/glcpp/glcpp-lex.l b/src/compiler/glsl/glcpp/glcpp-lex.l
> index 381b97364a..93e5cb3845 100644
> --- a/src/compiler/glsl/glcpp/glcpp-lex.l
> +++ b/src/compiler/glsl/glcpp/glcpp-lex.l
> @@ -101,7 +101,8 @@ void glcpp_set_column (int  column_no , yyscan_t yyscanner);
>   #define RETURN_STRING_TOKEN(token)					\
>   	do {								\
>   		if (! parser->skipping) {				\
> -			yylval->str = linear_strdup(yyextra->linalloc, yytext);	\
> +			yylval->str = linear_alloc_child(yyextra->linalloc, yyleng + 1);	\
> +			memcpy(yylval->str, yytext, yyleng + 1);        \
>   			RETURN_TOKEN_NEVER_SKIP (token);		\
>   		}							\
>   	} while(0)
> 

Copy and pasted comments from the last time this was sent:

Seems reasonable. This pattern is also happening in glsl_lexer.ll maybe 
we should do this there also?

It might also make sense to add a comment here to say why we don't use 
linear_strdup(), so the optimisation doesn't get removed in future.

With that:

Reviewed-by: Timothy Arceri <tarceri at itsqueeze.com>


More information about the mesa-dev mailing list