Changeset: ada132a6bf6d for MonetDB
URL: http://dev.monetdb.org/hg/MonetDB?cmd=changeset;node=ada132a6bf6d
Modified Files:
        gdk/gdk_group.c
Branch: Dec2016
Log Message:

Avoid "static" tests inside the loops.


diffs (167 lines):

diff --git a/gdk/gdk_group.c b/gdk/gdk_group.c
--- a/gdk/gdk_group.c
+++ b/gdk/gdk_group.c
@@ -207,16 +207,17 @@
 #define GRP_use_existing_hash_table(INIT_0,INIT_1,COMP)                        
\
        do {                                                            \
                INIT_0;                                                 \
-               for (r = lo, p = r, q = hi;                             \
-                    p < q;                                             \
-                    p++) {                                             \
-                       INIT_1;                                         \
-                       /* this loop is similar, but not equal, to */   \
-                       /* HASHloop: the difference is that we only */  \
-                       /* consider BUNs smaller than the one we're */  \
-                       /* looking up (p), and that we also consider */ \
-                       /* the input groups */                          \
-                       if (grps) {                                     \
+               if (grps) {                                             \
+                       for (r = lo, p = r, q = hi;                     \
+                            p < q;                                     \
+                            p++) {                                     \
+                               INIT_1;                                 \
+                               /* this loop is similar, but not */     \
+                               /* equal, to HASHloop: the difference */ \
+                               /* is that we only consider BUNs */     \
+                               /* smaller than the one we're looking */ \
+                               /* up (p), and that we also consider */ \
+                               /* the input groups */                  \
                                for (hb = HASHgetlink(hs, p);           \
                                     hb != HASHnil(hs) && hb >= lo;     \
                                     hb = HASHgetlink(hs, hb)) {        \
@@ -233,7 +234,20 @@
                                                break;                  \
                                        }                               \
                                }                                       \
-                       } else {                                        \
+                               if (hb == HASHnil(hs) || hb < lo) {     \
+                                       GRPnotfound();                  \
+                               }                                       \
+                       }                                               \
+               } else {                                                \
+                       for (r = lo, p = r, q = hi;                     \
+                            p < q;                                     \
+                            p++) {                                     \
+                               INIT_1;                                 \
+                               /* this loop is similar, but not */     \
+                               /* equal, to HASHloop: the difference */ \
+                               /* is that we only consider BUNs */     \
+                               /* smaller than the one we're looking */ \
+                               /* up (p) */                            \
                                for (hb = HASHgetlink(hs, p);           \
                                     hb != HASHnil(hs) && hb >= lo;     \
                                     hb = HASHgetlink(hs, hb)) {        \
@@ -249,9 +263,9 @@
                                                break;                  \
                                        }                               \
                                }                                       \
-                       }                                               \
-                       if (hb == HASHnil(hs) || hb < lo) {             \
-                               GRPnotfound();                          \
+                               if (hb == HASHnil(hs) || hb < lo) {     \
+                                       GRPnotfound();                  \
+                               }                                       \
                        }                                               \
                }                                                       \
        } while(0)
@@ -274,21 +288,21 @@
 #define GRP_create_partial_hash_table(INIT_0,INIT_1,HASH,COMP)         \
        do {                                                            \
                INIT_0;                                                 \
-               for (r = 0, p = r, q = r + BATcount(b);                 \
-                    p < q;                                             \
-                    p++) {                                             \
-                       INIT_1;                                         \
-                       prb = HASH;                                     \
-                       if (gc) {                                       \
+               if (gc) {                                               \
+                       for (r = 0, p = r, q = r + BATcount(b);         \
+                            p < q;                                     \
+                            p++) {                                     \
+                               INIT_1;                                 \
+                               prb = HASH;                             \
                                for (hb = HASHget(hs,prb);              \
                                     hb != HASHnil(hs) &&               \
-                                     grps[hb - r] == grps[p - r];      \
+                                            grps[hb - r] == grps[p - r]; \
                                     hb = HASHgetlink(hs,hb)) {         \
                                        assert(HASHgetlink(hs,hb) == 
HASHnil(hs) \
                                               || HASHgetlink(hs,hb) < hb); \
-                                       if (COMP) {             \
+                                       if (COMP) {                     \
                                                oid grp = ngrps[hb - r]; \
-                                               ngrps[p - r] = grp;     \
+                                               ngrps[p - r] = grp;     \
                                                if (histo)              \
                                                        cnts[grp]++;    \
                                                if (gn->tsorted &&      \
@@ -297,12 +311,20 @@
                                                break;                  \
                                        }                               \
                                }                                       \
-                               if (hb != HASHnil(hs) &&                \
+                               if (hb == HASHnil(hs) ||                \
                                    grps[hb - r] != grps[p - r]) {      \
-                                       /* no group assigned yet */     \
-                                       hb = HASHnil(hs);               \
+                                       GRPnotfound();                  \
+                                       /* enter new group into hash table */ \
+                                       HASHputlink(hs,p, HASHget(hs,prb)); \
+                                       HASHput(hs,prb,p);              \
                                }                                       \
-                       } else if (grps) {                              \
+                       }                                               \
+               } else if (grps) {                                      \
+                       for (r = 0, p = r, q = r + BATcount(b);         \
+                            p < q;                                     \
+                            p++) {                                     \
+                               INIT_1;                                 \
+                               prb = HASH;                             \
                                prb = (prb ^ (BUN) grps[p-r] << bits) & 
hs->mask; \
                                for (hb = HASHget(hs,prb);              \
                                     hb != HASHnil(hs);                 \
@@ -319,11 +341,23 @@
                                                break;                  \
                                        }                               \
                                }                                       \
-                       } else {                                        \
+                               if (hb == HASHnil(hs)) {                \
+                                       GRPnotfound();                  \
+                                       /* enter new group into hash table */ \
+                                       HASHputlink(hs,p, HASHget(hs,prb)); \
+                                       HASHput(hs,prb,p);              \
+                               }                                       \
+                       }                                               \
+               } else {                                                \
+                       for (r = 0, p = r, q = r + BATcount(b);         \
+                            p < q;                                     \
+                            p++) {                                     \
+                               INIT_1;                                 \
+                               prb = HASH;                             \
                                for (hb = HASHget(hs,prb);              \
                                     hb != HASHnil(hs);                 \
                                     hb = HASHgetlink(hs,hb)) {         \
-                                       if (COMP) {             \
+                                       if (COMP) {                     \
                                                oid grp = ngrps[hb - r]; \
                                                ngrps[p - r] = grp;     \
                                                if (histo)              \
@@ -334,12 +368,12 @@
                                                break;                  \
                                        }                               \
                                }                                       \
-                       }                                               \
-                       if (hb == HASHnil(hs)) {                        \
-                               GRPnotfound();                          \
-                               /* enter new group into hash table */   \
-                               HASHputlink(hs,p, HASHget(hs,prb));     \
-                               HASHput(hs,prb,p);                      \
+                               if (hb == HASHnil(hs)) {                \
+                                       GRPnotfound();                  \
+                                       /* enter new group into hash table */ \
+                                       HASHputlink(hs,p, HASHget(hs,prb)); \
+                                       HASHput(hs,prb,p);              \
+                               }                                       \
                        }                                               \
                }                                                       \
        } while (0)
_______________________________________________
checkin-list mailing list
checkin-list@monetdb.org
https://www.monetdb.org/mailman/listinfo/checkin-list

Reply via email to