Mesa (master): ralloc: remove memset from ralloc_size
Marek Olšák
mareko at kemper.freedesktop.org
Mon Oct 31 11:26:38 UTC 2016
Module: Mesa
Branch: master
Commit: acc23b04cfd64e0f1dcdb699aaf653376ca6df15
URL: http://cgit.freedesktop.org/mesa/mesa/commit/?id=acc23b04cfd64e0f1dcdb699aaf653376ca6df15
Author: Marek Olšák <marek.olsak at amd.com>
Date: Fri Oct 7 00:51:41 2016 +0200
ralloc: remove memset from ralloc_size
only do it in rzalloc_size as it was supposed to be
Reviewed-by: Edward O'Callaghan <funfunctor at folklore1984.net>
Tested-by: Edmondo Tommasina <edmondo.tommasina at gmail.com>
---
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 7023d79..b202753 100644
--- a/src/util/ralloc.c
+++ b/src/util/ralloc.c
@@ -110,18 +110,6 @@ ralloc_context(const void *ctx)
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;
@@ -140,9 +128,6 @@ rzalloc_size(const void *ctx, size_t size)
info->next = NULL;
info->destructor = NULL;
- /* memset the allocation except for ralloc_header */
- memset(&info[1], 0, size);
-
parent = ctx != NULL ? get_header(ctx) : NULL;
add_child(parent, info);
@@ -154,6 +139,17 @@ rzalloc_size(const void *ctx, size_t size)
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)
More information about the mesa-commit
mailing list