0004-Convert-macros-to-static-inline-functions-bufmgr.h.patch

text/plain

Filename: 0004-Convert-macros-to-static-inline-functions-bufmgr.h.patch
Type: text/plain
Part: 3
Message: Convert macros to static inline functions

Patch

Format: format-patch
Series: patch 0004
Subject: Convert macros to static inline functions (bufmgr.h)
File+
src/include/storage/bufmgr.h 30 20
From 86ce1edc994669bd3c86965e1c264951a231c6ca Mon Sep 17 00:00:00 2001
From: Peter Eisentraut <peter@eisentraut.org>
Date: Mon, 16 May 2022 09:58:13 +0200
Subject: [PATCH] Convert macros to static inline functions (bufmgr.h)

---
 src/include/storage/bufmgr.h | 50 +++++++++++++++++++++---------------
 1 file changed, 30 insertions(+), 20 deletions(-)

diff --git a/src/include/storage/bufmgr.h b/src/include/storage/bufmgr.h
index 58391406f6..ce725afa5e 100644
--- a/src/include/storage/bufmgr.h
+++ b/src/include/storage/bufmgr.h
@@ -98,7 +98,7 @@ extern PGDLLIMPORT int32 *LocalRefCount;
 #define BUFFER_LOCK_EXCLUSIVE	2
 
 /*
- * These routines are beaten on quite heavily, hence the macroization.
+ * These routines are beaten on quite heavily, hence inline.
  */
 
 /*
@@ -120,11 +120,14 @@ extern PGDLLIMPORT int32 *LocalRefCount;
  * even in non-assert-enabled builds can be significant.  Thus, we've
  * now demoted the range checks to assertions within the macro itself.
  */
-#define BufferIsValid(bufnum) \
-( \
-	AssertMacro((bufnum) <= NBuffers && (bufnum) >= -NLocBuffer), \
-	(bufnum) != InvalidBuffer  \
-)
+static inline bool
+BufferIsValid(Buffer bufnum)
+{
+	Assert(bufnum <= NBuffers);
+	Assert(bufnum >= -NLocBuffer);
+
+	return bufnum != InvalidBuffer;
+}
 
 /*
  * BufferGetBlock
@@ -133,14 +136,16 @@ extern PGDLLIMPORT int32 *LocalRefCount;
  * Note:
  *		Assumes buffer is valid.
  */
-#define BufferGetBlock(buffer) \
-( \
-	AssertMacro(BufferIsValid(buffer)), \
-	BufferIsLocal(buffer) ? \
-		LocalBufferBlockPointers[-(buffer) - 1] \
-	: \
-		(Block) (BufferBlocks + ((Size) ((buffer) - 1)) * BLCKSZ) \
-)
+static inline Block
+BufferGetBlock(Buffer buffer)
+{
+	Assert(BufferIsValid(buffer));
+
+	if (BufferIsLocal(buffer))
+		return LocalBufferBlockPointers[-buffer - 1];
+	else
+		return (Block) (BufferBlocks + ((Size) (buffer - 1)) * BLCKSZ);
+}
 
 /*
  * BufferGetPageSize
@@ -153,11 +158,12 @@ extern PGDLLIMPORT int32 *LocalRefCount;
  *		(formatted) disk page.
  */
 /* XXX should dig out of buffer descriptor */
-#define BufferGetPageSize(buffer) \
-( \
-	AssertMacro(BufferIsValid(buffer)), \
-	(Size)BLCKSZ \
-)
+static inline Size
+BufferGetPageSize(Buffer buffer)
+{
+	AssertMacro(BufferIsValid(buffer));
+	return (Size) BLCKSZ;
+}
 
 /*
  * BufferGetPage
@@ -166,7 +172,11 @@ extern PGDLLIMPORT int32 *LocalRefCount;
  * When this is called as part of a scan, there may be a need for a nearby
  * call to TestForOldSnapshot().  See the definition of that for details.
  */
-#define BufferGetPage(buffer) ((Page)BufferGetBlock(buffer))
+static inline Page
+BufferGetPage(Buffer buffer)
+{
+	return (Page) BufferGetBlock(buffer);
+}
 
 /*
  * prototypes for functions in bufmgr.c
-- 
2.35.1