Changeset: 70e73feb5787 for MonetDB
URL: http://dev.monetdb.org/hg/MonetDB?cmd=changeset;node=70e73feb5787
Modified Files:
gdk/gdk_atoms.c
gdk/gdk_atoms.h
gdk/gdk_calc.c
Branch: Oct2014
Log Message:
Only use "storage" type if comparison functions and nils are equal.
diffs (truncated from 2561 to 300 lines):
diff --git a/gdk/gdk_atoms.c b/gdk/gdk_atoms.c
--- a/gdk/gdk_atoms.c
+++ b/gdk/gdk_atoms.c
@@ -268,7 +268,10 @@ ATOMheap(int t, Heap *hp, size_t cap)
int
ATOMcmp(int t, const void *l, const void *r)
{
- switch (ATOMstorage(t)) {
+ switch (t != ATOMstorage(t) &&
+ ATOMnilptr(t) == ATOMnilptr(ATOMstorage(t)) &&
+ ATOMcompare(t) == ATOMcompare(ATOMstorage(t)) ?
+ ATOMstorage(t) : t) {
case TYPE_bte:
return simple_CMP(l, r, bte);
case TYPE_sht:
diff --git a/gdk/gdk_atoms.h b/gdk/gdk_atoms.h
--- a/gdk/gdk_atoms.h
+++ b/gdk/gdk_atoms.h
@@ -198,6 +198,7 @@ gdk_export const ptr ptr_nil;
#define ATOMalign(t) BATatoms[t].align
#define ATOMfromstr(t,s,l,src) BATatoms[t].atomFromStr(src,l,s)
#define ATOMnilptr(t) BATatoms[t].atomNull
+#define ATOMcompare(t) BATatoms[t].atomCmp
#define ATOMhash(t,src) BATatoms[t].atomHash(src)
#define ATOMdel(t,hp,src) do if (BATatoms[t].atomDel)
BATatoms[t].atomDel(hp,src); while (0)
#define ATOMvarsized(t) (BATatoms[t].atomPut != NULL)
diff --git a/gdk/gdk_calc.c b/gdk/gdk_calc.c
--- a/gdk/gdk_calc.c
+++ b/gdk/gdk_calc.c
@@ -45,6 +45,14 @@
#define FMTdbl "%.17g"
#define FMToid OIDFMT
+/* The base type is the storage type if the comparison function and
+ * nil values are the same as those of the storage type; otherwise it
+ * is the type itself, even if the storage type is different. */
+#define BASETYPE(t) ((t) != ATOMstorage(t) && \
+ ATOMnilptr(t) == ATOMnilptr(ATOMstorage(t)) && \
+ ATOMcompare(t) == ATOMcompare(ATOMstorage(t)) ? \
+ ATOMstorage(t) : (t))
+
/* Most of the internal routines return a count of the number of NIL
* values they produced. They indicate an error by returning a value
* >= BUN_NONE. BUN_NONE means that the error was dealt with by
@@ -195,7 +203,7 @@ BATcalcnot(BAT *b, BAT *s)
if (bn == NULL)
return NULL;
- switch (ATOMstorage(b->T->type)) {
+ switch (BASETYPE(b->T->type)) {
case TYPE_bte:
if (b->T->type == TYPE_bit) {
UNARY_2TYPE_FUNC(bit, bit, NOTBIT);
@@ -245,19 +253,14 @@ int
VARcalcnot(ValPtr ret, const ValRecord *v)
{
ret->vtype = v->vtype;
- switch (ATOMstorage(v->vtype)) {
+ switch (BASETYPE(v->vtype)) {
case TYPE_bte:
- if (v->vtype == TYPE_bit) {
- if (v->val.btval == bit_nil)
- ret->val.btval = bit_nil;
- else
- ret->val.btval = !v->val.btval;
- } else {
- if (v->val.btval == bte_nil)
- ret->val.btval = bte_nil;
- else
- ret->val.btval = ~v->val.btval;
- }
+ if (v->val.btval == bit_nil)
+ ret->val.btval = bit_nil;
+ else if (v->vtype == TYPE_bit)
+ ret->val.btval = !v->val.btval;
+ else
+ ret->val.btval = ~v->val.btval;
break;
case TYPE_sht:
if (v->val.shval == sht_nil)
@@ -307,7 +310,7 @@ BATcalcnegate(BAT *b, BAT *s)
if (bn == NULL)
return NULL;
- switch (ATOMstorage(b->T->type)) {
+ switch (BASETYPE(b->T->type)) {
case TYPE_bte:
UNARY_2TYPE_FUNC(bte, bte, NEGATE);
break;
@@ -359,7 +362,7 @@ int
VARcalcnegate(ValPtr ret, const ValRecord *v)
{
ret->vtype = v->vtype;
- switch (ATOMstorage(v->vtype)) {
+ switch (BASETYPE(v->vtype)) {
case TYPE_bte:
if (v->val.btval == bte_nil)
ret->val.btval = bte_nil;
@@ -424,7 +427,7 @@ BATcalcabsolute(BAT *b, BAT *s)
if (bn == NULL)
return NULL;
- switch (ATOMstorage(b->T->type)) {
+ switch (BASETYPE(b->T->type)) {
case TYPE_bte:
UNARY_2TYPE_FUNC(bte, bte, (bte) abs);
break;
@@ -478,7 +481,7 @@ int
VARcalcabsolute(ValPtr ret, const ValRecord *v)
{
ret->vtype = v->vtype;
- switch (ATOMstorage(v->vtype)) {
+ switch (BASETYPE(v->vtype)) {
case TYPE_bte:
if (v->val.btval == bte_nil)
ret->val.btval = bte_nil;
@@ -545,7 +548,7 @@ BATcalciszero(BAT *b, BAT *s)
if (bn == NULL)
return NULL;
- switch (ATOMstorage(b->T->type)) {
+ switch (BASETYPE(b->T->type)) {
case TYPE_bte:
UNARY_2TYPE_FUNC(bte, bit, ISZERO);
break;
@@ -596,7 +599,7 @@ int
VARcalciszero(ValPtr ret, const ValRecord *v)
{
ret->vtype = TYPE_bit;
- switch (ATOMstorage(v->vtype)) {
+ switch (BASETYPE(v->vtype)) {
case TYPE_bte:
if (v->val.btval == bte_nil)
ret->val.btval = bit_nil;
@@ -664,7 +667,7 @@ BATcalcsign(BAT *b, BAT *s)
if (bn == NULL)
return NULL;
- switch (ATOMstorage(b->T->type)) {
+ switch (BASETYPE(b->T->type)) {
case TYPE_bte:
UNARY_2TYPE_FUNC(bte, bte, SIGN);
break;
@@ -718,7 +721,7 @@ int
VARcalcsign(ValPtr ret, const ValRecord *v)
{
ret->vtype = TYPE_bte;
- switch (ATOMstorage(v->vtype)) {
+ switch (BASETYPE(v->vtype)) {
case TYPE_bte:
if (v->val.btval == bte_nil)
ret->val.btval = bte_nil;
@@ -782,9 +785,6 @@ BATcalcisnil(BAT *b, BAT *s)
BUN i, cnt, start, end;
const oid *cand = NULL, *candend = NULL;
bit *dst;
- int t;
- const void *nil;
- int (*atomcmp)(const void *, const void *);
BUN nils = 0;
BATcheck(b, "BATcalcisnil");
@@ -816,14 +816,7 @@ BATcalcisnil(BAT *b, BAT *s)
CANDLOOP(dst, i, bit_nil, 0, start);
- t = b->T->type;
- nil = ATOMnilptr(t);
- atomcmp = BATatoms[t].atomCmp;
- if (t != ATOMstorage(t) &&
- ATOMnilptr(ATOMstorage(t)) == nil &&
- BATatoms[ATOMstorage(t)].atomCmp == atomcmp)
- t = ATOMstorage(t);
- switch (t) {
+ switch (BASETYPE(b->T->type)) {
case TYPE_bte:
ISNIL_TYPE(bte);
break;
@@ -845,6 +838,8 @@ BATcalcisnil(BAT *b, BAT *s)
default:
{
BATiter bi = bat_iterator(b);
+ int (*atomcmp)(const void *, const void *) =
ATOMcompare(b->T->type);
+ const void *nil = ATOMnilptr(b->T->type);
for (i = start; i < end; i++) {
CHECKCAND(dst, i, b->H->seq, bit_nil);
@@ -1088,11 +1083,14 @@ add_typeswitchloop(const void *lft, int
{
BUN nils;
- switch (ATOMstorage(tp1)) {
+ tp1 = BASETYPE(tp1);
+ tp2 = BASETYPE(tp2);
+ tp = BASETYPE(tp);
+ switch (tp1) {
case TYPE_bte:
- switch (ATOMstorage(tp2)) {
+ switch (tp2) {
case TYPE_bte:
- switch (ATOMstorage(tp)) {
+ switch (tp) {
case TYPE_bte:
nils = add_bte_bte_bte(lft, incr1, rgt, incr2,
dst, cnt, start, end,
@@ -1131,7 +1129,7 @@ add_typeswitchloop(const void *lft, int
}
break;
case TYPE_sht:
- switch (ATOMstorage(tp)) {
+ switch (tp) {
case TYPE_sht:
nils = add_bte_sht_sht(lft, incr1, rgt, incr2,
dst, cnt, start, end,
@@ -1165,7 +1163,7 @@ add_typeswitchloop(const void *lft, int
}
break;
case TYPE_int:
- switch (ATOMstorage(tp)) {
+ switch (tp) {
case TYPE_int:
nils = add_bte_int_int(lft, incr1, rgt, incr2,
dst, cnt, start, end,
@@ -1194,7 +1192,7 @@ add_typeswitchloop(const void *lft, int
}
break;
case TYPE_lng:
- switch (ATOMstorage(tp)) {
+ switch (tp) {
case TYPE_lng:
nils = add_bte_lng_lng(lft, incr1, rgt, incr2,
dst, cnt, start, end,
@@ -1218,7 +1216,7 @@ add_typeswitchloop(const void *lft, int
}
break;
case TYPE_flt:
- switch (ATOMstorage(tp)) {
+ switch (tp) {
case TYPE_flt:
nils = add_bte_flt_flt(lft, incr1, rgt, incr2,
dst, cnt, start, end,
@@ -1235,7 +1233,7 @@ add_typeswitchloop(const void *lft, int
}
break;
case TYPE_dbl:
- switch (ATOMstorage(tp)) {
+ switch (tp) {
case TYPE_dbl:
nils = add_bte_dbl_dbl(lft, incr1, rgt, incr2,
dst, cnt, start, end,
@@ -1251,9 +1249,9 @@ add_typeswitchloop(const void *lft, int
}
break;
case TYPE_sht:
- switch (ATOMstorage(tp2)) {
+ switch (tp2) {
case TYPE_bte:
- switch (ATOMstorage(tp)) {
+ switch (tp) {
case TYPE_sht:
nils = add_sht_bte_sht(lft, incr1, rgt, incr2,
dst, cnt, start, end,
@@ -1287,7 +1285,7 @@ add_typeswitchloop(const void *lft, int
}
break;
case TYPE_sht:
- switch (ATOMstorage(tp)) {
+ switch (tp) {
case TYPE_sht:
nils = add_sht_sht_sht(lft, incr1, rgt, incr2,
dst, cnt, start, end,
@@ -1321,7 +1319,7 @@ add_typeswitchloop(const void *lft, int
}
break;
case TYPE_int:
- switch (ATOMstorage(tp)) {
+ switch (tp) {
case TYPE_int:
nils = add_sht_int_int(lft, incr1, rgt, incr2,
dst, cnt, start, end,
@@ -1350,7 +1348,7 @@ add_typeswitchloop(const void *lft, int
}
break;
case TYPE_lng:
- switch (ATOMstorage(tp)) {
+ switch (tp) {
case TYPE_lng:
nils = add_sht_lng_lng(lft, incr1, rgt, incr2,
dst, cnt, start, end,
@@ -1374,7 +1372,7 @@ add_typeswitchloop(const void *lft, int
}
break;
case TYPE_flt:
- switch (ATOMstorage(tp)) {
+ switch (tp) {
case TYPE_flt:
nils = add_sht_flt_flt(lft, incr1, rgt, incr2,
dst, cnt, start, end,
@@ -1391,7 +1389,7 @@ add_typeswitchloop(const void *lft, int
}
_______________________________________________
checkin-list mailing list
[email protected]
https://www.monetdb.org/mailman/listinfo/checkin-list