From 3c080fb4fad3e1c1e34f74a7b84a443137adc9f2 Mon Sep 17 00:00:00 2001 From: Heikki Linnakangas Date: Tue, 19 Dec 2023 12:11:47 +0200 Subject: Simplify newNode() by removing special cases - Remove MemoryContextAllocZeroAligned(). It was supposed to be a faster version of MemoryContextAllocZero(), but modern compilers turn the MemSetLoop() into a call to memset() anyway, making it more or less identical to MemoryContextAllocZero(). That was the only user of MemSetTest, MemSetLoop, so remove those too, as well as palloc0fast(). - Convert newNode() to a static inline function. When this was originally originally written, it was written as a macro because testing showed that gcc didn't inline the size check as we intended. Modern compiler versions do, and now that it just calls palloc0() there is no size-check to inline anyway. One nice effect is that the palloc0() takes one less argument than MemoryContextAllocZeroAligned(), which saves a few instructions in the callers of newNode(). Reviewed-by: Peter Eisentraut, Tom Lane, John Naylor, Thomas Munro Discussion: https://www.postgresql.org/message-id/b51f1fa7-7e6a-4ecc-936d-90a8a1659e7c@iki.fi --- src/backend/utils/mmgr/mcxt.c | 38 -------------------------------------- 1 file changed, 38 deletions(-) (limited to 'src/backend/utils') diff --git a/src/backend/utils/mmgr/mcxt.c b/src/backend/utils/mmgr/mcxt.c index 9fc83f11f6f..4b30fcaebd0 100644 --- a/src/backend/utils/mmgr/mcxt.c +++ b/src/backend/utils/mmgr/mcxt.c @@ -1091,44 +1091,6 @@ MemoryContextAllocZero(MemoryContext context, Size size) return ret; } -/* - * MemoryContextAllocZeroAligned - * MemoryContextAllocZero where length is suitable for MemSetLoop - * - * This might seem overly specialized, but it's not because newNode() - * is so often called with compile-time-constant sizes. - */ -void * -MemoryContextAllocZeroAligned(MemoryContext context, Size size) -{ - void *ret; - - Assert(MemoryContextIsValid(context)); - AssertNotInCriticalSection(context); - - if (!AllocSizeIsValid(size)) - elog(ERROR, "invalid memory alloc request size %zu", size); - - context->isReset = false; - - ret = context->methods->alloc(context, size); - if (unlikely(ret == NULL)) - { - MemoryContextStats(TopMemoryContext); - ereport(ERROR, - (errcode(ERRCODE_OUT_OF_MEMORY), - errmsg("out of memory"), - errdetail("Failed on request of size %zu in memory context \"%s\".", - size, context->name))); - } - - VALGRIND_MEMPOOL_ALLOC(context, ret, size); - - MemSetLoop(ret, 0, size); - - return ret; -} - /* * MemoryContextAllocExtended * Allocate space within the specified context using the given flags. -- cgit v1.2.3