mirror of
https://gitlab.freedesktop.org/mesa/mesa.git
synced 2026-05-05 09:38:07 +02:00
glcpp: Use string_buffer for line continuation removal
Migrate removal of line continuations to string_buffer. Before this it used ralloc_strncat() to append strings, which internally each time calculates strlen() of its argument. Its argument is entire shader, so it multiple time scans the whole shader text. Signed-off-by: Vladislav Egorov <vegorov180@gmail.com> Tested-by: Dieter Nützel <Dieter at nuetzel-hh.de> Reviewed-by: Nicolai Hähnle <nicolai.haehnle at amd.com> V2: Adapt to different API of string buffer (Thomas Helland)
This commit is contained in:
parent
cad323f898
commit
e7220d2c22
1 changed files with 18 additions and 7 deletions
|
|
@ -97,17 +97,25 @@ skip_newline (const char *str)
|
|||
return ret;
|
||||
}
|
||||
|
||||
/* Initial output buffer size, 4096 minus ralloc() overhead. It was selected
|
||||
* to minimize total amount of allocated memory during shader-db run.
|
||||
*/
|
||||
#define INITIAL_PP_OUTPUT_BUF_SIZE 4048
|
||||
|
||||
/* Remove any line continuation characters in the shader, (whether in
|
||||
* preprocessing directives or in GLSL code).
|
||||
*/
|
||||
static char *
|
||||
remove_line_continuations(glcpp_parser_t *ctx, const char *shader)
|
||||
{
|
||||
char *clean = ralloc_strdup(ctx, "");
|
||||
struct _mesa_string_buffer *sb =
|
||||
_mesa_string_buffer_create(ctx, INITIAL_PP_OUTPUT_BUF_SIZE);
|
||||
|
||||
const char *backslash, *newline, *search_start;
|
||||
const char *cr, *lf;
|
||||
char newline_separator[3];
|
||||
int collapsed_newlines = 0;
|
||||
int separator_len;
|
||||
|
||||
backslash = strchr(shader, '\\');
|
||||
|
||||
|
|
@ -153,6 +161,7 @@ remove_line_continuations(glcpp_parser_t *ctx, const char *shader)
|
|||
newline_separator[0] = '\n';
|
||||
newline_separator[1] = '\r';
|
||||
}
|
||||
separator_len = strlen(newline_separator);
|
||||
|
||||
while (true) {
|
||||
/* If we have previously collapsed any line-continuations,
|
||||
|
|
@ -172,10 +181,12 @@ remove_line_continuations(glcpp_parser_t *ctx, const char *shader)
|
|||
if (newline &&
|
||||
(backslash == NULL || newline < backslash))
|
||||
{
|
||||
ralloc_strncat(&clean, shader,
|
||||
newline - shader + 1);
|
||||
_mesa_string_buffer_append_len(sb, shader,
|
||||
newline - shader + 1);
|
||||
while (collapsed_newlines) {
|
||||
ralloc_strcat(&clean, newline_separator);
|
||||
_mesa_string_buffer_append_len(sb,
|
||||
newline_separator,
|
||||
separator_len);
|
||||
collapsed_newlines--;
|
||||
}
|
||||
shader = skip_newline (newline);
|
||||
|
|
@ -196,7 +207,7 @@ remove_line_continuations(glcpp_parser_t *ctx, const char *shader)
|
|||
if (backslash[1] == '\r' || backslash[1] == '\n')
|
||||
{
|
||||
collapsed_newlines++;
|
||||
ralloc_strncat(&clean, shader, backslash - shader);
|
||||
_mesa_string_buffer_append_len(sb, shader, backslash - shader);
|
||||
shader = skip_newline (backslash + 1);
|
||||
search_start = shader;
|
||||
}
|
||||
|
|
@ -204,9 +215,9 @@ remove_line_continuations(glcpp_parser_t *ctx, const char *shader)
|
|||
backslash = strchr(search_start, '\\');
|
||||
}
|
||||
|
||||
ralloc_strcat(&clean, shader);
|
||||
_mesa_string_buffer_append(sb, shader);
|
||||
|
||||
return clean;
|
||||
return sb->buf;
|
||||
}
|
||||
|
||||
int
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue