diff options
author | Kenneth Graunke <[email protected]> | 2012-02-09 20:33:44 -0800 |
---|---|---|
committer | Kenneth Graunke <[email protected]> | 2012-02-28 13:07:12 -0800 |
commit | b823b99ec0f13af257dcd885f436a4d294c6222a (patch) | |
tree | a14501441c082303589b10821ca56c9554c57dc1 | |
parent | 8292b7419d0405e94a5ea270ba710d20f0eb071f (diff) |
glcpp: Don't strlen() the output for every token being printed.
The ralloc string appending functions were originally intended for
simple, non-hot-path uses like printing to an info log.
Cuts Unigine Tropics load time by around 20% (6 seconds).
v2: Avoid strlen() on every newline, too.
Signed-off-by: Kenneth Graunke <[email protected]>
Reviewed-by: Ian Romanick <[email protected]> [v1]
Acked-by: José Fonseca <[email protected]> [v1]
-rw-r--r-- | src/glsl/glcpp/glcpp-parse.y | 50 | ||||
-rw-r--r-- | src/glsl/glcpp/glcpp.h | 2 |
2 files changed, 28 insertions, 24 deletions
diff --git a/src/glsl/glcpp/glcpp-parse.y b/src/glsl/glcpp/glcpp-parse.y index efcc205c2d3..47ba54ddfbb 100644 --- a/src/glsl/glcpp/glcpp-parse.y +++ b/src/glsl/glcpp/glcpp-parse.y @@ -184,11 +184,11 @@ input: line: control_line { - ralloc_strcat (&parser->output, "\n"); + ralloc_asprintf_rewrite_tail (&parser->output, &parser->output_length, "\n"); } | text_line { _glcpp_parser_print_expanded_token_list (parser, $1); - ralloc_strcat (&parser->output, "\n"); + ralloc_asprintf_rewrite_tail (&parser->output, &parser->output_length, "\n"); ralloc_free ($1); } | expanded_line @@ -320,7 +320,7 @@ control_line: if ($2 >= 130 || $2 == 100) add_builtin_define (parser, "GL_FRAGMENT_PRECISION_HIGH", 1); - ralloc_asprintf_append (&parser->output, "#version %" PRIiMAX, $2); + ralloc_asprintf_rewrite_tail (&parser->output, &parser->output_length, "#version %" PRIiMAX, $2); } | HASH NEWLINE ; @@ -903,54 +903,54 @@ _token_list_equal_ignoring_space (token_list_t *a, token_list_t *b) } static void -_token_print (char **out, token_t *token) +_token_print (char **out, size_t *len, token_t *token) { if (token->type < 256) { - ralloc_asprintf_append (out, "%c", token->type); + ralloc_asprintf_rewrite_tail (out, len, "%c", token->type); return; } switch (token->type) { case INTEGER: - ralloc_asprintf_append (out, "%" PRIiMAX, token->value.ival); + ralloc_asprintf_rewrite_tail (out, len, "%" PRIiMAX, token->value.ival); break; case IDENTIFIER: case INTEGER_STRING: case OTHER: - ralloc_strcat (out, token->value.str); + ralloc_asprintf_rewrite_tail (out, len, "%s", token->value.str); break; case SPACE: - ralloc_strcat (out, " "); + ralloc_asprintf_rewrite_tail (out, len, " "); break; case LEFT_SHIFT: - ralloc_strcat (out, "<<"); + ralloc_asprintf_rewrite_tail (out, len, "<<"); break; case RIGHT_SHIFT: - ralloc_strcat (out, ">>"); + ralloc_asprintf_rewrite_tail (out, len, ">>"); break; case LESS_OR_EQUAL: - ralloc_strcat (out, "<="); + ralloc_asprintf_rewrite_tail (out, len, "<="); break; case GREATER_OR_EQUAL: - ralloc_strcat (out, ">="); + ralloc_asprintf_rewrite_tail (out, len, ">="); break; case EQUAL: - ralloc_strcat (out, "=="); + ralloc_asprintf_rewrite_tail (out, len, "=="); break; case NOT_EQUAL: - ralloc_strcat (out, "!="); + ralloc_asprintf_rewrite_tail (out, len, "!="); break; case AND: - ralloc_strcat (out, "&&"); + ralloc_asprintf_rewrite_tail (out, len, "&&"); break; case OR: - ralloc_strcat (out, "||"); + ralloc_asprintf_rewrite_tail (out, len, "||"); break; case PASTE: - ralloc_strcat (out, "##"); + ralloc_asprintf_rewrite_tail (out, len, "##"); break; case COMMA_FINAL: - ralloc_strcat (out, ","); + ralloc_asprintf_rewrite_tail (out, len, ","); break; case PLACEHOLDER: /* Nothing to print. */ @@ -1040,11 +1040,11 @@ _token_paste (glcpp_parser_t *parser, token_t *token, token_t *other) } glcpp_error (&token->location, parser, ""); - ralloc_strcat (&parser->info_log, "Pasting \""); - _token_print (&parser->info_log, token); - ralloc_strcat (&parser->info_log, "\" and \""); - _token_print (&parser->info_log, other); - ralloc_strcat (&parser->info_log, "\" does not give a valid preprocessing token.\n"); + ralloc_asprintf_rewrite_tail (&parser->info_log, &parser->info_log_length, "Pasting \""); + _token_print (&parser->info_log, &parser->info_log_length, token); + ralloc_asprintf_rewrite_tail (&parser->info_log, &parser->info_log_length, "\" and \""); + _token_print (&parser->info_log, &parser->info_log_length, other); + ralloc_asprintf_rewrite_tail (&parser->info_log, &parser->info_log_length, "\" does not give a valid preprocessing token.\n"); return token; } @@ -1058,7 +1058,7 @@ _token_list_print (glcpp_parser_t *parser, token_list_t *list) return; for (node = list->head; node; node = node->next) - _token_print (&parser->output, node->token); + _token_print (&parser->output, &parser->output_length, node->token); } void @@ -1104,7 +1104,9 @@ glcpp_parser_create (const struct gl_extensions *extensions, int api) parser->lex_from_node = NULL; parser->output = ralloc_strdup(parser, ""); + parser->output_length = 0; parser->info_log = ralloc_strdup(parser, ""); + parser->info_log_length = 0; parser->error = 0; /* Add pre-defined macros. */ diff --git a/src/glsl/glcpp/glcpp.h b/src/glsl/glcpp/glcpp.h index dc816e90ee7..2d7cad2e601 100644 --- a/src/glsl/glcpp/glcpp.h +++ b/src/glsl/glcpp/glcpp.h @@ -174,6 +174,8 @@ struct glcpp_parser { token_node_t *lex_from_node; char *output; char *info_log; + size_t output_length; + size_t info_log_length; int error; }; |