@@ -78,20 +78,24 @@ extern PGDLLIMPORT int32 *LocalRefCount;
78
78
* True iff the given buffer number is valid (either as a shared
79
79
* or local buffer).
80
80
*
81
- * This is not quite the inverse of the BufferIsInvalid() macro, since this
82
- * adds sanity rangechecks on the buffer number.
83
- *
84
81
* Note: For a long time this was defined the same as BufferIsPinned,
85
82
* that is it would say False if you didn't hold a pin on the buffer.
86
83
* I believe this was bogus and served only to mask logic errors.
87
84
* Code should always know whether it has a buffer reference,
88
85
* independently of the pin state.
86
+ *
87
+ * Note: For a further long time this was not quite the inverse of the
88
+ * BufferIsInvalid() macro, in that it also did sanity checks to verify
89
+ * that the buffer number was in range. Most likely, this macro was
90
+ * originally intended only to be used in assertions, but its use has
91
+ * since expanded quite a bit, and the overhead of making those checks
92
+ * even in non-assert-enabled builds can be significant. Thus, we've
93
+ * now demoted the range checks to assertions within the macro itself.
89
94
*/
90
95
#define BufferIsValid (bufnum ) \
91
96
( \
92
- (bufnum) != InvalidBuffer && \
93
- (bufnum) >= -NLocBuffer && \
94
- (bufnum) <= NBuffers \
97
+ AssertMacro((bufnum) <= NBuffers && (bufnum) >= -NLocBuffer), \
98
+ (bufnum) != InvalidBuffer \
95
99
)
96
100
97
101
/*
0 commit comments