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/include/utils/palloc.h | 14 -------------- 1 file changed, 14 deletions(-) (limited to 'src/include/utils/palloc.h') diff --git a/src/include/utils/palloc.h b/src/include/utils/palloc.h index d1146c12351..cf98ddc0ec9 100644 --- a/src/include/utils/palloc.h +++ b/src/include/utils/palloc.h @@ -70,7 +70,6 @@ extern PGDLLIMPORT MemoryContext CurrentMemoryContext; */ extern void *MemoryContextAlloc(MemoryContext context, Size size); extern void *MemoryContextAllocZero(MemoryContext context, Size size); -extern void *MemoryContextAllocZeroAligned(MemoryContext context, Size size); extern void *MemoryContextAllocExtended(MemoryContext context, Size size, int flags); extern void *MemoryContextAllocAligned(MemoryContext context, @@ -109,19 +108,6 @@ extern void pfree(void *pointer); #define repalloc_array(pointer, type, count) ((type *) repalloc(pointer, sizeof(type) * (count))) #define repalloc0_array(pointer, type, oldcount, count) ((type *) repalloc0(pointer, sizeof(type) * (oldcount), sizeof(type) * (count))) -/* - * The result of palloc() is always word-aligned, so we can skip testing - * alignment of the pointer when deciding which MemSet variant to use. - * Note that this variant does not offer any advantage, and should not be - * used, unless its "sz" argument is a compile-time constant; therefore, the - * issue that it evaluates the argument multiple times isn't a problem in - * practice. - */ -#define palloc0fast(sz) \ - ( MemSetTest(0, sz) ? \ - MemoryContextAllocZeroAligned(CurrentMemoryContext, sz) : \ - MemoryContextAllocZero(CurrentMemoryContext, sz) ) - /* Higher-limit allocators. */ extern void *MemoryContextAllocHuge(MemoryContext context, Size size); extern pg_nodiscard void *repalloc_huge(void *pointer, Size size); -- cgit v1.2.3