Changeset: 7e11cab348bf for MonetDB
URL: https://dev.monetdb.org/hg/MonetDB?cmd=changeset;node=7e11cab348bf
Modified Files:
        gdk/gdk.h
        gdk/gdk_atoms.h
        gdk/gdk_batop.c
        gdk/gdk_bbp.c
        gdk/gdk_delta.h
        gdk/gdk_string.c
        monetdb5/mal/mal_module.c
        monetdb5/optimizer/opt_oltp.c
        sql/backends/monet5/UDF/capi/capi.c
Branch: default
Log Message:

More inline functions instead of macros.
The interface of GDK_STRHASH changed to be a function instead of a
macro that changes the value of an argument.


diffs (288 lines):

diff --git a/gdk/gdk.h b/gdk/gdk.h
--- a/gdk/gdk.h
+++ b/gdk/gdk.h
@@ -1000,19 +1000,6 @@ typedef var_t stridx_t;
 #define SIZEOF_STRIDX_T SIZEOF_VAR_T
 #define GDK_VARALIGN SIZEOF_STRIDX_T
 
-#if SIZEOF_VAR_T == 8
-#define VarHeapValRaw(b,p,w)                                           \
-       ((w) == 1 ? (var_t) ((uint8_t *) (b))[p] + GDK_VAROFFSET :      \
-        (w) == 2 ? (var_t) ((uint16_t *) (b))[p] + GDK_VAROFFSET :     \
-        (w) == 4 ? (var_t) ((uint32_t *) (b))[p] :                     \
-        ((var_t *) (b))[p])
-#else
-#define VarHeapValRaw(b,p,w)                                           \
-       ((w) == 1 ? (var_t) ((uint8_t *) (b))[p] + GDK_VAROFFSET :      \
-        (w) == 2 ? (var_t) ((uint16_t *) (b))[p] + GDK_VAROFFSET :     \
-        ((var_t *) (b))[p])
-#endif
-#define VarHeapVal(b,p,w) ((size_t) VarHeapValRaw(b,p,w))
 #define BUNtvaroff(bi,p) VarHeapVal((bi).b->theap.base, (p), (bi).b->twidth)
 
 #define BUNtloc(bi,p)  Tloc((bi).b,p)
@@ -2648,8 +2635,6 @@ gdk_export void VIEWbounds(BAT *b, BAT *
  * to the head column of `b'). The 'hb' is an integer index, pointing
  * out the `hb'-th BUN.
  */
-#define GDK_STREQ(l,r) (*(char*) (l) == *(char*) (r) && !strcmp(l,r))
-
 #define HASHloop(bi, h, hb, v)                                 \
        for (hb = HASHget(h, HASHprobe((h), v));                \
             hb != HASHnil(h);                                  \
@@ -2661,7 +2646,7 @@ gdk_export void VIEWbounds(BAT *b, BAT *
             hb = HASHgetlink(h,hb))                            \
                if (GDK_STREQ(v, BUNtvar(bi, hb)))
 #define HASHloop_str(bi, h, hb, v)                     \
-       for (hb = HASHget((h),strHash(v)&(h)->mask);    \
+       for (hb = HASHget((h),GDK_STRHASH(v)&(h)->mask);        \
             hb != HASHnil(h);                          \
             hb = HASHgetlink(h,hb))                    \
                if (GDK_STREQ(v, BUNtvar(bi, hb)))
diff --git a/gdk/gdk_atoms.h b/gdk/gdk_atoms.h
--- a/gdk/gdk_atoms.h
+++ b/gdk/gdk_atoms.h
@@ -323,12 +323,33 @@ ATOMreplaceVAR(int type, Heap *heap, var
  * though we have to take corrective action to ensure that str(nil) is
  * the smallest value of the domain.
  */
-#define GDK_STRNIL(s)    ((s) == NULL || *(const char*) (s) == '\200')
-#define GDK_STRLEN(s)    ((GDK_STRNIL(s)?1:strlen(s))+1)
-#define GDK_STRCMP(l,r)  (GDK_STRNIL(l)?(GDK_STRNIL(r)?0:-1):GDK_STRNIL(r)?1: \
-                         (*(const unsigned char*)(l) < *(const unsigned 
char*)(r))?-1: \
-                         (*(const unsigned char*)(l) > *(const unsigned 
char*)(r))?1: \
-                         strCmpNoNil((const unsigned char*)(l),(const unsigned 
char*)(r)))
+#define GDK_STREQ(l,r) (strcmp(l,r) == 0)
+#define GDK_STRNIL(s)  ((s) == NULL || *(const char*) (s) == '\200')
+#define GDK_STRLEN(s)  ((GDK_STRNIL(s)?1:strlen(s))+1)
+#define GDK_STRCMP(l,r)        
(GDK_STRNIL(l)?(GDK_STRNIL(r)?0:-1):GDK_STRNIL(r)?1: \
+                        (*(const unsigned char*)(l) < *(const unsigned 
char*)(r))?-1: \
+                        (*(const unsigned char*)(l) > *(const unsigned 
char*)(r))?1: \
+                        strCmpNoNil((const unsigned char*)(l),(const unsigned 
char*)(r)))
+
+static inline var_t
+VarHeapValRaw(const void *b, BUN p, int w)
+{
+       switch (w) {
+       case 1:
+               return (var_t) ((const uint8_t *) b)[p] + GDK_VAROFFSET;
+       case 2:
+               return (var_t) ((const uint16_t *) b)[p] + GDK_VAROFFSET;
+#if SIZEOF_VAR_T == 8
+       case 4:
+               return (var_t) ((const uint32_t *) b)[p];
+#endif
+       default:
+               return ((const var_t *) b)[p];
+       }
+}
+
+#define VarHeapVal(b,p,w)      ((size_t) VarHeapValRaw(b,p,w))
+
 /*
  * @- Hash Function
  * The string hash function is a very simple hash function that xors
@@ -336,18 +357,20 @@ ATOMreplaceVAR(int type, Heap *heap, var
  * characters at a time (adding 16-bits to the hash value each
  * iteration).
  */
-#define GDK_STRHASH(x,y)                               \
-       do {                                            \
-               const char *_key = (const char *) (x);  \
-               BUN _i;                                 \
-               for (_i = y = 0; _key[_i]; _i++) {      \
-                   y += _key[_i];                      \
-                   y += (y << 10);                     \
-                   y ^= (y >> 6);                      \
-               }                                       \
-               y += (y << 3);                          \
-               y ^= (y >> 11);                         \
-               y += (y << 15);                         \
-       } while (0)
+static inline BUN
+GDK_STRHASH(const char *key)
+{
+       BUN y = 0;
+
+       for (BUN i = 0; key[i]; i++) {
+               y += key[i];
+               y += (y << 10);
+               y ^= (y >> 6);
+       }
+       y += (y << 3);
+       y ^= (y >> 11);
+       y += (y << 15);
+       return y;
+}
 
 #endif /* _GDK_ATOMS_H_ */
diff --git a/gdk/gdk_batop.c b/gdk/gdk_batop.c
--- a/gdk/gdk_batop.c
+++ b/gdk/gdk_batop.c
@@ -148,7 +148,7 @@ insert_string_bat(BAT *b, BAT *n, BAT *s
                                if (off < b->tvheap->free &&
                                    strcmp(b->tvheap->base + off, 
n->tvheap->base + off) == 0 &&
                                    (!b->tvheap->hashash ||
-                                    ((BUN *) (b->tvheap->base + off))[-1] == 
(n->tvheap->hashash ? ((BUN *) (n->tvheap->base + off))[-1] : 
strHash(n->tvheap->base + off))))
+                                    ((BUN *) (b->tvheap->base + off))[-1] == 
(n->tvheap->hashash ? ((BUN *) (n->tvheap->base + off))[-1] : 
GDK_STRHASH(n->tvheap->base + off))))
                                        match++;
                                len += (strlen(n->tvheap->base + off) + 8) & ~7;
                        }
@@ -335,7 +335,7 @@ insert_string_bat(BAT *b, BAT *n, BAT *s
                        if (off < b->tvheap->free &&
                            strcmp(b->tvheap->base + off, tp) == 0 &&
                            (!b->tvheap->hashash ||
-                            ((BUN *) (b->tvheap->base + off))[-1] == 
(n->tvheap->hashash ? ((BUN *) tp)[-1] : strHash(tp)))) {
+                            ((BUN *) (b->tvheap->base + off))[-1] == 
(n->tvheap->hashash ? ((BUN *) tp)[-1] : GDK_STRHASH(tp)))) {
                                /* we found the string at the same
                                 * offset in b's string heap as it was
                                 * in n's string heap, so we don't
diff --git a/gdk/gdk_bbp.c b/gdk/gdk_bbp.c
--- a/gdk/gdk_bbp.c
+++ b/gdk/gdk_bbp.c
@@ -127,7 +127,7 @@ static bool havehge = false;
 static void
 BBP_insert(bat i)
 {
-       bat idx = (bat) (strHash(BBP_logical(i)) & BBP_mask);
+       bat idx = (bat) (GDK_STRHASH(BBP_logical(i)) & BBP_mask);
 
        BBP_next(i) = BBP_hash[idx];
        BBP_hash[idx] = i;
@@ -138,7 +138,7 @@ BBP_delete(bat i)
 {
        bat *h = BBP_hash;
        const char *s = BBP_logical(i);
-       bat idx = (bat) (strHash(s) & BBP_mask);
+       bat idx = (bat) (GDK_STRHASH(s) & BBP_mask);
 
        for (h += idx; (i = *h) != 0; h = &BBP_next(i)) {
                if (strcmp(BBP_logical(i), s) == 0) {
@@ -2020,7 +2020,7 @@ BBP_find(const char *nme, bool lock)
                /* must lock since hash-lookup traverses other BATs */
                if (lock)
                        MT_lock_set(&GDKnameLock);
-               for (i = BBP_hash[strHash(nme) & BBP_mask]; i; i = BBP_next(i)) 
{
+               for (i = BBP_hash[GDK_STRHASH(nme) & BBP_mask]; i; i = 
BBP_next(i)) {
                        if (strcmp(BBP_logical(i), nme) == 0)
                                break;
                }
diff --git a/gdk/gdk_delta.h b/gdk/gdk_delta.h
--- a/gdk/gdk_delta.h
+++ b/gdk/gdk_delta.h
@@ -15,20 +15,21 @@
  * e.g. a BAT[void,bit] is (at least) integer aligned.  This optimizes
  * processing on such BATs (DDBENCH).
  */
-#define DELTAinit(P1)                                          \
-       do {                                                    \
-               BATsetcount((P1), 0);                           \
-               (P1)->theap.free = 0;                           \
-               (P1)->batInserted = 0;                          \
-               (P1)->tshift = ATOMelmshift(Tsize(P1));         \
-               DELTADEBUG fprintf(stderr,                      \
-                       "#DELTAinit %s free %zu ins " BUNFMT    \
-                       " base %p\n",                           \
-                       BATgetId(P1),                           \
-                       (P1)->theap.free,                       \
-                       (P1)->batInserted,                      \
-                       (P1)->theap.base);                      \
-       } while (0)
+static inline void
+DELTAinit(BAT *b)
+{
+       BATsetcount(b, 0);
+       b->theap.free = 0;
+       b->batInserted = 0;
+       b->tshift = ATOMelmshift(Tsize(b));
+       DELTADEBUG fprintf(stderr,
+                          "#DELTAinit %s free %zu ins " BUNFMT " base %p\n",
+                          BBP_logical(b->batCacheid),
+                          b->theap.free,
+                          b->batInserted,
+                          b->theap.base);
+}
+
 /*
  * Upon saving a BAT, we should convert the delta marker BUN pointers
  * into indexes and convert them back into pointers upon reload.
diff --git a/gdk/gdk_string.c b/gdk/gdk_string.c
--- a/gdk/gdk_string.c
+++ b/gdk/gdk_string.c
@@ -117,10 +117,7 @@ strHeap(Heap *d, size_t cap)
 BUN
 strHash(const char *s)
 {
-       BUN res;
-
-       GDK_STRHASH(s, res);
-       return res;
+       return GDK_STRHASH(s);
 }
 
 void
@@ -156,7 +153,7 @@ strCleanHash(Heap *h, bool rebuild)
                if (h->hashash)
                        strhash = ((const BUN *) s)[-1];
                else
-                       GDK_STRHASH(s, strhash);
+                       strhash = GDK_STRHASH(s);
                off = strhash & GDK_STRHASHMASK;
                newhash[off] = (stridx_t) (pos - extralen - sizeof(stridx_t));
                pos += GDK_STRLEN(s);
@@ -200,7 +197,7 @@ strLocate(Heap *h, const char *v)
 
        /* search hash-table, if double-elimination is still in place */
        BUN off;
-       GDK_STRHASH(v, off);
+       off = GDK_STRHASH(v);
        off &= GDK_STRHASHMASK;
 
        /* should only use strLocate iff fully double eliminated */
@@ -225,7 +222,7 @@ strPut(Heap *h, var_t *dst, const char *
        stridx_t *bucket;
        BUN off, strhash;
 
-       GDK_STRHASH(v, off);
+       off = GDK_STRHASH(v);
        strhash = off;
        off &= GDK_STRHASHMASK;
        bucket = ((stridx_t *) h->base) + off;
diff --git a/monetdb5/mal/mal_module.c b/monetdb5/mal/mal_module.c
--- a/monetdb5/mal/mal_module.c
+++ b/monetdb5/mal/mal_module.c
@@ -82,7 +82,7 @@ mal_module_reset(void)
 }
 
 static int getModuleIndex(str name) {
-       return (int) (strHash(name) % MODULE_HASH_SIZE);
+       return (int) (GDK_STRHASH(name) % MODULE_HASH_SIZE);
 }
 
 static void clrModuleIndex(Module cur){
diff --git a/monetdb5/optimizer/opt_oltp.c b/monetdb5/optimizer/opt_oltp.c
--- a/monetdb5/optimizer/opt_oltp.c
+++ b/monetdb5/optimizer/opt_oltp.c
@@ -22,7 +22,7 @@ addLock(Client cntxt, OLTPlocks locks, M
        (void) cntxt;
        r =(sch?getVarConstant(mb, getArg(p,sch)).val.sval : "sqlcatalog");
        s =(tbl? getVarConstant(mb, getArg(p,tbl)).val.sval : "");
-       hash = (strHash(r)  ^ strHash(s)) % MAXOLTPLOCKS ;
+       hash = (GDK_STRHASH(r)  ^ GDK_STRHASH(s)) % MAXOLTPLOCKS ;
        hash += (hash == 0);
        locks[hash] = 1;
 }
diff --git a/sql/backends/monet5/UDF/capi/capi.c 
b/sql/backends/monet5/UDF/capi/capi.c
--- a/sql/backends/monet5/UDF/capi/capi.c
+++ b/sql/backends/monet5/UDF/capi/capi.c
@@ -562,8 +562,8 @@ static str CUDFeval(Client cntxt, MalBlk
        // begin the compilation phase
        // first look up if we have already compiled this function
        expression_hash = 0;
-       GDK_STRHASH(exprStr, expression_hash);
-       GDK_STRHASH(funcname, funcname_hash);
+       expression_hash = GDK_STRHASH(exprStr);
+       funcname_hash = GDK_STRHASH(funcname);
        funcname_hash = funcname_hash % FUNCTION_CACHE_SIZE;
        j = 0;
        for (i = 0; i < (size_t)pci->argc; i++) {
_______________________________________________
checkin-list mailing list
[email protected]
https://www.monetdb.org/mailman/listinfo/checkin-list

Reply via email to