aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorPeter Eisentraut <peter@eisentraut.org>2022-07-18 07:43:39 +0200
committerPeter Eisentraut <peter@eisentraut.org>2022-07-18 08:01:27 +0200
commitf58d7073b7750d58b5d53232f0d6a967f902b78f (patch)
treed9967e0b8cd163e1ca28ee763509da89bb33d27f /src
parent8cf64d35eaccab967c51d8bccf2c1babe3f84715 (diff)
downloadpostgresql-f58d7073b7750d58b5d53232f0d6a967f902b78f.tar.gz
postgresql-f58d7073b7750d58b5d53232f0d6a967f902b78f.zip
Convert macros to static inline functions (tupmacs.h)
Reviewed-by: Amul Sul <sulamul@gmail.com> Discussion: https://www.postgresql.org/message-id/flat/5b558da8-99fb-0a99-83dd-f72f05388517%40enterprisedb.com
Diffstat (limited to 'src')
-rw-r--r--src/include/access/itup.h2
-rw-r--r--src/include/access/tupmacs.h154
2 files changed, 58 insertions, 98 deletions
diff --git a/src/include/access/itup.h b/src/include/access/itup.h
index 7458bc2fda6..8bd852b15db 100644
--- a/src/include/access/itup.h
+++ b/src/include/access/itup.h
@@ -114,7 +114,7 @@ typedef IndexAttributeBitMapData * IndexAttributeBitMap;
) \
: \
( \
- (att_isnull((attnum)-1, (char *)(tup) + sizeof(IndexTupleData))) ? \
+ (att_isnull((attnum)-1, (bits8 *)(tup) + sizeof(IndexTupleData))) ? \
( \
*(isnull) = true, \
(Datum)NULL \
diff --git a/src/include/access/tupmacs.h b/src/include/access/tupmacs.h
index 16c74a581e4..8b24cd36586 100644
--- a/src/include/access/tupmacs.h
+++ b/src/include/access/tupmacs.h
@@ -22,8 +22,13 @@
* Note that a 0 in the null bitmap indicates a null, while 1 indicates
* non-null.
*/
-#define att_isnull(ATT, BITS) (!((BITS)[(ATT) >> 3] & (1 << ((ATT) & 0x07))))
+static inline bool
+att_isnull(int ATT, const bits8 *BITS)
+{
+ return !(BITS[ATT >> 3] & (1 << (ATT & 0x07)));
+}
+#ifndef FRONTEND
/*
* Given a Form_pg_attribute and a pointer into a tuple's data area,
* return the correct value or pointer.
@@ -43,56 +48,32 @@
/*
* Same, but work from byval/len parameters rather than Form_pg_attribute.
*/
+static inline Datum
+fetch_att(const void *T, bool attbyval, int attlen)
+{
+ if (attbyval)
+ {
+ switch (attlen)
+ {
+ case sizeof(char):
+ return CharGetDatum(*((const char *) T));
+ case sizeof(int16):
+ return Int16GetDatum(*((const int16 *) T));
+ case sizeof(int32):
+ return Int32GetDatum(*((const int32 *) T));
#if SIZEOF_DATUM == 8
-
-#define fetch_att(T,attbyval,attlen) \
-( \
- (attbyval) ? \
- ( \
- (attlen) == (int) sizeof(Datum) ? \
- *((Datum *)(T)) \
- : \
- ( \
- (attlen) == (int) sizeof(int32) ? \
- Int32GetDatum(*((int32 *)(T))) \
- : \
- ( \
- (attlen) == (int) sizeof(int16) ? \
- Int16GetDatum(*((int16 *)(T))) \
- : \
- ( \
- AssertMacro((attlen) == 1), \
- CharGetDatum(*((char *)(T))) \
- ) \
- ) \
- ) \
- ) \
- : \
- PointerGetDatum((char *) (T)) \
-)
-#else /* SIZEOF_DATUM != 8 */
-
-#define fetch_att(T,attbyval,attlen) \
-( \
- (attbyval) ? \
- ( \
- (attlen) == (int) sizeof(int32) ? \
- Int32GetDatum(*((int32 *)(T))) \
- : \
- ( \
- (attlen) == (int) sizeof(int16) ? \
- Int16GetDatum(*((int16 *)(T))) \
- : \
- ( \
- AssertMacro((attlen) == 1), \
- CharGetDatum(*((char *)(T))) \
- ) \
- ) \
- ) \
- : \
- PointerGetDatum((char *) (T)) \
-)
-#endif /* SIZEOF_DATUM == 8 */
+ case sizeof(Datum):
+ return *((const Datum *) T);
+#endif
+ default:
+ elog(ERROR, "unsupported byval length: %d", attlen);
+ return 0;
+ }
+ }
+ else
+ return PointerGetDatum(T);
+}
+#endif /* FRONTEND */
/*
* att_align_datum aligns the given offset as needed for a datum of alignment
@@ -190,58 +171,37 @@
)) \
)
+#ifndef FRONTEND
/*
* store_att_byval is a partial inverse of fetch_att: store a given Datum
* value into a tuple data area at the specified address. However, it only
* handles the byval case, because in typical usage the caller needs to
- * distinguish by-val and by-ref cases anyway, and so a do-it-all macro
+ * distinguish by-val and by-ref cases anyway, and so a do-it-all function
* wouldn't be convenient.
*/
+static inline void
+store_att_byval(void *T, Datum newdatum, int attlen)
+{
+ switch (attlen)
+ {
+ case sizeof(char):
+ *(char *) T = DatumGetChar(newdatum);
+ break;
+ case sizeof(int16):
+ *(int16 *) T = DatumGetInt16(newdatum);
+ break;
+ case sizeof(int32):
+ *(int32 *) T = DatumGetInt32(newdatum);
+ break;
#if SIZEOF_DATUM == 8
-
-#define store_att_byval(T,newdatum,attlen) \
- do { \
- switch (attlen) \
- { \
- case sizeof(char): \
- *(char *) (T) = DatumGetChar(newdatum); \
- break; \
- case sizeof(int16): \
- *(int16 *) (T) = DatumGetInt16(newdatum); \
- break; \
- case sizeof(int32): \
- *(int32 *) (T) = DatumGetInt32(newdatum); \
- break; \
- case sizeof(Datum): \
- *(Datum *) (T) = (newdatum); \
- break; \
- default: \
- elog(ERROR, "unsupported byval length: %d", \
- (int) (attlen)); \
- break; \
- } \
- } while (0)
-#else /* SIZEOF_DATUM != 8 */
-
-#define store_att_byval(T,newdatum,attlen) \
- do { \
- switch (attlen) \
- { \
- case sizeof(char): \
- *(char *) (T) = DatumGetChar(newdatum); \
- break; \
- case sizeof(int16): \
- *(int16 *) (T) = DatumGetInt16(newdatum); \
- break; \
- case sizeof(int32): \
- *(int32 *) (T) = DatumGetInt32(newdatum); \
- break; \
- default: \
- elog(ERROR, "unsupported byval length: %d", \
- (int) (attlen)); \
- break; \
- } \
- } while (0)
-#endif /* SIZEOF_DATUM == 8 */
-
+ case sizeof(Datum):
+ *(Datum *) T = newdatum;
+ break;
#endif
+ default:
+ elog(ERROR, "unsupported byval length: %d", attlen);
+ }
+}
+#endif /* FRONTEND */
+
+#endif /* TUPMACS_H */