From ebd92f33c9a2b04c533c1e5dfe4f6e7a63f86667 Mon Sep 17 00:00:00 2001
From: japinli <japinli@hotmail.com>
Date: Sat, 26 Sep 2020 00:06:09 +0800
Subject: [PATCH] Optimize memory allocation code

The palloc0() is similar to the palloc(), we can use palloc() inside palloc0()
to allocate space, thereby reducing duplication of code.
---
 src/backend/utils/mmgr/mcxt.c | 22 +---------------------
 1 file changed, 1 insertion(+), 21 deletions(-)

diff --git a/src/backend/utils/mmgr/mcxt.c b/src/backend/utils/mmgr/mcxt.c
index dda70ef9f3..cb07958a1f 100644
--- a/src/backend/utils/mmgr/mcxt.c
+++ b/src/backend/utils/mmgr/mcxt.c
@@ -982,28 +982,8 @@ palloc0(Size size)
 {
 	/* duplicates MemoryContextAllocZero to avoid increased overhead */
 	void	   *ret;
-	MemoryContext context = CurrentMemoryContext;
-
-	AssertArg(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);
+	ret = palloc(size);
 
 	MemSetAligned(ret, 0, size);
 
-- 
2.20.1 (Apple Git-117)

