From 8fc130783b220c2d94f4960a7613615ca4c75091 Mon Sep 17 00:00:00 2001 From: Caio Oliveira Date: Mon, 18 Sep 2023 02:34:34 -0700 Subject: [PATCH] util: Remove linear_realloc() MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit 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 Part-of: --- src/util/ralloc.c | 19 ------------------- src/util/ralloc.h | 8 -------- 2 files changed, 27 deletions(-) diff --git a/src/util/ralloc.c b/src/util/ralloc.c index a7ce0e4..9c1d013 100644 --- a/src/util/ralloc.c +++ b/src/util/ralloc.c @@ -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. */ diff --git a/src/util/ralloc.h b/src/util/ralloc.h index 54084a2..a20d8e3 100644 --- a/src/util/ralloc.h +++ b/src/util/ralloc.h @@ -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. -- 2.7.4