util: Remove linear_realloc()
authorCaio Oliveira <caio.oliveira@intel.com>
Mon, 18 Sep 2023 09:34:34 +0000 (02:34 -0700)
committerMarge Bot <emma+marge@anholt.net>
Mon, 25 Sep 2023 17:26:17 +0000 (17:26 +0000)
Now that linear_realloc() is unused, remove it.  It is not an actual
realloc, will always allocate new memory and copy data around -- and
had a big warning about it in the documentation.

In the couple of uses we had before, the client code knew the size,
so it could be changed to perform the allocation and the copy by
themselves.  The client code keeping the size is the recommended
way here.

This will allow us remove linear_size_chunk later.

Reviewed-by: Marek Olšák <marek.olsak@amd.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/25280>

src/util/ralloc.c
src/util/ralloc.h

index a7ce0e4..9c1d013 100644 (file)
@@ -1112,25 +1112,6 @@ ralloc_parent_of_linear_context(linear_ctx *ctx)
    return PTR_FROM_HEADER(get_header(node)->parent);
 }
 
-void *
-linear_realloc(linear_ctx *ctx, void *old, unsigned new_size)
-{
-   unsigned old_size = 0;
-   ralloc_header *new_ptr;
-
-   new_ptr = linear_alloc_child(ctx, new_size);
-
-   if (unlikely(!old))
-      return new_ptr;
-
-   old_size = ((linear_size_chunk*)old)[-1].size;
-
-   if (likely(new_ptr && old_size))
-      memcpy(new_ptr, old, MIN2(old_size, new_size));
-
-   return new_ptr;
-}
-
 /* All code below is pretty much copied from ralloc and only the alloc
  * calls are different.
  */
index 54084a2..a20d8e3 100644 (file)
@@ -610,14 +610,6 @@ void ralloc_steal_linear_context(void *new_ralloc_ctx, linear_ctx *ctx);
 void *ralloc_parent_of_linear_context(linear_ctx *ctx);
 
 /**
- * Same as realloc except that the linear allocator doesn't free child nodes,
- * so it's reduced to memory duplication. It's used in places where
- * reallocation is required. Don't use it often. It's much slower than
- * realloc.
- */
-void *linear_realloc(linear_ctx *ctx, void *old, unsigned new_size);
-
-/**
  * Do a fast allocation of an array from the linear context and initialize it to zero.
  *
  * Similar to \c calloc, but does not initialize the memory to zero.