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.)

Reviewed-by: Amul Sul <sulamul@gmail.com>
Discussion: https://www.postgresql.org/message-id/flat/5b558da8-99fb-0a99-83dd-f72f05388517%40enterprisedb.com
This commit is contained in:
Peter Eisentraut 2022-07-07 08:30:52 +02:00
parent 495ed0ef2d
commit d63d957e33

View File

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