Skip to content

Commit 9c72736

Browse files
committed
Convert macros to static inline functions (bufmgr.h)
Reviewed-by: Amul Sul <sulamul@gmail.com> Discussion: https://www.postgresql.org/message-id/flat/5b558da8-99fb-0a99-83dd-f72f05388517%40enterprisedb.com
1 parent aeb767c commit 9c72736

File tree

1 file changed

+36
-23
lines changed

1 file changed

+36
-23
lines changed

src/include/storage/bufmgr.h

Lines changed: 36 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,7 @@ extern PGDLLIMPORT int32 *LocalRefCount;
9898
#define BUFFER_LOCK_EXCLUSIVE 2
9999

100100
/*
101-
* These routines are beaten on quite heavily, hence the macroization.
101+
* These routines are beaten on quite heavily, hence inline.
102102
*/
103103

104104
/*
@@ -120,11 +120,14 @@ extern PGDLLIMPORT int32 *LocalRefCount;
120120
* even in non-assert-enabled builds can be significant. Thus, we've
121121
* now demoted the range checks to assertions within the macro itself.
122122
*/
123-
#define BufferIsValid(bufnum) \
124-
( \
125-
AssertMacro((bufnum) <= NBuffers && (bufnum) >= -NLocBuffer), \
126-
(bufnum) != InvalidBuffer \
127-
)
123+
static inline bool
124+
BufferIsValid(Buffer bufnum)
125+
{
126+
Assert(bufnum <= NBuffers);
127+
Assert(bufnum >= -NLocBuffer);
128+
129+
return bufnum != InvalidBuffer;
130+
}
128131

129132
/*
130133
* BufferGetBlock
@@ -133,14 +136,16 @@ extern PGDLLIMPORT int32 *LocalRefCount;
133136
* Note:
134137
* Assumes buffer is valid.
135138
*/
136-
#define BufferGetBlock(buffer) \
137-
( \
138-
AssertMacro(BufferIsValid(buffer)), \
139-
BufferIsLocal(buffer) ? \
140-
LocalBufferBlockPointers[-(buffer) - 1] \
141-
: \
142-
(Block) (BufferBlocks + ((Size) ((buffer) - 1)) * BLCKSZ) \
143-
)
139+
static inline Block
140+
BufferGetBlock(Buffer buffer)
141+
{
142+
Assert(BufferIsValid(buffer));
143+
144+
if (BufferIsLocal(buffer))
145+
return LocalBufferBlockPointers[-buffer - 1];
146+
else
147+
return (Block) (BufferBlocks + ((Size) (buffer - 1)) * BLCKSZ);
148+
}
144149

145150
/*
146151
* BufferGetPageSize
@@ -153,11 +158,12 @@ extern PGDLLIMPORT int32 *LocalRefCount;
153158
* (formatted) disk page.
154159
*/
155160
/* XXX should dig out of buffer descriptor */
156-
#define BufferGetPageSize(buffer) \
157-
( \
158-
AssertMacro(BufferIsValid(buffer)), \
159-
(Size)BLCKSZ \
160-
)
161+
static inline Size
162+
BufferGetPageSize(Buffer buffer)
163+
{
164+
AssertMacro(BufferIsValid(buffer));
165+
return (Size) BLCKSZ;
166+
}
161167

162168
/*
163169
* BufferGetPage
@@ -166,7 +172,11 @@ extern PGDLLIMPORT int32 *LocalRefCount;
166172
* When this is called as part of a scan, there may be a need for a nearby
167173
* call to TestForOldSnapshot(). See the definition of that for details.
168174
*/
169-
#define BufferGetPage(buffer) ((Page)BufferGetBlock(buffer))
175+
static inline Page
176+
BufferGetPage(Buffer buffer)
177+
{
178+
return (Page) BufferGetBlock(buffer);
179+
}
170180

171181
/*
172182
* prototypes for functions in bufmgr.c
@@ -201,6 +211,12 @@ extern void CheckPointBuffers(int flags);
201211
extern BlockNumber BufferGetBlockNumber(Buffer buffer);
202212
extern BlockNumber RelationGetNumberOfBlocksInFork(Relation relation,
203213
ForkNumber forkNum);
214+
static inline BlockNumber
215+
RelationGetNumberOfBlocks(Relation reln)
216+
{
217+
return RelationGetNumberOfBlocksInFork(reln, MAIN_FORKNUM);
218+
}
219+
204220
extern void FlushOneBuffer(Buffer buffer);
205221
extern void FlushRelationBuffers(Relation rel);
206222
extern void FlushRelationsAllBuffers(struct SMgrRelationData **smgrs, int nrels);
@@ -215,9 +231,6 @@ extern void DropRelationsAllBuffers(struct SMgrRelationData **smgr_reln,
215231
int nlocators);
216232
extern void DropDatabaseBuffers(Oid dbid);
217233

218-
#define RelationGetNumberOfBlocks(reln) \
219-
RelationGetNumberOfBlocksInFork(reln, MAIN_FORKNUM)
220-
221234
extern bool BufferIsPermanent(Buffer buffer);
222235
extern XLogRecPtr BufferGetLSNAtomic(Buffer buffer);
223236

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy