Changeset: 9c66d9eb8f51 for MonetDB
URL: https://dev.monetdb.org/hg/MonetDB/rev/9c66d9eb8f51
Modified Files:
gdk/gdk_bat.c
gdk/gdk_group.c
Branch: default
Log Message:
Use structure on stack for temporary hash.
diffs (138 lines):
diff --git a/gdk/gdk_bat.c b/gdk/gdk_bat.c
--- a/gdk/gdk_bat.c
+++ b/gdk/gdk_bat.c
@@ -2714,37 +2714,32 @@ BATassertProps(BAT *b)
/* we need to check for uniqueness the hard
* way (i.e. using a hash table) */
const char *nme = BBP_physical(b->batCacheid);
- Hash *hs = NULL;
+ Hash hsh;
BUN mask;
- if ((hs = GDKzalloc(sizeof(Hash))) == NULL) {
- TRC_WARNING(BAT, "Cannot allocate hash
table\n");
- goto abort_check;
- }
- if (snprintf(hs->heaplink.filename,
sizeof(hs->heaplink.filename), "%s.thshprpl%x", nme, (unsigned) MT_getpid()) >=
(int) sizeof(hs->heaplink.filename) ||
- snprintf(hs->heapbckt.filename,
sizeof(hs->heapbckt.filename), "%s.thshprpb%x", nme, (unsigned) MT_getpid()) >=
(int) sizeof(hs->heapbckt.filename)) {
- /* cannot happen, see comment in gdk.h
- * about sizes near definition of
- * BBPINIT */
- GDKfree(hs);
- TRC_CRITICAL(BAT, "Heap filename is too
large\n");
- goto abort_check;
- }
+ hsh = (Hash) {
+ .heapbckt.parentid = b->batCacheid,
+ .heaplink.parentid = b->batCacheid,
+ .heaplink.farmid = BBPselectfarm(
+ TRANSIENT, b->ttype, hashheap),
+ .heapbckt.farmid = BBPselectfarm(
+ TRANSIENT, b->ttype, hashheap),
+ };
if (ATOMsize(b->ttype) == 1)
mask = (BUN) 1 << 8;
else if (ATOMsize(b->ttype) == 2)
mask = (BUN) 1 << 16;
else
mask = HASHmask(b->batCount);
- hs->heapbckt.parentid = b->batCacheid;
- hs->heaplink.parentid = b->batCacheid;
- if ((hs->heaplink.farmid = BBPselectfarm(
- TRANSIENT, b->ttype, hashheap)) < 0 ||
- (hs->heapbckt.farmid = BBPselectfarm(
- TRANSIENT, b->ttype, hashheap)) < 0 ||
- HASHnew(hs, b->ttype, BATcount(b),
+ if (hsh.heaplink.farmid < 0 ||
+ hsh.heapbckt.farmid < 0 ||
+ snprintf(hsh.heaplink.filename,
sizeof(hsh.heaplink.filename), "%s.thshprpl%x", nme, (unsigned) MT_getpid()) >=
(int) sizeof(hsh.heaplink.filename) ||
+ snprintf(hsh.heapbckt.filename,
sizeof(hsh.heapbckt.filename), "%s.thshprpb%x", nme, (unsigned) MT_getpid()) >=
(int) sizeof(hsh.heapbckt.filename) ||
+ HASHnew(&hsh, b->ttype, BATcount(b),
mask, BUN_NONE, false) != GDK_SUCCEED) {
- GDKfree(hs);
+ /* snprintf failing cannot happen, see
+ * comment in gdk.h about sizes near
+ * definition of BBPINIT */
TRC_WARNING(BAT, "Cannot allocate hash
table\n");
goto abort_check;
}
@@ -2776,20 +2771,19 @@ BATassertProps(BAT *b)
assert(cmp <= 0);
seenmin |= cmp == 0;
}
- prb = HASHprobe(hs, valp);
- for (hb = HASHget(hs, prb);
+ prb = HASHprobe(&hsh, valp);
+ for (hb = HASHget(&hsh, prb);
hb != BUN_NONE;
- hb = HASHgetlink(hs, hb))
+ hb = HASHgetlink(&hsh, hb))
if (eqf(valp, BUNtail(&bi, hb)))
assert(!b->tkey);
- HASHputlink(hs, p, HASHget(hs, prb));
- HASHput(hs, prb, p);
+ HASHputlink(&hsh, p, HASHget(&hsh, prb));
+ HASHput(&hsh, prb, p);
assert(!b->tnonil || !isnil);
seennil |= isnil;
}
- HEAPfree(&hs->heaplink, true);
- HEAPfree(&hs->heapbckt, true);
- GDKfree(hs);
+ HEAPfree(&hsh.heaplink, true);
+ HEAPfree(&hsh.heapbckt, true);
}
abort_check:
GDKclrerr();
diff --git a/gdk/gdk_group.c b/gdk/gdk_group.c
--- a/gdk/gdk_group.c
+++ b/gdk/gdk_group.c
@@ -1103,6 +1103,7 @@ BATgroup_internal(BAT **groups, BAT **ex
int bits;
BUN nbucket;
oid grp;
+ Hash hsh;
lost_hash:
gc = g != NULL && (BATordered(g) || BATordered_rev(g));
@@ -1152,10 +1153,12 @@ BATgroup_internal(BAT **groups, BAT **ex
/* nbucket is a power of two, so ctz(nbucket)
* tells us which power of two */
bits = 8 * SIZEOF_OID - ctz(nbucket);
- if ((hs = GDKzalloc(sizeof(Hash))) == NULL ||
- (hs->heaplink.farmid = BBPselectfarm(TRANSIENT, bi.type,
hashheap)) < 0 ||
- (hs->heapbckt.farmid = BBPselectfarm(TRANSIENT, bi.type,
hashheap)) < 0) {
- GDKfree(hs);
+ hsh = (Hash) {
+ .heaplink.farmid = BBPselectfarm(TRANSIENT, bi.type,
hashheap),
+ .heapbckt.farmid = BBPselectfarm(TRANSIENT, bi.type,
hashheap),
+ };
+ hs = &hsh;
+ if (hs->heaplink.farmid < 0 || hs->heapbckt.farmid < 0) {
hs = NULL;
GDKerror("cannot allocate hash table\n");
goto error;
@@ -1165,7 +1168,6 @@ BATgroup_internal(BAT **groups, BAT **ex
if (snprintf(hs->heaplink.filename,
sizeof(hs->heaplink.filename), "%s.thshgrpl%x", nme, (unsigned) MT_getpid()) >=
(int) sizeof(hs->heaplink.filename) ||
snprintf(hs->heapbckt.filename,
sizeof(hs->heapbckt.filename), "%s.thshgrpb%x", nme, (unsigned) MT_getpid()) >=
(int) sizeof(hs->heapbckt.filename) ||
HASHnew(hs, t, BATcount(b), nbucket, BUN_NONE, false) !=
GDK_SUCCEED) {
- GDKfree(hs);
hs = NULL;
GDKerror("cannot allocate hash table\n");
goto error;
@@ -1259,7 +1261,6 @@ BATgroup_internal(BAT **groups, BAT **ex
HEAPfree(&hs->heapbckt, true);
HEAPfree(&hs->heaplink, true);
- GDKfree(hs);
}
ma_close(&ta_state);
bat_iterator_end(&bi);
@@ -1321,7 +1322,6 @@ BATgroup_internal(BAT **groups, BAT **ex
if (hs != NULL && hs != b->thash) {
HEAPfree(&hs->heaplink, true);
HEAPfree(&hs->heapbckt, true);
- GDKfree(hs);
}
if (locked)
MT_rwlock_rdunlock(&b->thashlock);
_______________________________________________
checkin-list mailing list -- [email protected]
To unsubscribe send an email to [email protected]