aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorTimothy Arceri <[email protected]>2017-08-09 13:34:09 +1000
committerTimothy Arceri <[email protected]>2017-08-11 10:43:34 +1000
commitd4f79e995f180239c5d14e8493de9aac5a9e6833 (patch)
tree39946f7f2d9ccfe6fa8e50681e23551804b9e568 /src
parent26f4657c3f075045527c4568e8cbbaaa5d0b08e4 (diff)
glsl: use ralloc_str_append() rather than ralloc_asprintf_rewrite_tail()
The Deus Ex: Mankind Divided shaders go from spending ~20 seconds in the GLSL IR compilers front-end down to ~18.5 seconds on a Ryzen 1800X. Tested by compiling once with shader-db then deleting the index file from the shader cache and compiling again. v2: - fix rebasing issue in v1 Reviewed-by: Thomas Helland <[email protected]>
Diffstat (limited to 'src')
-rw-r--r--src/compiler/glsl/glcpp/glcpp-parse.y144
1 files changed, 113 insertions, 31 deletions
diff --git a/src/compiler/glsl/glcpp/glcpp-parse.y b/src/compiler/glsl/glcpp/glcpp-parse.y
index f1719f90b11..898a26044fa 100644
--- a/src/compiler/glsl/glcpp/glcpp-parse.y
+++ b/src/compiler/glsl/glcpp/glcpp-parse.y
@@ -209,7 +209,12 @@ line:
| SPACE control_line
| text_line {
_glcpp_parser_print_expanded_token_list (parser, $1);
- ralloc_asprintf_rewrite_tail (&parser->output, &parser->output_length, "\n");
+ const char *newline_str = "\n";
+ size_t size = strlen(newline_str);
+
+ ralloc_str_append(&parser->output, newline_str,
+ parser->output_length, size);
+ parser->output_length += size;
}
| expanded_line
;
@@ -259,7 +264,12 @@ define:
control_line:
control_line_success {
- ralloc_asprintf_rewrite_tail (&parser->output, &parser->output_length, "\n");
+ const char *newline_str = "\n";
+ size_t size = strlen(newline_str);
+
+ ralloc_str_append(&parser->output, newline_str,
+ parser->output_length, size);
+ parser->output_length += size;
}
| control_line_error
| HASH_TOKEN LINE pp_tokens NEWLINE {
@@ -1130,7 +1140,10 @@ static void
_token_print(char **out, size_t *len, token_t *token)
{
if (token->type < 256) {
- ralloc_asprintf_rewrite_tail (out, len, "%c", token->type);
+ size_t size = sizeof(char);
+
+ ralloc_str_append(out, (char *) &token->type, *len, size);
+ *len += size;
return;
}
@@ -1140,48 +1153,117 @@ _token_print(char **out, size_t *len, token_t *token)
break;
case IDENTIFIER:
case INTEGER_STRING:
- case OTHER:
- ralloc_asprintf_rewrite_tail (out, len, "%s", token->value.str);
+ case OTHER: {
+ size_t size = strlen(token->value.str);
+
+ ralloc_str_append(out, token->value.str, *len, size);
+ *len += size;
break;
- case SPACE:
- ralloc_asprintf_rewrite_tail (out, len, " ");
+ }
+ case SPACE: {
+ const char *token_str = " ";
+ size_t size = strlen(token_str);
+
+ ralloc_str_append(out, token_str, *len, size);
+ *len += size;
break;
- case LEFT_SHIFT:
- ralloc_asprintf_rewrite_tail (out, len, "<<");
+ }
+ case LEFT_SHIFT: {
+ const char *token_str = "<<";
+ size_t size = strlen(token_str);
+
+ ralloc_str_append(out, token_str, *len, size);
+ *len += size;
break;
- case RIGHT_SHIFT:
- ralloc_asprintf_rewrite_tail (out, len, ">>");
+ }
+ case RIGHT_SHIFT: {
+ const char *token_str = ">>";
+ size_t size = strlen(token_str);
+
+ ralloc_str_append(out, token_str, *len, size);
+ *len += size;
break;
- case LESS_OR_EQUAL:
- ralloc_asprintf_rewrite_tail (out, len, "<=");
+ }
+ case LESS_OR_EQUAL: {
+ const char *token_str = "<=";
+ size_t size = strlen(token_str);
+
+ ralloc_str_append(out, token_str, *len, size);
+ *len += size;
break;
- case GREATER_OR_EQUAL:
- ralloc_asprintf_rewrite_tail (out, len, ">=");
+ }
+ case GREATER_OR_EQUAL: {
+ const char *token_str = ">=";
+ size_t size = strlen(token_str);
+
+ ralloc_str_append(out, token_str, *len, size);
+ *len += size;
break;
- case EQUAL:
- ralloc_asprintf_rewrite_tail (out, len, "==");
+ }
+ case EQUAL: {
+ const char *token_str = "==";
+ size_t size = strlen(token_str);
+
+ ralloc_str_append(out, token_str, *len, size);
+ *len += size;
break;
- case NOT_EQUAL:
- ralloc_asprintf_rewrite_tail (out, len, "!=");
+ }
+ case NOT_EQUAL: {
+ const char *token_str = "!=";
+ size_t size = strlen(token_str);
+
+ ralloc_str_append(out, token_str, *len, size);
+ *len += size;
break;
- case AND:
- ralloc_asprintf_rewrite_tail (out, len, "&&");
+ }
+ case AND: {
+ const char *token_str = "&&";
+ size_t size = strlen(token_str);
+
+ ralloc_str_append(out, token_str, *len, size);
+ *len += size;
break;
- case OR:
- ralloc_asprintf_rewrite_tail (out, len, "||");
+ }
+ case OR: {
+ const char *token_str = "||";
+ size_t size = strlen(token_str);
+
+ ralloc_str_append(out, token_str, *len, size);
+ *len += size;
break;
- case PASTE:
- ralloc_asprintf_rewrite_tail (out, len, "##");
+ }
+ case PASTE: {
+ const char *token_str = "##";
+ size_t size = strlen(token_str);
+
+ ralloc_str_append(out, token_str, *len, size);
+ *len += size;
break;
- case PLUS_PLUS:
- ralloc_asprintf_rewrite_tail (out, len, "++");
+ }
+ case PLUS_PLUS: {
+ const char *token_str = "++";
+ size_t size = strlen(token_str);
+
+ ralloc_str_append(out, token_str, *len, size);
+ *len += size;
break;
- case MINUS_MINUS:
- ralloc_asprintf_rewrite_tail (out, len, "--");
+ }
+ case MINUS_MINUS: {
+ const char *token_str = "--";
+ size_t size = strlen(token_str);
+
+ ralloc_str_append(out, token_str, *len, size);
+ *len += size;
break;
- case DEFINED:
- ralloc_asprintf_rewrite_tail (out, len, "defined");
+ }
+ case DEFINED: {
+ const char *token_str = "defined";
+ size_t size = strlen(token_str);
+
+ ralloc_str_append(out, token_str, *len, size);
+ *len += size;
break;
+ }
case PLACEHOLDER:
/* Nothing to print. */
break;