diff options
author | Peter Eisentraut <peter@eisentraut.org> | 2022-07-19 06:58:11 +0200 |
---|---|---|
committer | Peter Eisentraut <peter@eisentraut.org> | 2022-07-19 07:24:55 +0200 |
commit | 14a8bd98274aaf51912b29cbb869696fc825da00 (patch) | |
tree | 7c3201b9d04a1e441ff070eeadf0c679d71bda95 /src | |
parent | 2cbc3c17a5c11d13c0ac92fe7557c56408f8f3d0 (diff) | |
download | postgresql-14a8bd98274aaf51912b29cbb869696fc825da00.tar.gz postgresql-14a8bd98274aaf51912b29cbb869696fc825da00.zip |
Convert macros to static inline functions (itup.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.h | 117 |
1 files changed, 60 insertions, 57 deletions
diff --git a/src/include/access/itup.h b/src/include/access/itup.h index 8bd852b15db..773cef8b3a3 100644 --- a/src/include/access/itup.h +++ b/src/include/access/itup.h @@ -73,21 +73,38 @@ typedef IndexAttributeBitMapData * IndexAttributeBitMap; #define IndexTupleHasVarwidths(itup) ((((IndexTuple) (itup))->t_info & INDEX_VAR_MASK)) +/* routines in indextuple.c */ +extern IndexTuple index_form_tuple(TupleDesc tupleDescriptor, + Datum *values, bool *isnull); +extern IndexTuple index_form_tuple_context(TupleDesc tupleDescriptor, + Datum *values, bool *isnull, + MemoryContext context); +extern Datum nocache_index_getattr(IndexTuple tup, int attnum, + TupleDesc tupleDesc); +extern void index_deform_tuple(IndexTuple tup, TupleDesc tupleDescriptor, + Datum *values, bool *isnull); +extern void index_deform_tuple_internal(TupleDesc tupleDescriptor, + Datum *values, bool *isnull, + char *tp, bits8 *bp, int hasnulls); +extern IndexTuple CopyIndexTuple(IndexTuple source); +extern IndexTuple index_truncate_tuple(TupleDesc sourceDescriptor, + IndexTuple source, int leavenatts); + + /* * Takes an infomask as argument (primarily because this needs to be usable * at index_form_tuple time so enough space is allocated). */ -#define IndexInfoFindDataOffset(t_info) \ -( \ - (!((t_info) & INDEX_NULL_MASK)) ? \ - ( \ - (Size)MAXALIGN(sizeof(IndexTupleData)) \ - ) \ - : \ - ( \ - (Size)MAXALIGN(sizeof(IndexTupleData) + sizeof(IndexAttributeBitMapData)) \ - ) \ -) +static inline Size +IndexInfoFindDataOffset(unsigned short t_info) +{ + if (!(t_info & INDEX_NULL_MASK)) + return MAXALIGN(sizeof(IndexTupleData)); + else + return MAXALIGN(sizeof(IndexTupleData) + sizeof(IndexAttributeBitMapData)); +} + +#ifndef FRONTEND /* ---------------- * index_getattr @@ -97,34 +114,38 @@ typedef IndexAttributeBitMapData * IndexAttributeBitMap; * * ---------------- */ -#define index_getattr(tup, attnum, tupleDesc, isnull) \ -( \ - AssertMacro(PointerIsValid(isnull) && (attnum) > 0), \ - *(isnull) = false, \ - !IndexTupleHasNulls(tup) ? \ - ( \ - TupleDescAttr((tupleDesc), (attnum)-1)->attcacheoff >= 0 ? \ - ( \ - fetchatt(TupleDescAttr((tupleDesc), (attnum)-1), \ - (char *) (tup) + IndexInfoFindDataOffset((tup)->t_info) \ - + TupleDescAttr((tupleDesc), (attnum)-1)->attcacheoff) \ - ) \ - : \ - nocache_index_getattr((tup), (attnum), (tupleDesc)) \ - ) \ - : \ - ( \ - (att_isnull((attnum)-1, (bits8 *)(tup) + sizeof(IndexTupleData))) ? \ - ( \ - *(isnull) = true, \ - (Datum)NULL \ - ) \ - : \ - ( \ - nocache_index_getattr((tup), (attnum), (tupleDesc)) \ - ) \ - ) \ -) +static inline Datum +index_getattr(IndexTuple tup, int attnum, TupleDesc tupleDesc, bool *isnull) +{ + Assert(PointerIsValid(isnull)); + Assert(attnum > 0); + + *isnull = false; + + if (!IndexTupleHasNulls(tup)) + { + if (TupleDescAttr(tupleDesc, attnum - 1)->attcacheoff >= 0) + { + return fetchatt(TupleDescAttr(tupleDesc, attnum - 1), + (char *) tup + IndexInfoFindDataOffset(tup->t_info) + + TupleDescAttr(tupleDesc, attnum - 1)->attcacheoff); + } + else + return nocache_index_getattr(tup, attnum, tupleDesc); + } + else + { + if (att_isnull(attnum - 1, (bits8 *) tup + sizeof(IndexTupleData))) + { + *isnull = true; + return (Datum) NULL; + } + else + return nocache_index_getattr(tup, attnum, tupleDesc); + } +} + +#endif /* * MaxIndexTuplesPerPage is an upper bound on the number of tuples that can @@ -146,22 +167,4 @@ typedef IndexAttributeBitMapData * IndexAttributeBitMap; ((int) ((BLCKSZ - SizeOfPageHeaderData) / \ (MAXALIGN(sizeof(IndexTupleData) + 1) + sizeof(ItemIdData)))) - -/* routines in indextuple.c */ -extern IndexTuple index_form_tuple(TupleDesc tupleDescriptor, - Datum *values, bool *isnull); -extern IndexTuple index_form_tuple_context(TupleDesc tupleDescriptor, - Datum *values, bool *isnull, - MemoryContext context); -extern Datum nocache_index_getattr(IndexTuple tup, int attnum, - TupleDesc tupleDesc); -extern void index_deform_tuple(IndexTuple tup, TupleDesc tupleDescriptor, - Datum *values, bool *isnull); -extern void index_deform_tuple_internal(TupleDesc tupleDescriptor, - Datum *values, bool *isnull, - char *tp, bits8 *bp, int hasnulls); -extern IndexTuple CopyIndexTuple(IndexTuple source); -extern IndexTuple index_truncate_tuple(TupleDesc sourceDescriptor, - IndexTuple source, int leavenatts); - #endif /* ITUP_H */ |