diff options
author | Tom Lane <tgl@sss.pgh.pa.us> | 2008-04-21 00:26:47 +0000 |
---|---|---|
committer | Tom Lane <tgl@sss.pgh.pa.us> | 2008-04-21 00:26:47 +0000 |
commit | 8472bf7a73487b0535c95e299773b882f7523463 (patch) | |
tree | f8cf1ad8529e819aec4d93cdcbf848996f4e3680 /contrib/btree_gist/btree_time.c | |
parent | be939544a68f852107c912da2f35f5d36958deb2 (diff) |
Allow float8, int8, and related datatypes to be passed by value on machines
where Datum is 8 bytes wide. Since this will break old-style C functions
(those still using version 0 calling convention) that have arguments or
results of these types, provide a configure option to disable it and retain
the old pass-by-reference behavior. Likewise, provide a configure option
to disable the recently-committed float4 pass-by-value change.
Zoltan Boszormenyi, plus configurability stuff by me.
Diffstat (limited to 'contrib/btree_gist/btree_time.c')
-rw-r--r-- | contrib/btree_gist/btree_time.c | 64 |
1 files changed, 42 insertions, 22 deletions
diff --git a/contrib/btree_gist/btree_time.c b/contrib/btree_gist/btree_time.c index 6c1ec80a314..0d2c2cf10ea 100644 --- a/contrib/btree_gist/btree_time.c +++ b/contrib/btree_gist/btree_time.c @@ -31,46 +31,66 @@ Datum gbt_time_penalty(PG_FUNCTION_ARGS); Datum gbt_time_same(PG_FUNCTION_ARGS); -#define P_TimeADTGetDatum(x) PointerGetDatum( &(x) ) +#ifdef USE_FLOAT8_BYVAL +#define TimeADTGetDatumFast(X) TimeADTGetDatum(X) +#else +#define TimeADTGetDatumFast(X) PointerGetDatum(&(X)) +#endif + static bool gbt_timegt(const void *a, const void *b) { - return DatumGetBool( - DirectFunctionCall2(time_gt, PointerGetDatum(a), PointerGetDatum(b)) - ); + const TimeADT *aa = (const TimeADT *) a; + const TimeADT *bb = (const TimeADT *) b; + + return DatumGetBool(DirectFunctionCall2(time_gt, + TimeADTGetDatumFast(*aa), + TimeADTGetDatumFast(*bb))); } static bool gbt_timege(const void *a, const void *b) { - return DatumGetBool( - DirectFunctionCall2(time_ge, PointerGetDatum(a), PointerGetDatum(b)) - ); + const TimeADT *aa = (const TimeADT *) a; + const TimeADT *bb = (const TimeADT *) b; + + return DatumGetBool(DirectFunctionCall2(time_ge, + TimeADTGetDatumFast(*aa), + TimeADTGetDatumFast(*bb))); } static bool gbt_timeeq(const void *a, const void *b) { - return DatumGetBool( - DirectFunctionCall2(time_eq, PointerGetDatum(a), PointerGetDatum(b)) - ); + const TimeADT *aa = (const TimeADT *) a; + const TimeADT *bb = (const TimeADT *) b; + + return DatumGetBool(DirectFunctionCall2(time_eq, + TimeADTGetDatumFast(*aa), + TimeADTGetDatumFast(*bb))); } static bool gbt_timele(const void *a, const void *b) { - return DatumGetBool( - DirectFunctionCall2(time_le, PointerGetDatum(a), PointerGetDatum(b)) - ); + const TimeADT *aa = (const TimeADT *) a; + const TimeADT *bb = (const TimeADT *) b; + + return DatumGetBool(DirectFunctionCall2(time_le, + TimeADTGetDatumFast(*aa), + TimeADTGetDatumFast(*bb))); } static bool gbt_timelt(const void *a, const void *b) { - return DatumGetBool( - DirectFunctionCall2(time_lt, PointerGetDatum(a), PointerGetDatum(b)) - ); + const TimeADT *aa = (const TimeADT *) a; + const TimeADT *bb = (const TimeADT *) b; + + return DatumGetBool(DirectFunctionCall2(time_lt, + TimeADTGetDatumFast(*aa), + TimeADTGetDatumFast(*bb))); } @@ -221,15 +241,15 @@ gbt_time_penalty(PG_FUNCTION_ARGS) intr = DatumGetIntervalP(DirectFunctionCall2( time_mi_time, - P_TimeADTGetDatum(newentry->upper), - P_TimeADTGetDatum(origentry->upper))); + TimeADTGetDatumFast(newentry->upper), + TimeADTGetDatumFast(origentry->upper))); res = INTERVAL_TO_SEC(intr); res = Max(res, 0); intr = DatumGetIntervalP(DirectFunctionCall2( time_mi_time, - P_TimeADTGetDatum(origentry->lower), - P_TimeADTGetDatum(newentry->lower))); + TimeADTGetDatumFast(origentry->lower), + TimeADTGetDatumFast(newentry->lower))); res2 = INTERVAL_TO_SEC(intr); res2 = Max(res2, 0); @@ -241,8 +261,8 @@ gbt_time_penalty(PG_FUNCTION_ARGS) { intr = DatumGetIntervalP(DirectFunctionCall2( time_mi_time, - P_TimeADTGetDatum(origentry->upper), - P_TimeADTGetDatum(origentry->lower))); + TimeADTGetDatumFast(origentry->upper), + TimeADTGetDatumFast(origentry->lower))); *result += FLT_MIN; *result += (float) (res / (res + INTERVAL_TO_SEC(intr))); *result *= (FLT_MAX / (((GISTENTRY *) PG_GETARG_POINTER(0))->rel->rd_att->natts + 1)); |