Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commitf58d707

Browse files
committed
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
1 parent8cf64d3 commitf58d707

File tree

2 files changed

+58
-98
lines changed

2 files changed

+58
-98
lines changed

‎src/include/access/itup.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,7 @@ typedef IndexAttributeBitMapData * IndexAttributeBitMap;
114114
) \
115115
: \
116116
( \
117-
(att_isnull((attnum)-1, (char *)(tup) + sizeof(IndexTupleData))) ? \
117+
(att_isnull((attnum)-1, (bits8 *)(tup) + sizeof(IndexTupleData))) ? \
118118
( \
119119
*(isnull) = true, \
120120
(Datum)NULL \

‎src/include/access/tupmacs.h

Lines changed: 57 additions & 97 deletions
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,13 @@
2222
* Note that a 0 in the null bitmap indicates a null, while 1 indicates
2323
* non-null.
2424
*/
25-
#defineatt_isnull(ATT,BITS) (!((BITS)[(ATT) >> 3] & (1 << ((ATT) & 0x07))))
25+
staticinlinebool
26+
att_isnull(intATT,constbits8*BITS)
27+
{
28+
return !(BITS[ATT >>3]& (1 << (ATT&0x07)));
29+
}
2630

31+
#ifndefFRONTEND
2732
/*
2833
* Given a Form_pg_attribute and a pointer into a tuple's data area,
2934
* return the correct value or pointer.
@@ -43,56 +48,32 @@
4348
/*
4449
* Same, but work from byval/len parameters rather than Form_pg_attribute.
4550
*/
51+
staticinlineDatum
52+
fetch_att(constvoid*T,boolattbyval,intattlen)
53+
{
54+
if (attbyval)
55+
{
56+
switch (attlen)
57+
{
58+
casesizeof(char):
59+
returnCharGetDatum(*((constchar*)T));
60+
casesizeof(int16):
61+
returnInt16GetDatum(*((constint16*)T));
62+
casesizeof(int32):
63+
returnInt32GetDatum(*((constint32*)T));
4664
#ifSIZEOF_DATUM==8
47-
48-
#definefetch_att(T,attbyval,attlen) \
49-
( \
50-
(attbyval) ? \
51-
( \
52-
(attlen) == (int) sizeof(Datum) ? \
53-
*((Datum *)(T)) \
54-
: \
55-
( \
56-
(attlen) == (int) sizeof(int32) ? \
57-
Int32GetDatum(*((int32 *)(T))) \
58-
: \
59-
( \
60-
(attlen) == (int) sizeof(int16) ? \
61-
Int16GetDatum(*((int16 *)(T))) \
62-
: \
63-
( \
64-
AssertMacro((attlen) == 1), \
65-
CharGetDatum(*((char *)(T))) \
66-
) \
67-
) \
68-
) \
69-
) \
70-
: \
71-
PointerGetDatum((char *) (T)) \
72-
)
73-
#else/* SIZEOF_DATUM != 8 */
74-
75-
#definefetch_att(T,attbyval,attlen) \
76-
( \
77-
(attbyval) ? \
78-
( \
79-
(attlen) == (int) sizeof(int32) ? \
80-
Int32GetDatum(*((int32 *)(T))) \
81-
: \
82-
( \
83-
(attlen) == (int) sizeof(int16) ? \
84-
Int16GetDatum(*((int16 *)(T))) \
85-
: \
86-
( \
87-
AssertMacro((attlen) == 1), \
88-
CharGetDatum(*((char *)(T))) \
89-
) \
90-
) \
91-
) \
92-
: \
93-
PointerGetDatum((char *) (T)) \
94-
)
95-
#endif/* SIZEOF_DATUM == 8 */
65+
casesizeof(Datum):
66+
return*((constDatum*)T);
67+
#endif
68+
default:
69+
elog(ERROR,"unsupported byval length: %d",attlen);
70+
return0;
71+
}
72+
}
73+
else
74+
returnPointerGetDatum(T);
75+
}
76+
#endif/* FRONTEND */
9677

9778
/*
9879
* att_align_datum aligns the given offset as needed for a datum of alignment
@@ -190,58 +171,37 @@
190171
)) \
191172
)
192173

174+
#ifndefFRONTEND
193175
/*
194176
* store_att_byval is a partial inverse of fetch_att: store a given Datum
195177
* value into a tuple data area at the specified address. However, it only
196178
* handles the byval case, because in typical usage the caller needs to
197-
* distinguish by-val and by-ref cases anyway, and so a do-it-allmacro
179+
* distinguish by-val and by-ref cases anyway, and so a do-it-allfunction
198180
* wouldn't be convenient.
199181
*/
182+
staticinlinevoid
183+
store_att_byval(void*T,Datumnewdatum,intattlen)
184+
{
185+
switch (attlen)
186+
{
187+
casesizeof(char):
188+
*(char*)T=DatumGetChar(newdatum);
189+
break;
190+
casesizeof(int16):
191+
*(int16*)T=DatumGetInt16(newdatum);
192+
break;
193+
casesizeof(int32):
194+
*(int32*)T=DatumGetInt32(newdatum);
195+
break;
200196
#ifSIZEOF_DATUM==8
201-
202-
#definestore_att_byval(T,newdatum,attlen) \
203-
do { \
204-
switch (attlen) \
205-
{ \
206-
case sizeof(char): \
207-
*(char *) (T) = DatumGetChar(newdatum); \
208-
break; \
209-
case sizeof(int16): \
210-
*(int16 *) (T) = DatumGetInt16(newdatum); \
211-
break; \
212-
case sizeof(int32): \
213-
*(int32 *) (T) = DatumGetInt32(newdatum); \
214-
break; \
215-
case sizeof(Datum): \
216-
*(Datum *) (T) = (newdatum); \
217-
break; \
218-
default: \
219-
elog(ERROR, "unsupported byval length: %d", \
220-
(int) (attlen)); \
221-
break; \
222-
} \
223-
} while (0)
224-
#else/* SIZEOF_DATUM != 8 */
225-
226-
#definestore_att_byval(T,newdatum,attlen) \
227-
do { \
228-
switch (attlen) \
229-
{ \
230-
case sizeof(char): \
231-
*(char *) (T) = DatumGetChar(newdatum); \
232-
break; \
233-
case sizeof(int16): \
234-
*(int16 *) (T) = DatumGetInt16(newdatum); \
235-
break; \
236-
case sizeof(int32): \
237-
*(int32 *) (T) = DatumGetInt32(newdatum); \
238-
break; \
239-
default: \
240-
elog(ERROR, "unsupported byval length: %d", \
241-
(int) (attlen)); \
242-
break; \
243-
} \
244-
} while (0)
245-
#endif/* SIZEOF_DATUM == 8 */
246-
197+
casesizeof(Datum):
198+
*(Datum*)T=newdatum;
199+
break;
247200
#endif
201+
default:
202+
elog(ERROR,"unsupported byval length: %d",attlen);
203+
}
204+
}
205+
#endif/* FRONTEND */
206+
207+
#endif/* TUPMACS_H */

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp