Changeset: 4ad6ef68ef78 for MonetDB URL: http://dev.monetdb.org/hg/MonetDB?cmd=changeset;node=4ad6ef68ef78 Modified Files: clients/Tests/exports.stable.out gdk/gdk.h gdk/gdk_calc.c gdk/gdk_private.h gdk/gdk_value.c monetdb5/mal/mal_instruction.c monetdb5/mal/mal_instruction.h monetdb5/mal/mal_recycle.c monetdb5/modules/mal/mal_mapi.c monetdb5/modules/mal/mdb.c monetdb5/modules/mal/recycle.c monetdb5/optimizer/opt_constants.c monetdb5/optimizer/opt_mapreduce.c monetdb5/optimizer/opt_remap.c monetdb5/optimizer/opt_support.c sql/server/sql_atom.c Branch: default Log Message:
VALptr is almost the same as VALget: make VALptr use and return const. Also introduce a new helper: VALisnil returns true if ValRecord* arg is nil. Use VALptr rather than VALget when possible (i.e. result can be const pointer). diffs (truncated from 1421 to 300 lines): diff --git a/clients/Tests/exports.stable.out b/clients/Tests/exports.stable.out --- a/clients/Tests/exports.stable.out +++ b/clients/Tests/exports.stable.out @@ -312,13 +312,14 @@ int TMcommit(void); int TMsubcommit(BAT *bl); int TMsubcommit_list(bat *subcommit, int cnt); void VALclear(ValPtr v); -int VALcmp(ValPtr p, ValPtr q); +int VALcmp(const ValRecord *p, const ValRecord *q); ptr VALconvert(int typ, ValPtr t); -ValPtr VALcopy(ValPtr dst, ValPtr src); +ValPtr VALcopy(ValPtr dst, const ValRecord *src); void VALempty(ValPtr v); -int VALformat(char **buf, ValPtr res); +int VALformat(char **buf, const ValRecord *res); void *VALget(ValPtr v); ValPtr VALinit(ValPtr d, int tpe, const void *s); +int VALisnil(const ValRecord *v); ValPtr VALset(ValPtr v, int t, ptr p); int VARcalcabsolute(ValPtr ret, const ValRecord *v); int VARcalcadd(ValPtr ret, const ValRecord *lft, const ValRecord *rgt, int abort_on_error); @@ -3005,7 +3006,7 @@ str finishFactory(Client cntxt, MalBlkPt void finishNamespace(void); str finishRef; Module fixModule(Module scope, str nme); -int fndConstant(MalBlkPtr mb, ValPtr cst, int depth); +int fndConstant(MalBlkPtr mb, const ValRecord *cst, int depth); void formatVolume(str buf, int len, lng vol); void freeInstruction(InstrPtr p); void freeMalBlk(MalBlkPtr mb); diff --git a/gdk/gdk.h b/gdk/gdk.h --- a/gdk/gdk.h +++ b/gdk/gdk.h @@ -714,17 +714,17 @@ typedef struct { /* interface definitions */ gdk_export ptr VALconvert(int typ, ValPtr t); -gdk_export int VALformat(char **buf, ValPtr res); -gdk_export ValPtr VALcopy(ValPtr dst, ValPtr src); +gdk_export int VALformat(char **buf, const ValRecord *res); +gdk_export ValPtr VALcopy(ValPtr dst, const ValRecord *src); gdk_export ValPtr VALinit(ValPtr d, int tpe, const void *s); gdk_export void VALempty(ValPtr v); gdk_export void VALclear(ValPtr v); gdk_export ValPtr VALset(ValPtr v, int t, ptr p); gdk_export void *VALget(ValPtr v); -gdk_export int VALcmp(ValPtr p, ValPtr q); +gdk_export int VALcmp(const ValRecord *p, const ValRecord *q); +gdk_export int VALisnil(const ValRecord *v); /* - * @- The BAT record * The elements of the BAT structure are introduced in the remainder. * Instead of using the underlying types hidden beneath it, one should @@ -2295,24 +2295,25 @@ gdk_export int GDKfatal(_In_z_ _Printf_f #define putenv _putenv #endif -static inline void * -VALptr(ValPtr v) +/* also see VALget */ +static inline const void * +VALptr(const ValRecord *v) { switch (ATOMstorage(v->vtype)) { - case TYPE_void: return (void *) &v->val.oval; - case TYPE_bit: return (void *) &v->val.btval; - case TYPE_bte: return (void *) &v->val.btval; - case TYPE_sht: return (void *) &v->val.shval; - case TYPE_bat: return (void *) &v->val.bval; - case TYPE_int: return (void *) &v->val.ival; - case TYPE_oid: return (void *) &v->val.oval; - case TYPE_wrd: return (void *) &v->val.wval; - case TYPE_ptr: return (void *) v->val.pval; - case TYPE_flt: return (void *) &v->val.fval; - case TYPE_dbl: return (void *) &v->val.dval; - case TYPE_lng: return (void *) &v->val.lval; - case TYPE_str: return (void *) v->val.sval; - default: return (void *) v->val.pval; + case TYPE_void: return (const void *) &v->val.oval; + case TYPE_bit: return (const void *) &v->val.btval; + case TYPE_bte: return (const void *) &v->val.btval; + case TYPE_sht: return (const void *) &v->val.shval; + case TYPE_bat: return (const void *) &v->val.bval; + case TYPE_int: return (const void *) &v->val.ival; + case TYPE_oid: return (const void *) &v->val.oval; + case TYPE_wrd: return (const void *) &v->val.wval; + case TYPE_ptr: return (const void *) v->val.pval; + case TYPE_flt: return (const void *) &v->val.fval; + case TYPE_dbl: return (const void *) &v->val.dval; + case TYPE_lng: return (const void *) &v->val.lval; + case TYPE_str: return (const void *) v->val.sval; + default: return (const void *) v->val.pval; } } diff --git a/gdk/gdk_calc.c b/gdk/gdk_calc.c --- a/gdk/gdk_calc.c +++ b/gdk/gdk_calc.c @@ -871,33 +871,7 @@ int VARcalcisnil(ValPtr ret, const ValRecord *v) { ret->vtype = TYPE_bit; - switch (ATOMstorage(v->vtype)) { - case TYPE_void: - ret->val.btval = (bit) 1; - break; - case TYPE_bte: - ret->val.btval = (bit) (v->val.btval == bte_nil); - break; - case TYPE_sht: - ret->val.btval = (bit) (v->val.shval == sht_nil); - break; - case TYPE_int: - case TYPE_bat: - ret->val.btval = (bit) (v->val.ival == int_nil); - break; - case TYPE_lng: - ret->val.btval = (bit) (v->val.lval == lng_nil); - break; - case TYPE_flt: - ret->val.btval = (bit) (v->val.fval == flt_nil); - break; - case TYPE_dbl: - ret->val.btval = (bit) (v->val.dval == dbl_nil); - break; - default: - ret->val.btval = (bit) (*BATatoms[v->vtype].atomCmp)(VALptr((ValPtr) v), ATOMnilptr(v->vtype)) == 0; - break; - } + ret->val.btval = (bit) VALisnil(v); return GDK_SUCCEED; } @@ -905,33 +879,7 @@ int VARcalcisnotnil(ValPtr ret, const ValRecord *v) { ret->vtype = TYPE_bit; - switch (ATOMstorage(v->vtype)) { - case TYPE_void: - ret->val.btval = (bit) 0; - break; - case TYPE_bte: - ret->val.btval = (bit) (v->val.btval != bte_nil); - break; - case TYPE_sht: - ret->val.btval = (bit) (v->val.shval != sht_nil); - break; - case TYPE_int: - case TYPE_bat: - ret->val.btval = (bit) (v->val.ival != int_nil); - break; - case TYPE_lng: - ret->val.btval = (bit) (v->val.lval != lng_nil); - break; - case TYPE_flt: - ret->val.btval = (bit) (v->val.fval != flt_nil); - break; - case TYPE_dbl: - ret->val.btval = (bit) (v->val.dval != dbl_nil); - break; - default: - ret->val.btval = (bit) (*BATatoms[v->vtype].atomCmp)(VALptr((ValPtr) v), ATOMnilptr(v->vtype)) != 0; - break; - } + ret->val.btval = (bit) !VALisnil(v); return GDK_SUCCEED; } @@ -1926,7 +1874,7 @@ BATcalcaddcst(BAT *b, const ValRecord *v BATaccessBegin(b, USE_TAIL, MMAP_SEQUENTIAL); nils = add_typeswitchloop(Tloc(b, b->U->first), b->T->type, 1, - VALptr((ValPtr) v), v->vtype, 0, + VALptr(v), v->vtype, 0, Tloc(bn, bn->U->first), tp, b->U->count, abort_on_error, "BATcalcaddcst"); @@ -1989,7 +1937,7 @@ BATcalccstadd(const ValRecord *v, BAT *b BATaccessBegin(b, USE_TAIL, MMAP_SEQUENTIAL); - nils = add_typeswitchloop(VALptr((ValPtr) v), v->vtype, 0, + nils = add_typeswitchloop(VALptr(v), v->vtype, 0, Tloc(b, b->U->first), b->T->type, 1, Tloc(bn, bn->U->first), tp, b->U->count, abort_on_error, "BATcalccstadd"); @@ -2027,9 +1975,9 @@ BATcalccstadd(const ValRecord *v, BAT *b int VARcalcadd(ValPtr ret, const ValRecord *lft, const ValRecord *rgt, int abort_on_error) { - if (add_typeswitchloop((const void *) VALptr((ValPtr) lft), lft->vtype, 0, - (const void *) VALptr((ValPtr) rgt), rgt->vtype, 0, - VALptr(ret), ret->vtype, 1, + if (add_typeswitchloop(VALptr(lft), lft->vtype, 0, + VALptr(rgt), rgt->vtype, 0, + VALget(ret), ret->vtype, 1, abort_on_error, "VARcalcadd") == BUN_NONE) return GDK_FAIL; return GDK_SUCCEED; @@ -2112,9 +2060,9 @@ VARcalcincr(ValPtr ret, const ValRecord { bte one = 1; - if (add_typeswitchloop((const void *) VALptr((ValPtr) v), v->vtype, 0, + if (add_typeswitchloop(VALptr(v), v->vtype, 0, &one, TYPE_bte, 0, - VALptr(ret), ret->vtype, 1, + VALget(ret), ret->vtype, 1, abort_on_error, "VARcalcincr") == BUN_NONE) return GDK_FAIL; return GDK_SUCCEED; @@ -3106,7 +3054,7 @@ BATcalcsubcst(BAT *b, const ValRecord *v BATaccessBegin(b, USE_TAIL, MMAP_SEQUENTIAL); nils = sub_typeswitchloop(Tloc(b, b->U->first), b->T->type, 1, - VALptr((ValPtr) v), v->vtype, 0, + VALptr(v), v->vtype, 0, Tloc(bn, bn->U->first), tp, b->U->count, abort_on_error, "BATcalcsubcst"); @@ -3170,7 +3118,7 @@ BATcalccstsub(const ValRecord *v, BAT *b BATaccessBegin(b, USE_TAIL, MMAP_SEQUENTIAL); - nils = sub_typeswitchloop(VALptr((ValPtr) v), v->vtype, 0, + nils = sub_typeswitchloop(VALptr(v), v->vtype, 0, Tloc(b, b->U->first), b->T->type, 1, Tloc(bn, bn->U->first), tp, b->U->count, abort_on_error, "BATcalccstsub"); @@ -3213,9 +3161,9 @@ BATcalccstsub(const ValRecord *v, BAT *b int VARcalcsub(ValPtr ret, const ValRecord *lft, const ValRecord *rgt, int abort_on_error) { - if (sub_typeswitchloop((const void *) VALptr((ValPtr) lft), lft->vtype, 0, - (const void *) VALptr((ValPtr) rgt), rgt->vtype, 0, - VALptr(ret), ret->vtype, 1, + if (sub_typeswitchloop(VALptr(lft), lft->vtype, 0, + VALptr(rgt), rgt->vtype, 0, + VALget(ret), ret->vtype, 1, abort_on_error, "VARcalcsub") == BUN_NONE) return GDK_FAIL; return GDK_SUCCEED; @@ -3298,9 +3246,9 @@ VARcalcdecr(ValPtr ret, const ValRecord { bte one = 1; - if (sub_typeswitchloop((const void *) VALptr((ValPtr) v), v->vtype, 0, + if (sub_typeswitchloop(VALptr(v), v->vtype, 0, &one, TYPE_bte, 0, - VALptr(ret), ret->vtype, 1, + VALget(ret), ret->vtype, 1, abort_on_error, "VARcalcdecr") == BUN_NONE) return GDK_FAIL; return GDK_SUCCEED; @@ -4373,7 +4321,7 @@ BATcalcmulcst(BAT *b, const ValRecord *v BATaccessBegin(b, USE_TAIL, MMAP_SEQUENTIAL); nils = mul_typeswitchloop(Tloc(b, b->U->first), b->T->type, 1, - VALptr((ValPtr) v), v->vtype, 0, + VALptr(v), v->vtype, 0, Tloc(bn, bn->U->first), tp, b->U->count, abort_on_error, "BATcalcmulcst"); @@ -4448,7 +4396,7 @@ BATcalccstmul(const ValRecord *v, BAT *b BATaccessBegin(b, USE_TAIL, MMAP_SEQUENTIAL); - nils = mul_typeswitchloop(VALptr((ValPtr) v), v->vtype, 0, + nils = mul_typeswitchloop(VALptr(v), v->vtype, 0, Tloc(b, b->U->first), b->T->type, 1, Tloc(bn, bn->U->first), tp, b->U->count, abort_on_error, "BATcalccstmul"); @@ -4498,9 +4446,9 @@ BATcalccstmul(const ValRecord *v, BAT *b int VARcalcmul(ValPtr ret, const ValRecord *lft, const ValRecord *rgt, int abort_on_error) { - if (mul_typeswitchloop((const void *) VALptr((ValPtr) lft), lft->vtype, 0, - (const void *) VALptr((ValPtr) rgt), rgt->vtype, 0, - VALptr(ret), ret->vtype, 1, + if (mul_typeswitchloop(VALptr(lft), lft->vtype, 0, + VALptr(rgt), rgt->vtype, 0, + VALget(ret), ret->vtype, 1, abort_on_error, "VARcalcmul") == BUN_NONE) return GDK_FAIL; return GDK_SUCCEED; @@ -5591,7 +5539,7 @@ BATcalcdivcst(BAT *b, const ValRecord *v BATaccessBegin(b, USE_TAIL, MMAP_SEQUENTIAL); nils = div_typeswitchloop(Tloc(b, b->U->first), b->T->type, 1, - VALptr((ValPtr) v), v->vtype, 0, + VALptr(v), v->vtype, 0, Tloc(bn, bn->U->first), tp, b->U->count, abort_on_error, "BATcalcdivcst"); @@ -5669,7 +5617,7 @@ BATcalccstdiv(const ValRecord *v, BAT *b BATaccessBegin(b, USE_TAIL, MMAP_SEQUENTIAL); _______________________________________________ Checkin-list mailing list Checkin-list@monetdb.org http://mail.monetdb.org/mailman/listinfo/checkin-list