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

Timothy Arceri tarceri at itsqueeze.com
Mon May 22 00:23:13 UTC 2017


On 22/05/17 06:49, 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);        \

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>


>   			RETURN_TOKEN_NEVER_SKIP (token);		\
>   		}							\
>   	} while(0)
> 


More information about the mesa-dev mailing list