From 9dd948206d3f8bd3c1b19c00af7e73c8070dae52 Mon Sep 17 00:00:00 2001 From: Peter Eisentraut Date: Mon, 23 May 2022 07:28:13 +0200 Subject: [PATCH v2] Convert macros to static inline functions (bufmgr.h) Discussion: https://www.postgresql.org/message-id/flat/5b558da8-99fb-0a99-83dd-f72f05388517%40enterprisedb.com --- 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.36.1