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

Thomas Helland thomashelland90 at gmail.com
Sun May 21 20:49:18 UTC 2017


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)
-- 
2.13.0



More information about the mesa-dev mailing list