summaryrefslogtreecommitdiffstats
path: root/src/glsl/ralloc.c
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/ralloc.c
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/ralloc.c')
-rw-r--r--src/glsl/ralloc.c11
1 files changed, 6 insertions, 5 deletions
diff --git a/src/glsl/ralloc.c b/src/glsl/ralloc.c
index 91e4bab2ebd..2f93dcdeaf7 100644
--- a/src/glsl/ralloc.c
+++ b/src/glsl/ralloc.c
@@ -448,11 +448,11 @@ ralloc_vasprintf_append(char **str, const char *fmt, va_list args)
size_t existing_length;
assert(str != NULL);
existing_length = *str ? strlen(*str) : 0;
- return ralloc_vasprintf_rewrite_tail(str, existing_length, fmt, args);
+ return ralloc_vasprintf_rewrite_tail(str, &existing_length, fmt, args);
}
bool
-ralloc_asprintf_rewrite_tail(char **str, size_t start, const char *fmt, ...)
+ralloc_asprintf_rewrite_tail(char **str, size_t *start, const char *fmt, ...)
{
bool success;
va_list args;
@@ -463,7 +463,7 @@ ralloc_asprintf_rewrite_tail(char **str, size_t start, const char *fmt, ...)
}
bool
-ralloc_vasprintf_rewrite_tail(char **str, size_t start, const char *fmt,
+ralloc_vasprintf_rewrite_tail(char **str, size_t *start, const char *fmt,
va_list args)
{
size_t new_length;
@@ -479,11 +479,12 @@ ralloc_vasprintf_rewrite_tail(char **str, size_t start, const char *fmt,
new_length = printf_length(fmt, args);
- ptr = resize(*str, start + new_length + 1);
+ ptr = resize(*str, *start + new_length + 1);
if (unlikely(ptr == NULL))
return false;
- vsnprintf(ptr + start, new_length + 1, fmt, args);
+ vsnprintf(ptr + *start, new_length + 1, fmt, args);
*str = ptr;
+ *start += new_length;
return true;
}