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
This commit is contained in:
parent
2cbc3c17a5
commit
14a8bd9827
@ -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 */
|
||||
|
Loading…
x
Reference in New Issue
Block a user