summaryrefslogtreecommitdiffstats
path: root/src/glsl/link_uniforms.cpp
diff options
context:
space:
mode:
authorKenneth Graunke <[email protected]>2012-02-09 20:03:36 -0800
committerKenneth Graunke <[email protected]>2012-02-28 13:07:12 -0800
commit8292b7419d0405e94a5ea270ba710d20f0eb071f (patch)
tree06aacf1c3dfc3c592909f54bb57a48d56267c3a8 /src/glsl/link_uniforms.cpp
parent579ccae73d29211c9f5c01ba527e1743ea39c94e (diff)
ralloc: Make rewrite_tail increase "start" by the new text's length.
Both callers of rewrite_tail immediately compute the new total string length by adding the (known) length of the existing string plus the length of the newly appended text. Unfortunately, callers generally won't know the length of the new text, as it's printf-formatted. Since ralloc already computes this length, it makes sense to add it in and save the caller the effort. This simplifies both existing callers, but more importantly, will allow for cheap-appending in the next commit. v2: The link_uniforms code needs both the old and new length. Apply the obvious fix (which sadly makes it less of a cleanup). Signed-off-by: Kenneth Graunke <[email protected]> Reviewed-by: Ian Romanick <[email protected]> [v1] Acked-by: José Fonseca <[email protected]> [v1]
Diffstat (limited to 'src/glsl/link_uniforms.cpp')
-rw-r--r--src/glsl/link_uniforms.cpp15
1 files changed, 7 insertions, 8 deletions
diff --git a/src/glsl/link_uniforms.cpp b/src/glsl/link_uniforms.cpp
index d51850c216a..613c9b7ae22 100644
--- a/src/glsl/link_uniforms.cpp
+++ b/src/glsl/link_uniforms.cpp
@@ -67,7 +67,7 @@ uniform_field_visitor::process(ir_variable *var)
void
uniform_field_visitor::recursion(const glsl_type *t, char **name,
- unsigned name_length)
+ size_t name_length)
{
/* Records need to have each field processed individually.
*
@@ -78,22 +78,21 @@ uniform_field_visitor::recursion(const glsl_type *t, char **name,
if (t->is_record()) {
for (unsigned i = 0; i < t->length; i++) {
const char *field = t->fields.structure[i].name;
+ size_t new_length = name_length;
/* Append '.field' to the current uniform name. */
- ralloc_asprintf_rewrite_tail(name, name_length, ".%s", field);
+ ralloc_asprintf_rewrite_tail(name, &new_length, ".%s", field);
- recursion(t->fields.structure[i].type, name,
- name_length + 1 + strlen(field));
+ recursion(t->fields.structure[i].type, name, new_length);
}
} else if (t->is_array() && t->fields.array->is_record()) {
for (unsigned i = 0; i < t->length; i++) {
- char subscript[13];
+ size_t new_length = name_length;
/* Append the subscript to the current uniform name */
- const unsigned subscript_length = snprintf(subscript, 13, "[%u]", i);
- ralloc_asprintf_rewrite_tail(name, name_length, "%s", subscript);
+ ralloc_asprintf_rewrite_tail(name, &new_length, "[%u]", i);
- recursion(t->fields.array, name, name_length + subscript_length);
+ recursion(t->fields.array, name, new_length);
}
} else {
this->visit_field(t, *name);