optimization, so don't backpatch.
/*
- * $PostgreSQL: pgsql/contrib/btree_gist/btree_cash.c,v 1.9 2009/06/11 14:48:50 momjian Exp $
+ * $PostgreSQL: pgsql/contrib/btree_gist/btree_cash.c,v 1.10 2009/12/02 13:13:24 teodor Exp $
*/
#include "btree_gist.h"
#include "btree_utils_num.h"
static int
gbt_cashkey_cmp(const void *a, const void *b)
{
+ cashKEY *ia = (cashKEY*)(((Nsrt *) a)->t);
+ cashKEY *ib = (cashKEY*)(((Nsrt *) b)->t);
- if (*(Cash *) &(((Nsrt *) a)->t[0]) > *(Cash *) &(((Nsrt *) b)->t[0]))
- return 1;
- else if (*(Cash *) &(((Nsrt *) a)->t[0]) < *(Cash *) &(((Nsrt *) b)->t[0]))
- return -1;
- return 0;
+ if (ia->lower == ib->lower)
+ {
+ if (ia->upper == ib->upper)
+ return 0;
+ return (ia->upper > ib->upper) ? 1 : -1;
+ }
+
+ return (ia->lower > ib->lower) ? 1 : -1;
}
/*
- * $PostgreSQL: pgsql/contrib/btree_gist/btree_date.c,v 1.7 2009/06/11 14:48:50 momjian Exp $
+ * $PostgreSQL: pgsql/contrib/btree_gist/btree_date.c,v 1.8 2009/12/02 13:13:24 teodor Exp $
*/
#include "btree_gist.h"
#include "btree_utils_num.h"
static int
gbt_datekey_cmp(const void *a, const void *b)
{
- if (gbt_dategt((void *) &(((Nsrt *) a)->t[0]), (void *) &(((Nsrt *) b)->t[0])))
- return 1;
- else if (gbt_datelt((void *) &(((Nsrt *) a)->t[0]), (void *) &(((Nsrt *) b)->t[0])))
- return -1;
- return 0;
+ dateKEY *ia = (dateKEY*)(((Nsrt *) a)->t);
+ dateKEY *ib = (dateKEY*)(((Nsrt *) b)->t);
+ int res;
+
+ res = DatumGetInt32(DirectFunctionCall2(date_cmp, DateADTGetDatum(ia->lower), DateADTGetDatum(ib->lower)));
+ if (res == 0)
+ return DatumGetInt32(DirectFunctionCall2(date_cmp, DateADTGetDatum(ia->upper), DateADTGetDatum(ib->upper)));
+
+ return res;
}
/*
- * $PostgreSQL: pgsql/contrib/btree_gist/btree_float4.c,v 1.8 2009/06/11 14:48:50 momjian Exp $
+ * $PostgreSQL: pgsql/contrib/btree_gist/btree_float4.c,v 1.9 2009/12/02 13:13:24 teodor Exp $
*/
#include "btree_gist.h"
#include "btree_utils_num.h"
static int
gbt_float4key_cmp(const void *a, const void *b)
{
+ float4KEY *ia = (float4KEY*)(((Nsrt *) a)->t);
+ float4KEY *ib = (float4KEY*)(((Nsrt *) b)->t);
- if (*(float4 *) &(((Nsrt *) a)->t[0]) > *(float4 *) &(((Nsrt *) b)->t[0]))
- return 1;
- else if (*(float4 *) &(((Nsrt *) a)->t[0]) < *(float4 *) &(((Nsrt *) b)->t[0]))
- return -1;
- return 0;
+ if (ia->lower == ib->lower)
+ {
+ if (ia->upper == ib->upper)
+ return 0;
+ return (ia->upper > ib->upper) ? 1 : -1;
+ }
+
+ return (ia->lower > ib->lower) ? 1 : -1;
}
/*
- * $PostgreSQL: pgsql/contrib/btree_gist/btree_float8.c,v 1.8 2009/06/11 14:48:50 momjian Exp $
+ * $PostgreSQL: pgsql/contrib/btree_gist/btree_float8.c,v 1.9 2009/12/02 13:13:24 teodor Exp $
*/
#include "btree_gist.h"
#include "btree_utils_num.h"
static int
gbt_float8key_cmp(const void *a, const void *b)
{
+ float8KEY *ia = (float8KEY*)(((Nsrt *) a)->t);
+ float8KEY *ib = (float8KEY*)(((Nsrt *) b)->t);
- if (*(float8 *) &(((Nsrt *) a)->t[0]) > *(float8 *) &(((Nsrt *) b)->t[0]))
- return 1;
- else if (*(float8 *) &(((Nsrt *) a)->t[0]) < *(float8 *) &(((Nsrt *) b)->t[0]))
- return -1;
- return 0;
+ if (ia->lower == ib->lower)
+ {
+ if (ia->upper == ib->upper)
+ return 0;
+ return (ia->upper > ib->upper) ? 1 : -1;
+ }
+
+ return (ia->lower > ib->lower) ? 1 : -1;
}
/*
- * $PostgreSQL: pgsql/contrib/btree_gist/btree_inet.c,v 1.10 2009/06/11 14:48:50 momjian Exp $
+ * $PostgreSQL: pgsql/contrib/btree_gist/btree_inet.c,v 1.11 2009/12/02 13:13:24 teodor Exp $
*/
#include "btree_gist.h"
#include "btree_utils_num.h"
static int
gbt_inetkey_cmp(const void *a, const void *b)
{
+ inetKEY *ia = (inetKEY*)(((Nsrt *) a)->t);
+ inetKEY *ib = (inetKEY*)(((Nsrt *) b)->t);
- if (*(double *) (&((Nsrt *) a)->t[0]) > *(double *) (&((Nsrt *) b)->t[0]))
- return 1;
- else if (*(double *) (&((Nsrt *) a)->t[0]) < *(double *) (&((Nsrt *) b)->t[0]))
- return -1;
- return 0;
+ if (ia->lower == ib->lower)
+ {
+ if (ia->upper == ib->upper)
+ return 0;
+
+ return (ia->upper > ib->upper) ? 1 : -1;
+ }
+ return (ia->lower > ib->lower) ? 1 : -1;
}
/*
- * $PostgreSQL: pgsql/contrib/btree_gist/btree_int2.c,v 1.8 2009/06/11 14:48:50 momjian Exp $
+ * $PostgreSQL: pgsql/contrib/btree_gist/btree_int2.c,v 1.9 2009/12/02 13:13:24 teodor Exp $
*/
#include "btree_gist.h"
#include "btree_utils_num.h"
static int
gbt_int2key_cmp(const void *a, const void *b)
{
+ int16KEY *ia = (int16KEY*)(((Nsrt *) a)->t);
+ int16KEY *ib = (int16KEY*)(((Nsrt *) b)->t);
- if (*(int16 *) (&((Nsrt *) a)->t[0]) > *(int16 *) &(((Nsrt *) b)->t[0]))
- return 1;
- else if (*(int16 *) &(((Nsrt *) a)->t[0]) < *(int16 *) &(((Nsrt *) b)->t[0]))
- return -1;
- return 0;
+ if (ia->lower == ib->lower)
+ {
+ if (ia->upper == ib->upper)
+ return 0;
+ return (ia->upper > ib->upper) ? 1 : -1;
+ }
+
+ return (ia->lower > ib->lower) ? 1 : -1;
}
/*
- * $PostgreSQL: pgsql/contrib/btree_gist/btree_int4.c,v 1.8 2009/06/11 14:48:50 momjian Exp $
+ * $PostgreSQL: pgsql/contrib/btree_gist/btree_int4.c,v 1.9 2009/12/02 13:13:24 teodor Exp $
*/
#include "btree_gist.h"
#include "btree_utils_num.h"
static int
gbt_int4key_cmp(const void *a, const void *b)
{
+ int32KEY *ia = (int32KEY*)(((Nsrt *) a)->t);
+ int32KEY *ib = (int32KEY*)(((Nsrt *) b)->t);
- if (*(int32 *) &(((Nsrt *) a)->t[0]) > *(int32 *) &(((Nsrt *) b)->t[0]))
- return 1;
- else if (*(int32 *) &(((Nsrt *) a)->t[0]) < *(int32 *) &(((Nsrt *) b)->t[0]))
- return -1;
- return 0;
+ if (ia->lower == ib->lower)
+ {
+ if (ia->upper == ib->upper)
+ return 0;
+ return (ia->upper > ib->upper) ? 1 : -1;
+ }
+
+ return (ia->lower > ib->lower) ? 1 : -1;
}
/*
- * $PostgreSQL: pgsql/contrib/btree_gist/btree_int8.c,v 1.8 2009/06/11 14:48:50 momjian Exp $
+ * $PostgreSQL: pgsql/contrib/btree_gist/btree_int8.c,v 1.9 2009/12/02 13:13:24 teodor Exp $
*/
#include "btree_gist.h"
#include "btree_utils_num.h"
static int
gbt_int8key_cmp(const void *a, const void *b)
{
+ int64KEY *ia = (int64KEY*)(((Nsrt *) a)->t);
+ int64KEY *ib = (int64KEY*)(((Nsrt *) b)->t);
- if (*(int64 *) &(((Nsrt *) a)->t[0]) > *(int64 *) &(((Nsrt *) b)->t[0]))
- return 1;
- else if (*(int64 *) &(((Nsrt *) a)->t[0]) < *(int64 *) &(((Nsrt *) b)->t[0]))
- return -1;
- return 0;
+ if (ia->lower == ib->lower)
+ {
+ if (ia->upper == ib->upper)
+ return 0;
+ return (ia->upper > ib->upper) ? 1 : -1;
+ }
+
+ return (ia->lower > ib->lower) ? 1 : -1;
}
/*
- * $PostgreSQL: pgsql/contrib/btree_gist/btree_interval.c,v 1.12 2009/06/11 14:48:50 momjian Exp $
+ * $PostgreSQL: pgsql/contrib/btree_gist/btree_interval.c,v 1.13 2009/12/02 13:13:24 teodor Exp $
*/
#include "btree_gist.h"
#include "btree_utils_num.h"
static int
gbt_intvkey_cmp(const void *a, const void *b)
{
- return DatumGetInt32(
- DirectFunctionCall2(interval_cmp,
- IntervalPGetDatum(((Nsrt *) a)->t),
- IntervalPGetDatum(((Nsrt *) b)->t)
- )
- );
+ intvKEY *ia = (intvKEY*)(((Nsrt *) a)->t);
+ intvKEY *ib = (intvKEY*)(((Nsrt *) b)->t);
+ int res;
+
+ res = DatumGetInt32(DirectFunctionCall2(interval_cmp, IntervalPGetDatum(&ia->lower), IntervalPGetDatum(&ib->lower)));
+ if (res == 0)
+ return DatumGetInt32(DirectFunctionCall2(interval_cmp, IntervalPGetDatum(&ia->upper), IntervalPGetDatum(&ib->upper)));
+
+ return res;
}
/*
- * $PostgreSQL: pgsql/contrib/btree_gist/btree_macaddr.c,v 1.8 2009/06/11 14:48:50 momjian Exp $
+ * $PostgreSQL: pgsql/contrib/btree_gist/btree_macaddr.c,v 1.9 2009/12/02 13:13:24 teodor Exp $
*/
#include "btree_gist.h"
#include "btree_utils_num.h"
static int
gbt_macadkey_cmp(const void *a, const void *b)
{
- return DatumGetInt32(
- DirectFunctionCall2(
- macaddr_cmp,
- PointerGetDatum(&((Nsrt *) a)->t[0]),
- PointerGetDatum(&((Nsrt *) b)->t[0])
- )
- );
+ macKEY *ia = (macKEY*)(((Nsrt *) a)->t);
+ macKEY *ib = (macKEY*)(((Nsrt *) b)->t);
+ int res;
+
+ res = DatumGetInt32(DirectFunctionCall2(macaddr_cmp, MacaddrPGetDatum(&ia->lower), MacaddrPGetDatum(&ib->lower)));
+ if (res == 0)
+ return DatumGetInt32(DirectFunctionCall2(macaddr_cmp, MacaddrPGetDatum(&ia->upper), MacaddrPGetDatum(&ib->upper)));
+
+ return res;
}
/*
- * $PostgreSQL: pgsql/contrib/btree_gist/btree_oid.c,v 1.8 2009/06/11 14:48:50 momjian Exp $
+ * $PostgreSQL: pgsql/contrib/btree_gist/btree_oid.c,v 1.9 2009/12/02 13:13:24 teodor Exp $
*/
#include "btree_gist.h"
#include "btree_utils_num.h"
static int
gbt_oidkey_cmp(const void *a, const void *b)
{
+ oidKEY *ia = (oidKEY*)(((Nsrt *) a)->t);
+ oidKEY *ib = (oidKEY*)(((Nsrt *) b)->t);
- if (*(Oid *) &(((Nsrt *) a)->t[0]) > *(Oid *) &(((Nsrt *) b)->t[0]))
- return 1;
- else if (*(Oid *) &(((Nsrt *) a)->t[0]) < *(Oid *) &(((Nsrt *) b)->t[0]))
- return -1;
- return 0;
+ if (ia->lower == ib->lower)
+ {
+ if (ia->upper == ib->upper)
+ return 0;
+ return (ia->upper > ib->upper) ? 1 : -1;
+ }
+
+ return (ia->lower > ib->lower) ? 1 : -1;
}
/*
- * $PostgreSQL: pgsql/contrib/btree_gist/btree_time.c,v 1.16 2009/06/11 14:48:50 momjian Exp $
+ * $PostgreSQL: pgsql/contrib/btree_gist/btree_time.c,v 1.17 2009/12/02 13:13:24 teodor Exp $
*/
#include "btree_gist.h"
#include "btree_utils_num.h"
static int
gbt_timekey_cmp(const void *a, const void *b)
{
- if (gbt_timegt((void *) &(((Nsrt *) a)->t[0]), (void *) &(((Nsrt *) b)->t[0])))
- return 1;
- else if (gbt_timelt((void *) &(((Nsrt *) a)->t[0]), (void *) &(((Nsrt *) b)->t[0])))
- return -1;
- return 0;
+ timeKEY *ia = (timeKEY*)(((Nsrt *) a)->t);
+ timeKEY *ib = (timeKEY*)(((Nsrt *) b)->t);
+ int res;
+
+ res = DatumGetInt32(DirectFunctionCall2(time_cmp, TimeADTGetDatumFast(ia->lower), TimeADTGetDatumFast(ib->lower)));
+ if (res == 0)
+ return DatumGetInt32(DirectFunctionCall2(time_cmp, TimeADTGetDatumFast(ia->upper), TimeADTGetDatumFast(ib->upper)));
+
+ return res;
}
/*
- * $PostgreSQL: pgsql/contrib/btree_gist/btree_ts.c,v 1.17 2009/06/11 14:48:50 momjian Exp $
+ * $PostgreSQL: pgsql/contrib/btree_gist/btree_ts.c,v 1.18 2009/12/02 13:13:24 teodor Exp $
*/
#include "btree_gist.h"
#include "btree_utils_num.h"
static int
gbt_tskey_cmp(const void *a, const void *b)
{
- if (gbt_tsgt((void *) &(((Nsrt *) a)->t[0]), (void *) &(((Nsrt *) b)->t[0])))
- return 1;
- else if (gbt_tslt((void *) &(((Nsrt *) a)->t[0]), (void *) &(((Nsrt *) b)->t[0])))
- return -1;
- return 0;
+ tsKEY *ia = (tsKEY*)(((Nsrt *) a)->t);
+ tsKEY *ib = (tsKEY*)(((Nsrt *) b)->t);
+ int res;
+
+ res = DatumGetInt32(DirectFunctionCall2(timestamp_cmp, TimestampGetDatumFast(ia->lower), TimestampGetDatumFast(ib->lower)));
+ if (res == 0)
+ return DatumGetInt32(DirectFunctionCall2(timestamp_cmp, TimestampGetDatumFast(ia->upper), TimestampGetDatumFast(ib->upper)));
+
+ return res;
}
/*
- * $PostgreSQL: pgsql/contrib/btree_gist/btree_utils_var.c,v 1.21 2009/06/11 14:48:50 momjian Exp $
+ * $PostgreSQL: pgsql/contrib/btree_gist/btree_utils_var.c,v 1.22 2009/12/02 13:13:24 teodor Exp $
*/
#include "btree_gist.h"
GBT_VARKEY_R ar = gbt_var_key_readable(((const Vsrt *) a)->t);
GBT_VARKEY_R br = gbt_var_key_readable(((const Vsrt *) b)->t);
const gbtree_vinfo *tinfo = (const gbtree_vinfo *) arg;
+ int res;
- return (*tinfo->f_cmp) (ar.lower, br.lower);
+ res = (*tinfo->f_cmp) (ar.lower, br.lower);
+ if (res == 0)
+ return (*tinfo->f_cmp) (ar.upper, br.upper);
+
+ return res;
}
GIST_SPLITVEC *