Skip to content

Commit 14a8bd9

Browse files
committed
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
1 parent 2cbc3c1 commit 14a8bd9

File tree

1 file changed

+60
-57
lines changed

1 file changed

+60
-57
lines changed

src/include/access/itup.h

Lines changed: 60 additions & 57 deletions
Original file line numberDiff line numberDiff line change
@@ -73,21 +73,38 @@ typedef IndexAttributeBitMapData * IndexAttributeBitMap;
7373
#define IndexTupleHasVarwidths(itup) ((((IndexTuple) (itup))->t_info & INDEX_VAR_MASK))
7474

7575

76+
/* routines in indextuple.c */
77+
extern IndexTuple index_form_tuple(TupleDesc tupleDescriptor,
78+
Datum *values, bool *isnull);
79+
extern IndexTuple index_form_tuple_context(TupleDesc tupleDescriptor,
80+
Datum *values, bool *isnull,
81+
MemoryContext context);
82+
extern Datum nocache_index_getattr(IndexTuple tup, int attnum,
83+
TupleDesc tupleDesc);
84+
extern void index_deform_tuple(IndexTuple tup, TupleDesc tupleDescriptor,
85+
Datum *values, bool *isnull);
86+
extern void index_deform_tuple_internal(TupleDesc tupleDescriptor,
87+
Datum *values, bool *isnull,
88+
char *tp, bits8 *bp, int hasnulls);
89+
extern IndexTuple CopyIndexTuple(IndexTuple source);
90+
extern IndexTuple index_truncate_tuple(TupleDesc sourceDescriptor,
91+
IndexTuple source, int leavenatts);
92+
93+
7694
/*
7795
* Takes an infomask as argument (primarily because this needs to be usable
7896
* at index_form_tuple time so enough space is allocated).
7997
*/
80-
#define IndexInfoFindDataOffset(t_info) \
81-
( \
82-
(!((t_info) & INDEX_NULL_MASK)) ? \
83-
( \
84-
(Size)MAXALIGN(sizeof(IndexTupleData)) \
85-
) \
86-
: \
87-
( \
88-
(Size)MAXALIGN(sizeof(IndexTupleData) + sizeof(IndexAttributeBitMapData)) \
89-
) \
90-
)
98+
static inline Size
99+
IndexInfoFindDataOffset(unsigned short t_info)
100+
{
101+
if (!(t_info & INDEX_NULL_MASK))
102+
return MAXALIGN(sizeof(IndexTupleData));
103+
else
104+
return MAXALIGN(sizeof(IndexTupleData) + sizeof(IndexAttributeBitMapData));
105+
}
106+
107+
#ifndef FRONTEND
91108

92109
/* ----------------
93110
* index_getattr
@@ -97,34 +114,38 @@ typedef IndexAttributeBitMapData * IndexAttributeBitMap;
97114
*
98115
* ----------------
99116
*/
100-
#define index_getattr(tup, attnum, tupleDesc, isnull) \
101-
( \
102-
AssertMacro(PointerIsValid(isnull) && (attnum) > 0), \
103-
*(isnull) = false, \
104-
!IndexTupleHasNulls(tup) ? \
105-
( \
106-
TupleDescAttr((tupleDesc), (attnum)-1)->attcacheoff >= 0 ? \
107-
( \
108-
fetchatt(TupleDescAttr((tupleDesc), (attnum)-1), \
109-
(char *) (tup) + IndexInfoFindDataOffset((tup)->t_info) \
110-
+ TupleDescAttr((tupleDesc), (attnum)-1)->attcacheoff) \
111-
) \
112-
: \
113-
nocache_index_getattr((tup), (attnum), (tupleDesc)) \
114-
) \
115-
: \
116-
( \
117-
(att_isnull((attnum)-1, (bits8 *)(tup) + sizeof(IndexTupleData))) ? \
118-
( \
119-
*(isnull) = true, \
120-
(Datum)NULL \
121-
) \
122-
: \
123-
( \
124-
nocache_index_getattr((tup), (attnum), (tupleDesc)) \
125-
) \
126-
) \
127-
)
117+
static inline Datum
118+
index_getattr(IndexTuple tup, int attnum, TupleDesc tupleDesc, bool *isnull)
119+
{
120+
Assert(PointerIsValid(isnull));
121+
Assert(attnum > 0);
122+
123+
*isnull = false;
124+
125+
if (!IndexTupleHasNulls(tup))
126+
{
127+
if (TupleDescAttr(tupleDesc, attnum - 1)->attcacheoff >= 0)
128+
{
129+
return fetchatt(TupleDescAttr(tupleDesc, attnum - 1),
130+
(char *) tup + IndexInfoFindDataOffset(tup->t_info)
131+
+ TupleDescAttr(tupleDesc, attnum - 1)->attcacheoff);
132+
}
133+
else
134+
return nocache_index_getattr(tup, attnum, tupleDesc);
135+
}
136+
else
137+
{
138+
if (att_isnull(attnum - 1, (bits8 *) tup + sizeof(IndexTupleData)))
139+
{
140+
*isnull = true;
141+
return (Datum) NULL;
142+
}
143+
else
144+
return nocache_index_getattr(tup, attnum, tupleDesc);
145+
}
146+
}
147+
148+
#endif
128149

129150
/*
130151
* MaxIndexTuplesPerPage is an upper bound on the number of tuples that can
@@ -146,22 +167,4 @@ typedef IndexAttributeBitMapData * IndexAttributeBitMap;
146167
((int) ((BLCKSZ - SizeOfPageHeaderData) / \
147168
(MAXALIGN(sizeof(IndexTupleData) + 1) + sizeof(ItemIdData))))
148169

149-
150-
/* routines in indextuple.c */
151-
extern IndexTuple index_form_tuple(TupleDesc tupleDescriptor,
152-
Datum *values, bool *isnull);
153-
extern IndexTuple index_form_tuple_context(TupleDesc tupleDescriptor,
154-
Datum *values, bool *isnull,
155-
MemoryContext context);
156-
extern Datum nocache_index_getattr(IndexTuple tup, int attnum,
157-
TupleDesc tupleDesc);
158-
extern void index_deform_tuple(IndexTuple tup, TupleDesc tupleDescriptor,
159-
Datum *values, bool *isnull);
160-
extern void index_deform_tuple_internal(TupleDesc tupleDescriptor,
161-
Datum *values, bool *isnull,
162-
char *tp, bits8 *bp, int hasnulls);
163-
extern IndexTuple CopyIndexTuple(IndexTuple source);
164-
extern IndexTuple index_truncate_tuple(TupleDesc sourceDescriptor,
165-
IndexTuple source, int leavenatts);
166-
167170
#endif /* ITUP_H */

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy