Changeset: be84d4420182 for MonetDB URL: https://dev.monetdb.org/hg/MonetDB/rev/be84d4420182 Modified Files: gdk/gdk_select.c gdk/gdk_storage.c gdk/gdk_unique.c monetdb5/modules/kernel/batmmath.c monetdb5/modules/mal/pcre.c Branch: default Log Message:
Extract constants from loops when possible
diffs (truncated from 734 to 300 lines):
diff --git a/gdk/gdk_select.c b/gdk/gdk_select.c
--- a/gdk/gdk_select.c
+++ b/gdk/gdk_select.c
@@ -222,7 +222,7 @@ hashselect(BAT *b, BATiter *bi, struct c
const oid e = (oid) (i+limit-pr_off+hseq); \
if (im[icnt] & mask) { \
if ((im[icnt] & ~innermask) == 0) { \
- while (p < ci->ncand && o < e) { \
+ while (p < ncand && o < e) { \
v = src[o-hseq]; \
if ((ADD) == NULL) { \
BBPreclaim(bn); \
@@ -233,7 +233,7 @@ hashselect(BAT *b, BATiter *bi, struct c
o = canditer_next(ci); \
} \
} else { \
- while (p < ci->ncand && o < e) { \
+ while (p < ncand && o < e) { \
v = src[o-hseq]; \
if ((ADD) == NULL) { \
BBPreclaim(bn); \
@@ -245,7 +245,7 @@ hashselect(BAT *b, BATiter *bi, struct c
} \
} \
} else { \
- while (p < ci->ncand && o < e) { \
+ while (p < ncand && o < e) { \
p++; \
o = canditer_next(ci); \
} \
@@ -258,7 +258,7 @@ hashselect(BAT *b, BATiter *bi, struct c
const oid e = (oid) (i+limit-pr_off+hseq); \
if (im[icnt] & mask) { \
if ((im[icnt] & ~innermask) == 0) { \
- while (p < ci->ncand && o < e) { \
+ while (p < ncand && o < e) { \
v = src[o-hseq]; \
if ((ADD) == NULL) { \
BBPreclaim(bn); \
@@ -269,7 +269,7 @@ hashselect(BAT *b, BATiter *bi, struct c
o = canditer_next_dense(ci); \
} \
} else { \
- while (p < ci->ncand && o < e) { \
+ while (p < ncand && o < e) { \
v = src[o-hseq]; \
if ((ADD) == NULL) { \
BBPreclaim(bn); \
@@ -281,7 +281,7 @@ hashselect(BAT *b, BATiter *bi, struct c
} \
} \
} else { \
- BUN skip_sz = MIN(ci->ncand - p, e - o); \
+ BUN skip_sz = MIN(ncand - p, e - o); \
p += skip_sz; \
o += skip_sz; \
ci->next += skip_sz; \
@@ -301,7 +301,7 @@ hashselect(BAT *b, BATiter *bi, struct c
const uint8_t rpp = ATOMelmshift(IMPS_PAGE >> bi->shift); \
o = canditer_next(ci); \
for (i = 0, dcnt = 0, icnt = 0, p = 0; \
- dcnt < imprints->dictcnt && i <= w - hseq + pr_off && p <
ci->ncand; \
+ dcnt < imprints->dictcnt && i <= w - hseq + pr_off && p <
ncand; \
dcnt++) { \
GDK_CHECK_TIMEOUT(timeoffset, counter,
GOTO_LABEL_TIMEOUT_HANDLER(bailout)); \
limit = ((BUN) d[dcnt].cnt) << rpp; \
@@ -375,7 +375,7 @@ quickins(oid *dst, BUN cnt, oid o, BAT *
impsloop(ISDENSE, TEST, \
dst = buninsfix(bn, dst, cnt, o, \
(BUN) ((dbl) cnt / (dbl) (p ==
0 ? 1 : p) \
- * (dbl) (ci->ncand-p) *
1.1 + 1024), \
+ * (dbl) (ncand-p) * 1.1
+ 1024), \
maximum)); \
} else { \
impsloop(ISDENSE, TEST, dst = quickins(dst, cnt, o,
bn)); \
@@ -406,6 +406,7 @@ quickins(oid *dst, BUN cnt, oid o, BAT *
/* choose number of bits */
#define bitswitch(ISDENSE, TEST, TYPE) \
do { \
+ BUN ncand = ci->ncand; \
assert(imprints); \
*algo = parent ? "parent imprints select " #TEST "
(canditer_next" #ISDENSE ")" : "imprints select " #TEST " (canditer_next"
#ISDENSE ")"; \
switch (imprints->bits) { \
@@ -434,15 +435,16 @@ quickins(oid *dst, BUN cnt, oid o, BAT *
/* core scan select loop with & without candidates */
#define scanloop(NAME,canditer_next,TEST) \
do { \
+ BUN ncand = ci->ncand; \
*algo = "select: " #NAME " " #TEST " (" #canditer_next ")"; \
if (BATcapacity(bn) < maximum) { \
- TIMEOUT_LOOP_IDX(p, ci->ncand, timeoffset) { \
+ TIMEOUT_LOOP_IDX(p, ncand, timeoffset) { \
o = canditer_next(ci); \
v = src[o-hseq]; \
if (TEST) { \
dst = buninsfix(bn, dst, cnt, o, \
(BUN) ((dbl) cnt / (dbl) (p
== 0 ? 1 : p) \
- * (dbl) (ci->ncand-p)
* 1.1 + 1024), \
+ * (dbl) (ncand-p) *
1.1 + 1024), \
maximum); \
if (dst == NULL) { \
BBPreclaim(bn); \
@@ -452,7 +454,7 @@ quickins(oid *dst, BUN cnt, oid o, BAT *
} \
} \
} else { \
- TIMEOUT_LOOP(ci->ncand, timeoffset) { \
+ TIMEOUT_LOOP(ncand, timeoffset) { \
o = canditer_next(ci); \
v = src[o-hseq]; \
assert(cnt < BATcapacity(bn)); \
@@ -604,7 +606,7 @@ fullscan_any(BAT *b, BATiter *bi, struct
const void *restrict nil = ATOMnilptr(b->ttype);
int (*cmp)(const void *, const void *) = ATOMcompare(b->ttype);
oid o;
- BUN p;
+ BUN p, ncand = ci->ncand;
int c;
(void) maximum;
@@ -619,13 +621,13 @@ fullscan_any(BAT *b, BATiter *bi, struct
if (equi) {
*algo = "select: fullscan equi";
if (ci->tpe == cand_dense) {
- TIMEOUT_LOOP_IDX(p, ci->ncand, timeoffset) {
+ TIMEOUT_LOOP_IDX(p, ncand, timeoffset) {
o = canditer_next_dense(ci);
v = BUNtail(*bi, o-hseq);
if ((*cmp)(tl, v) == 0) {
dst = buninsfix(bn, dst, cnt, o,
(BUN) ((dbl) cnt /
(dbl) (p == 0 ? 1 : p)
- * (dbl)
(ci->ncand-p) * 1.1 + 1024),
+ * (dbl)
(ncand-p) * 1.1 + 1024),
maximum);
if (dst == NULL) {
BBPreclaim(bn);
@@ -635,13 +637,13 @@ fullscan_any(BAT *b, BATiter *bi, struct
}
}
} else {
- TIMEOUT_LOOP_IDX(p, ci->ncand, timeoffset) {
+ TIMEOUT_LOOP_IDX(p, ncand, timeoffset) {
o = canditer_next(ci);
v = BUNtail(*bi, o-hseq);
if ((*cmp)(tl, v) == 0) {
dst = buninsfix(bn, dst, cnt, o,
(BUN) ((dbl) cnt / (dbl) (p ==
0 ? 1 : p)
- * (dbl) (ci->ncand-p) *
1.1 + 1024),
+ * (dbl) (ncand-p) * 1.1
+ 1024),
maximum);
if (dst == NULL) {
BBPreclaim(bn);
@@ -654,7 +656,7 @@ fullscan_any(BAT *b, BATiter *bi, struct
} else if (anti) {
*algo = "select: fullscan anti";
if (ci->tpe == cand_dense) {
- TIMEOUT_LOOP_IDX(p, ci->ncand, timeoffset) {
+ TIMEOUT_LOOP_IDX(p, ncand, timeoffset) {
o = canditer_next_dense(ci);
v = BUNtail(*bi, o-hseq);
if ((nil == NULL || (*cmp)(v, nil) != 0) &&
@@ -666,7 +668,7 @@ fullscan_any(BAT *b, BATiter *bi, struct
(!hi && c == 0))))) {
dst = buninsfix(bn, dst, cnt, o,
(BUN) ((dbl) cnt /
(dbl) (p == 0 ? 1 : p)
- * (dbl)
(ci->ncand-p) * 1.1 + 1024),
+ * (dbl)
(ncand-p) * 1.1 + 1024),
maximum);
if (dst == NULL) {
BBPreclaim(bn);
@@ -676,7 +678,7 @@ fullscan_any(BAT *b, BATiter *bi, struct
}
}
} else {
- TIMEOUT_LOOP_IDX(p, ci->ncand, timeoffset) {
+ TIMEOUT_LOOP_IDX(p, ncand, timeoffset) {
o = canditer_next(ci);
v = BUNtail(*bi, o-hseq);
if ((nil == NULL || (*cmp)(v, nil) != 0) &&
@@ -688,7 +690,7 @@ fullscan_any(BAT *b, BATiter *bi, struct
(!hi && c == 0))))) {
dst = buninsfix(bn, dst, cnt, o,
(BUN) ((dbl) cnt /
(dbl) (p == 0 ? 1 : p)
- * (dbl)
(ci->ncand-p) * 1.1 + 1024),
+ * (dbl)
(ncand-p) * 1.1 + 1024),
maximum);
if (dst == NULL) {
BBPreclaim(bn);
@@ -701,7 +703,7 @@ fullscan_any(BAT *b, BATiter *bi, struct
} else {
*algo = "select: fullscan range";
if (ci->tpe == cand_dense) {
- TIMEOUT_LOOP_IDX(p, ci->ncand, timeoffset) {
+ TIMEOUT_LOOP_IDX(p, ncand, timeoffset) {
o = canditer_next_dense(ci);
v = BUNtail(*bi, o-hseq);
if ((nil == NULL || (*cmp)(v, nil) != 0) &&
@@ -713,7 +715,7 @@ fullscan_any(BAT *b, BATiter *bi, struct
(hi && c == 0)))) {
dst = buninsfix(bn, dst, cnt, o,
(BUN) ((dbl) cnt /
(dbl) (p == 0 ? 1 : p)
- * (dbl)
(ci->ncand-p) * 1.1 + 1024),
+ * (dbl)
(ncand-p) * 1.1 + 1024),
maximum);
if (dst == NULL) {
BBPreclaim(bn);
@@ -723,7 +725,7 @@ fullscan_any(BAT *b, BATiter *bi, struct
}
}
} else {
- TIMEOUT_LOOP_IDX(p, ci->ncand, timeoffset) {
+ TIMEOUT_LOOP_IDX(p, ncand, timeoffset) {
o = canditer_next(ci);
v = BUNtail(*bi, o-hseq);
if ((nil == NULL || (*cmp)(v, nil) != 0) &&
@@ -735,7 +737,7 @@ fullscan_any(BAT *b, BATiter *bi, struct
(hi && c == 0)))) {
dst = buninsfix(bn, dst, cnt, o,
(BUN) ((dbl) cnt /
(dbl) (p == 0 ? 1 : p)
- * (dbl)
(ci->ncand-p) * 1.1 + 1024),
+ * (dbl)
(ncand-p) * 1.1 + 1024),
maximum);
if (dst == NULL) {
BBPreclaim(bn);
@@ -761,7 +763,7 @@ fullscan_str(BAT *b, BATiter *bi, struct
BUN maximum, Imprints *imprints, const char **algo)
{
var_t pos;
- BUN p;
+ BUN p, ncand = ci->ncand;
oid o;
lng timeoffset = 0;
QryCtx *qry_ctx = MT_thread_get_qry_ctx();
@@ -788,12 +790,12 @@ fullscan_str(BAT *b, BATiter *bi, struct
const unsigned char *ptr = (const unsigned char *) bi->base;
pos -= GDK_VAROFFSET;
if (ci->tpe == cand_dense) {
- TIMEOUT_LOOP_IDX(p, ci->ncand, timeoffset) {
+ TIMEOUT_LOOP_IDX(p, ncand, timeoffset) {
o = canditer_next_dense(ci);
if (ptr[o - hseq] == pos) {
dst = buninsfix(bn, dst, cnt, o,
(BUN) ((dbl) cnt /
(dbl) (p == 0 ? 1 : p)
- * (dbl)
(ci->ncand-p) * 1.1 + 1024),
+ * (dbl)
(ncand-p) * 1.1 + 1024),
maximum);
if (dst == NULL) {
BBPreclaim(bn);
@@ -803,12 +805,12 @@ fullscan_str(BAT *b, BATiter *bi, struct
}
}
} else {
- TIMEOUT_LOOP_IDX(p, ci->ncand, timeoffset) {
+ TIMEOUT_LOOP_IDX(p, ncand, timeoffset) {
o = canditer_next(ci);
if (ptr[o - hseq] == pos) {
dst = buninsfix(bn, dst, cnt, o,
(BUN) ((dbl) cnt /
(dbl) (p == 0 ? 1 : p)
- * (dbl)
(ci->ncand-p) * 1.1 + 1024),
+ * (dbl)
(ncand-p) * 1.1 + 1024),
maximum);
if (dst == NULL) {
BBPreclaim(bn);
@@ -824,12 +826,12 @@ fullscan_str(BAT *b, BATiter *bi, struct
const unsigned short *ptr = (const unsigned short *) bi->base;
pos -= GDK_VAROFFSET;
if (ci->tpe == cand_dense) {
- TIMEOUT_LOOP_IDX(p, ci->ncand, timeoffset) {
+ TIMEOUT_LOOP_IDX(p, ncand, timeoffset) {
o = canditer_next_dense(ci);
if (ptr[o - hseq] == pos) {
dst = buninsfix(bn, dst, cnt, o,
(BUN) ((dbl) cnt /
(dbl) (p == 0 ? 1 : p)
- * (dbl)
(ci->ncand-p) * 1.1 + 1024),
+ * (dbl)
(ncand-p) * 1.1 + 1024),
maximum);
if (dst == NULL) {
BBPreclaim(bn);
@@ -839,12 +841,12 @@ fullscan_str(BAT *b, BATiter *bi, struct
}
}
} else {
- TIMEOUT_LOOP_IDX(p, ci->ncand, timeoffset) {
+ TIMEOUT_LOOP_IDX(p, ncand, timeoffset) {
o = canditer_next(ci);
if (ptr[o - hseq] == pos) {
dst = buninsfix(bn, dst, cnt, o,
(BUN) ((dbl) cnt /
(dbl) (p == 0 ? 1 : p)
- * (dbl)
(ci->ncand-p) * 1.1 + 1024),
+ * (dbl)
(ncand-p) * 1.1 + 1024),
maximum);
if (dst == NULL) {
BBPreclaim(bn);
@@ -860,12 +862,12 @@ fullscan_str(BAT *b, BATiter *bi, struct
case 4: {
const unsigned int *ptr = (const unsigned int *) bi->base;
if (ci->tpe == cand_dense) {
- TIMEOUT_LOOP_IDX(p, ci->ncand, timeoffset) {
+ TIMEOUT_LOOP_IDX(p, ncand, timeoffset) {
o = canditer_next_dense(ci);
_______________________________________________
checkin-list mailing list
[email protected]
https://www.monetdb.org/mailman/listinfo/checkin-list
