[Mesa-dev] [PATCH 05/15] ralloc: remove memset from ralloc_size
Marek Olšák
maraeo at gmail.com
Sat Oct 8 10:58:29 UTC 2016
From: Marek Olšák <marek.olsak at amd.com>
only do it in rzalloc_size as it was supposed to be
---
src/util/ralloc.c | 26 +++++++++++---------------
1 file changed, 11 insertions(+), 15 deletions(-)
diff --git a/src/util/ralloc.c b/src/util/ralloc.c
index 23c89e5..bf21ac3 100644
--- a/src/util/ralloc.c
+++ b/src/util/ralloc.c
@@ -106,62 +106,58 @@ add_child(ralloc_header *parent, ralloc_header *info)
void *
ralloc_context(const void *ctx)
{
return ralloc_size(ctx, 0);
}
void *
ralloc_size(const void *ctx, size_t size)
{
- /* ralloc_size was originally implemented using calloc, which meant some
- * code accidentally relied on its zero filling behavior.
- *
- * TODO: Make ralloc_size not zero fill memory, and cleanup any code that
- * should instead be using rzalloc.
- */
- return rzalloc_size(ctx, size);
-}
-
-void *
-rzalloc_size(const void *ctx, size_t size)
-{
void *block = malloc(size + sizeof(ralloc_header));
ralloc_header *info;
ralloc_header *parent;
if (unlikely(block == NULL))
return NULL;
info = (ralloc_header *) block;
/* measurements have shown that calloc is slower, so clear things
* manually
*/
info->child = NULL;
info->prev = NULL;
info->destructor = NULL;
/* add_child() clears other members */
- /* memset the allocation except for ralloc_header */
- memset(&info[1], 0, size);
-
parent = ctx != NULL ? get_header(ctx) : NULL;
add_child(parent, info);
#ifdef DEBUG
info->canary = CANARY;
#endif
return PTR_FROM_HEADER(info);
}
+void *
+rzalloc_size(const void *ctx, size_t size)
+{
+ void *ptr = ralloc_size(ctx, size);
+
+ if (likely(ptr))
+ memset(ptr, 0, size);
+
+ return ptr;
+}
+
/* helper function - assumes ptr != NULL */
static void *
resize(void *ptr, size_t size)
{
ralloc_header *child, *old, *info;
old = get_header(ptr);
info = realloc(old, size + sizeof(ralloc_header));
if (info == NULL)
--
2.7.4
More information about the mesa-dev
mailing list