Changeset: d5c4aa7b5a09 for MonetDB
URL: https://dev.monetdb.org/hg/MonetDB/rev/d5c4aa7b5a09
Modified Files:
gdk/gdk_hash.h
gdk/gdk_string.c
Branch: default
Log Message:
If we can, only compute string length once when calculating the string hash.
diffs (92 lines):
diff --git a/gdk/gdk_hash.h b/gdk/gdk_hash.h
--- a/gdk/gdk_hash.h
+++ b/gdk/gdk_hash.h
@@ -243,11 +243,19 @@ dblHash(const void *x)
return lngHash(x);
}
+/* if you happen to already know the string length, pass it along */
+__attribute__((__pure__))
+static inline BUN
+strHashLen(const void *x, size_t len)
+{
+ return (BUN) XXHASHFUNC(x, len, 0);
+}
+
__attribute__((__pure__))
static inline BUN
strHash(const void *x)
{
- return (BUN) XXHASHFUNC(x, strlen(x), 0);
+ return strHashLen(x, strlen(x));
}
__attribute__((__pure__))
diff --git a/gdk/gdk_string.c b/gdk/gdk_string.c
--- a/gdk/gdk_string.c
+++ b/gdk/gdk_string.c
@@ -114,7 +114,8 @@ strCleanHash(Heap *h, bool rebuild)
if (pos >= GDK_ELIMLIMIT)
break;
s = h->base + pos;
- strhash = strHash(s);
+ size_t slen = strlen(s);
+ strhash = strHashLen(s, slen);
off = strhash & GDK_STRHASHMASK;
var_t *p = (var_t *) (h->base + pos - sizeof(var_t));
if (*p != newhash[off]) {
@@ -122,7 +123,7 @@ strCleanHash(Heap *h, bool rebuild)
h->dirty = true;
}
newhash[off] = (var_t) (pos - sizeof(var_t));
- pos += strlen(s) + 1;
+ pos += slen + 1;
}
/* only set dirty flag if the hash table actually changed */
if (memcmp(newhash, h->base, sizeof(newhash)) != 0) {
@@ -198,7 +199,8 @@ ustrPut(BAT *b, var_t *dst, const char *
Heap *h = ustrbat->tvheap;
BUN p = BUN_NONE;
- BUN hsh = strHash(v);
+ size_t slen = strlen(v);
+ BUN hsh = strHashLen(v, slen);
if (ustrbat->batCount != 0) {
BATiter ui = bat_iterator_nolock(ustrbat);
if (ustrbat->thash == NULL) {
@@ -269,7 +271,7 @@ ustrPut(BAT *b, var_t *dst, const char *
#endif
size_t pad;
- size_t len = strlen(v) + 1;
+ size_t len = slen + 1;
if (GDK_ELIMBASE(h->free) != 0) {
/* no extra padding needed when no hash links needed
@@ -466,7 +468,8 @@ strPut(BAT *b, var_t *dst, const void *V
const char *v = V;
Heap *h = b->tvheap;
size_t pad;
- size_t pos, len = strlen(v) + 1;
+ size_t pos;
+ size_t slen = strlen(v);
var_t *bucket;
BUN off;
@@ -489,7 +492,7 @@ strPut(BAT *b, var_t *dst, const void *V
b->tvkey = true;
}
- off = strHash(v);
+ off = strHashLen(v, slen);
off &= GDK_STRHASHMASK;
bucket = ((var_t *) h->base) + off;
@@ -553,6 +556,7 @@ strPut(BAT *b, var_t *dst, const void *V
pad = 0;
}
+ size_t len = slen + 1;
/* check heap for space (limited to a certain maximum after
* which nils are inserted) */
if (h->free + pad + len >= h->size) {
_______________________________________________
checkin-list mailing list -- [email protected]
To unsubscribe send an email to [email protected]