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

Thomas Helland thomashelland90 at gmail.com
Thu Sep 14 09:20:16 UTC 2017


2017-09-14 3:32 GMT+02:00 Ian Romanick <idr at freedesktop.org>:
> 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'?
>

Yes, you are absolutely right. Not sure how this got to be like this.
Good job catching that!

>>                              _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