Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
Skip to content

Commit d63d957

Browse files
committed
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
1 parent 495ed0e commit d63d957

File tree

1 file changed

+23
-30
lines changed

1 file changed

+23
-30
lines changed

src/include/storage/block.h

+23-30
Original file line numberDiff line numberDiff line change
@@ -59,57 +59,50 @@ typedef struct BlockIdData
5959
typedef BlockIdData *BlockId; /* block identifier */
6060

6161
/* ----------------
62-
* support macros
62+
* support functions
6363
* ----------------
6464
*/
6565

6666
/*
6767
* BlockNumberIsValid
6868
* True iff blockNumber is valid.
6969
*/
70-
#define BlockNumberIsValid(blockNumber) \
71-
((BlockNumber) (blockNumber) != InvalidBlockNumber)
72-
73-
/*
74-
* BlockIdIsValid
75-
* True iff the block identifier is valid.
76-
*/
77-
#define BlockIdIsValid(blockId) \
78-
PointerIsValid(blockId)
70+
static inline bool
71+
BlockNumberIsValid(BlockNumber blockNumber)
72+
{
73+
return blockNumber != InvalidBlockNumber;
74+
}
7975

8076
/*
8177
* BlockIdSet
8278
* Sets a block identifier to the specified value.
8379
*/
84-
#define BlockIdSet(blockId, blockNumber) \
85-
( \
86-
(blockId)->bi_hi = (blockNumber) >> 16, \
87-
(blockId)->bi_lo = (blockNumber) & 0xffff \
88-
)
89-
90-
/*
91-
* BlockIdCopy
92-
* Copy a block identifier.
93-
*/
94-
#define BlockIdCopy(toBlockId, fromBlockId) \
95-
( \
96-
(toBlockId)->bi_hi = (fromBlockId)->bi_hi, \
97-
(toBlockId)->bi_lo = (fromBlockId)->bi_lo \
98-
)
80+
static inline void
81+
BlockIdSet(BlockIdData *blockId, BlockNumber blockNumber)
82+
{
83+
blockId->bi_hi = blockNumber >> 16;
84+
blockId->bi_lo = blockNumber & 0xffff;
85+
}
9986

10087
/*
10188
* BlockIdEquals
10289
* Check for block number equality.
10390
*/
104-
#define BlockIdEquals(blockId1, blockId2) \
105-
((blockId1)->bi_hi == (blockId2)->bi_hi && \
106-
(blockId1)->bi_lo == (blockId2)->bi_lo)
91+
static inline bool
92+
BlockIdEquals(const BlockIdData *blockId1, const BlockIdData *blockId2)
93+
{
94+
return (blockId1->bi_hi == blockId2->bi_hi &&
95+
blockId1->bi_lo == blockId2->bi_lo);
96+
}
10797

10898
/*
10999
* BlockIdGetBlockNumber
110100
* Retrieve the block number from a block identifier.
111101
*/
112-
#define BlockIdGetBlockNumber(blockId) \
113-
((((BlockNumber) (blockId)->bi_hi) << 16) | ((BlockNumber) (blockId)->bi_lo))
102+
static inline BlockNumber
103+
BlockIdGetBlockNumber(const BlockIdData *blockId)
104+
{
105+
return (((BlockNumber) blockId->bi_hi) << 16) | ((BlockNumber) blockId->bi_lo);
106+
}
114107

115108
#endif /* BLOCK_H */

0 commit comments

Comments
 (0)