Changeset: b440c909b84e for MonetDB
URL: https://dev.monetdb.org/hg/MonetDB/rev/b440c909b84e
Modified Files:
gdk/gdk_bat.c
gdk/gdk_batop.c
Branch: Jul2021
Log Message:
Make it easier to append multiple NIL values in one go.
Just call BUNappendmulti with a NULL value for the values array.
diffs (130 lines):
diff --git a/gdk/gdk_bat.c b/gdk/gdk_bat.c
--- a/gdk/gdk_bat.c
+++ b/gdk/gdk_bat.c
@@ -1159,7 +1159,8 @@ setcolprops(BAT *b, const void *x)
/* Append an array of values of length count to the bat. For
* fixed-sized values, `values' is an array of values, for
- * variable-sized values, `values' is an array of pointers to values. */
+ * variable-sized values, `values' is an array of pointers to values.
+ * If values equals NULL, count times nil will be appended. */
gdk_return
BUNappendmulti(BAT *b, const void *values, BUN count, bool force)
{
@@ -1183,18 +1184,20 @@ BUNappendmulti(BAT *b, const void *value
if (b->ttype == TYPE_void && BATtdense(b)) {
const oid *ovals = values;
- bool dense = b->batCount == 0 || b->tseqbase + 1 == ovals[0];
- for (BUN i = 1; dense && i < count; i++) {
- dense = ovals[i - 1] + 1 == ovals[i];
+ bool dense = b->batCount == 0 || (ovals != NULL && b->tseqbase
+ 1 == ovals[0]);
+ if (ovals) {
+ for (BUN i = 1; dense && i < count; i++) {
+ dense = ovals[i - 1] + 1 == ovals[i];
+ }
}
if (dense) {
if (b->batCount == 0)
- b->tseqbase = ovals[0];
+ b->tseqbase = ovals ? ovals[0] : oid_nil;
BATsetcount(b, BATcount(b) + count);
return GDK_SUCCEED;
} else {
/* we need to materialize b; allocate enough capacity */
- b->batCapacity = BATcount(b) + 1;
+ b->batCapacity = BATcount(b) + count;
if (BATmaterialize(b) != GDK_SUCCEED)
return GDK_FAIL;
}
@@ -1220,9 +1223,12 @@ BUNappendmulti(BAT *b, const void *value
BATrmprop(b, GDK_UNIQUE_ESTIMATE);
b->theap->dirty |= count > 0;
MT_rwlock_wrlock(&b->thashlock);
+ const void *t = b->ttype == TYPE_msk ? &(msk){false} :
ATOMnilptr(b->ttype);
for (BUN i = 0; i < count; i++) {
- void *t = b->ttype && b->tvarsized ? ((void **) values)[i] :
- (void *) ((char *) values + i * Tsize(b));
+ if (values) {
+ t = b->ttype && b->tvarsized ? ((void **) values)[i] :
+ (void *) ((char *) values + i * Tsize(b));
+ }
setcolprops(b, t);
gdk_return rc = bunfastapp_nocheck(b, p, t, Tsize(b));
if (rc != GDK_SUCCEED) {
diff --git a/gdk/gdk_batop.c b/gdk/gdk_batop.c
--- a/gdk/gdk_batop.c
+++ b/gdk/gdk_batop.c
@@ -1244,11 +1244,10 @@ BATappend_or_update(BAT *b, BAT *p, cons
if (updid >= BATcount(b)) {
assert(mayappend);
- while (BATcount(b) < updid) {
- if (BUNappend(b, ATOMnilptr(b->ttype),
force) != GDK_SUCCEED) {
- bat_iterator_end(&ni);
- return GDK_FAIL;
- }
+ if (BATcount(b) < updid &&
+ BUNappendmulti(b, NULL, (BUN) (updid -
BATcount(b)), force) != GDK_SUCCEED) {
+ bat_iterator_end(&ni);
+ return GDK_FAIL;
}
if (BUNappend(b, new, force) != GDK_SUCCEED) {
bat_iterator_end(&ni);
@@ -1392,11 +1391,10 @@ BATappend_or_update(BAT *b, BAT *p, cons
}
if (updid >= BATcount(b)) {
assert(mayappend);
- while (BATcount(b) < updid) {
- if (BUNappend(b, &(msk){false}, force)
!= GDK_SUCCEED) {
- bat_iterator_end(&ni);
- return GDK_FAIL;
- }
+ if (BATcount(b) < updid &&
+ BUNappendmulti(b, NULL, (BUN) (updid -
BATcount(b)), force) != GDK_SUCCEED) {
+ bat_iterator_end(&ni);
+ return GDK_FAIL;
}
if (BUNappend(b, Tmsk(&ni, i), force) !=
GDK_SUCCEED) {
bat_iterator_end(&ni);
@@ -1423,17 +1421,16 @@ BATappend_or_update(BAT *b, BAT *p, cons
if (pos >= BATcount(b)) {
assert(mayappend);
bat_iterator_end(&ni);
- while (BATcount(b) < pos) {
- if (BUNappend(b, ATOMnilptr(b->ttype), force)
!= GDK_SUCCEED)
- return GDK_FAIL;
+ if (BATcount(b) < pos &&
+ BUNappendmulti(b, NULL, (BUN) (pos - BATcount(b)),
force) != GDK_SUCCEED) {
+ return GDK_FAIL;
}
return BATappend(b, n, NULL, force);
}
- while (pos + ni.count > BATcount(b)) {
- if (BUNappend(b, ATOMnilptr(b->ttype), force) !=
GDK_SUCCEED) {
- bat_iterator_end(&ni);
- return GDK_FAIL;
- }
+ if (pos + ni.count > BATcount(b) &&
+ BUNappendmulti(b, NULL, (BUN) (pos + ni.count -
BATcount(b)), force) != GDK_SUCCEED) {
+ bat_iterator_end(&ni);
+ return GDK_FAIL;
}
/* we copy all of n, so if there are nils in n we get
@@ -1579,11 +1576,10 @@ BATappend_or_update(BAT *b, BAT *p, cons
if (updid >= BATcount(b)) {
assert(mayappend);
- while (BATcount(b) < updid) {
- if (BUNappend(b, ATOMnilptr(b->ttype),
force) != GDK_SUCCEED) {
- bat_iterator_end(&ni);
- return GDK_FAIL;
- }
+ if (BATcount(b) < updid &&
+ BUNappendmulti(b, NULL, (BUN) (updid -
BATcount(b)), force) != GDK_SUCCEED) {
+ bat_iterator_end(&ni);
+ return GDK_FAIL;
}
if (BUNappend(b, new, force) != GDK_SUCCEED) {
bat_iterator_end(&ni);
_______________________________________________
checkin-list mailing list
[email protected]
https://www.monetdb.org/mailman/listinfo/checkin-list