@@ -516,6 +516,20 @@ static bool glslang_parse_meta(const struct shader_line_buf *lines,
516516 id[0 ] = ' \0 ' ;
517517 desc[0 ] = ' \0 ' ;
518518
519+ /* Pre-count parameters to avoid vector reallocation */
520+ {
521+ size_t param_count = 0 ;
522+ for (i = 0 ; i < lines->num_lines ; i++)
523+ {
524+ const char *line = shader_line_buf_get (lines, i);
525+ if (line && !memcmp (line, " #pragma parameter " ,
526+ sizeof (" #pragma parameter " ) - 1 ))
527+ param_count++;
528+ }
529+ if (param_count > 0 )
530+ meta->parameters .reserve (param_count);
531+ }
532+
519533 for (i = 0 ; i < lines->num_lines ; i++)
520534 {
521535 const char *line = shader_line_buf_get (lines, i);
@@ -547,6 +561,7 @@ static bool glslang_parse_meta(const struct shader_line_buf *lines,
547561 int fields = 0 ;
548562 const char *s = line + (sizeof (" #pragma parameter " ) - 1 );
549563 size_t len = 0 ;
564+ size_t id_len, desc_len;
550565 char *end = NULL ;
551566
552567 /* Parse id */
@@ -562,6 +577,7 @@ static bool glslang_parse_meta(const struct shader_line_buf *lines,
562577 }
563578 memcpy (id, s, len);
564579 id[len] = ' \0 ' ;
580+ id_len = len;
565581 s += len;
566582
567583 /* Parse quoted description */
@@ -583,6 +599,7 @@ static bool glslang_parse_meta(const struct shader_line_buf *lines,
583599 }
584600 memcpy (desc, s, len);
585601 desc[len] = ' \0 ' ;
602+ desc_len = len;
586603 s += len + 1 ;
587604
588605 /* Parse initial */
@@ -642,7 +659,9 @@ static bool glslang_parse_meta(const struct shader_line_buf *lines,
642659
643660 for (j = 0 ; j < meta->parameters .size (); j++)
644661 {
645- if (meta->parameters [j].id == id)
662+ const std::string &pid = meta->parameters [j].id ;
663+ if (pid.size () == id_len
664+ && !memcmp (pid.data (), id, id_len))
646665 {
647666 parameter_found = true ;
648667 parameter_index = j;
@@ -656,7 +675,8 @@ static bool glslang_parse_meta(const struct shader_line_buf *lines,
656675 {
657676 const glslang_parameter *parameter =
658677 &meta->parameters [parameter_index];
659- if ( (parameter->desc != desc)
678+ if ( parameter->desc .size () != desc_len
679+ || memcmp (parameter->desc .data (), desc, desc_len)
660680 || (parameter->initial != initial)
661681 || (parameter->minimum != minimum)
662682 || (parameter->maximum != maximum)
@@ -670,8 +690,16 @@ static bool glslang_parse_meta(const struct shader_line_buf *lines,
670690 }
671691 }
672692 else
673- meta->parameters .push_back ({
674- id, desc, initial, minimum, maximum, step });
693+ {
694+ glslang_parameter p;
695+ p.id .assign (id, id_len);
696+ p.desc .assign (desc, desc_len);
697+ p.initial = initial;
698+ p.minimum = minimum;
699+ p.maximum = maximum;
700+ p.step = step;
701+ meta->parameters .push_back (p);
702+ }
675703 }
676704 }
677705 /* Check for framebuffer format */
0 commit comments