0001-Convert-macros-to-static-inline-functions-block.h.patch

text/plain

Filename: 0001-Convert-macros-to-static-inline-functions-block.h.patch
Type: text/plain
Part: 0
Message: Convert macros to static inline functions

Patch

Format: format-patch
Series: patch 0001
Subject: Convert macros to static inline functions (block.h)
File+
src/include/storage/block.h 23 30
From 3c1abb1cb26bd58b09a5416ae7df192a9c247653 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 (block.h)

Remove BlockIdIsValid(), which wasn't used and is unnecessary.

Remove BlockIdCopy(), which wasn't used and can be done by struct
assignment.

(BlockIdEquals() also isn't used, but seems reasonable to keep
around.)
---
 src/include/storage/block.h | 53 ++++++++++++++++---------------------
 1 file changed, 23 insertions(+), 30 deletions(-)

diff --git a/src/include/storage/block.h b/src/include/storage/block.h
index d756e3fda5..c726142f96 100644
--- a/src/include/storage/block.h
+++ b/src/include/storage/block.h
@@ -59,7 +59,7 @@ typedef struct BlockIdData
 typedef BlockIdData *BlockId;	/* block identifier */
 
 /* ----------------
- *		support macros
+ *		support functions
  * ----------------
  */
 
@@ -67,49 +67,42 @@ typedef BlockIdData *BlockId;	/* block identifier */
  * BlockNumberIsValid
  *		True iff blockNumber is valid.
  */
-#define BlockNumberIsValid(blockNumber) \
-	((BlockNumber) (blockNumber) != InvalidBlockNumber)
-
-/*
- * BlockIdIsValid
- *		True iff the block identifier is valid.
- */
-#define BlockIdIsValid(blockId) \
-	PointerIsValid(blockId)
+static inline bool
+BlockNumberIsValid(BlockNumber blockNumber)
+{
+	return blockNumber != InvalidBlockNumber;
+}
 
 /*
  * BlockIdSet
  *		Sets a block identifier to the specified value.
  */
-#define BlockIdSet(blockId, blockNumber) \
-( \
-	(blockId)->bi_hi = (blockNumber) >> 16, \
-	(blockId)->bi_lo = (blockNumber) & 0xffff \
-)
-
-/*
- * BlockIdCopy
- *		Copy a block identifier.
- */
-#define BlockIdCopy(toBlockId, fromBlockId) \
-( \
-	(toBlockId)->bi_hi = (fromBlockId)->bi_hi, \
-	(toBlockId)->bi_lo = (fromBlockId)->bi_lo \
-)
+static inline void
+BlockIdSet(BlockIdData *blockId, BlockNumber blockNumber)
+{
+	blockId->bi_hi = blockNumber >> 16;
+	blockId->bi_lo = blockNumber & 0xffff;
+}
 
 /*
  * BlockIdEquals
  *		Check for block number equality.
  */
-#define BlockIdEquals(blockId1, blockId2) \
-	((blockId1)->bi_hi == (blockId2)->bi_hi && \
-	 (blockId1)->bi_lo == (blockId2)->bi_lo)
+static inline bool
+BlockIdEquals(const BlockIdData *blockId1, const BlockIdData *blockId2)
+{
+	return (blockId1->bi_hi == blockId2->bi_hi &&
+			blockId1->bi_lo == blockId2->bi_lo);
+}
 
 /*
  * BlockIdGetBlockNumber
  *		Retrieve the block number from a block identifier.
  */
-#define BlockIdGetBlockNumber(blockId) \
-	((((BlockNumber) (blockId)->bi_hi) << 16) | ((BlockNumber) (blockId)->bi_lo))
+static inline BlockNumber
+BlockIdGetBlockNumber(const BlockIdData *blockId)
+{
+	return (((BlockNumber) (blockId)->bi_hi) << 16) | ((BlockNumber) (blockId)->bi_lo);
+}
 
 #endif							/* BLOCK_H */
-- 
2.35.1