Changeset: 83b14401e2a1 for MonetDB
URL: https://dev.monetdb.org/hg/MonetDB?cmd=changeset;node=83b14401e2a1
Modified Files:
        monetdb5/modules/atoms/str.h
        monetdb5/modules/kernel/batstr.c
Branch: alloc-less-str
Log Message:

Look for null values outside string function to avoid an extra branch. Further 
cleaning needed


diffs (truncated from 1621 to 300 lines):

diff --git a/monetdb5/modules/atoms/str.h b/monetdb5/modules/atoms/str.h
--- a/monetdb5/modules/atoms/str.h
+++ b/monetdb5/modules/atoms/str.h
@@ -32,6 +32,10 @@
                } \
        } while (0)
 
+/* For str returning functions, the result is passed as the input parameter 
buf. The returned str indicates
+   if the function succeeded (ie malloc failure or invalid unicode character). 
str_wchr_at function also
+   follows this pattern. */
+
 mal_export int str_utf8_length(str s);
 extern int str_nbytes(str s);
 
diff --git a/monetdb5/modules/kernel/batstr.c b/monetdb5/modules/kernel/batstr.c
--- a/monetdb5/modules/kernel/batstr.c
+++ b/monetdb5/modules/kernel/batstr.c
@@ -35,7 +35,7 @@ do_batstr_int(bat *res, const bat *l, co
        BATiter bi;
        BAT *bn = NULL, *b = NULL;
        BUN p, q;
-       int *restrict vals, next;
+       int *restrict vals;
        str x, msg = MAL_SUCCEED;
        bool nils = false;
 
@@ -53,9 +53,13 @@ do_batstr_int(bat *res, const bat *l, co
        vals = Tloc(bn, 0);
        for (p = 0; p < q ; p++) {
                x = (str) BUNtail(bi, p);
-               next = func(x);
-               vals[p] = next;
-               nils |= is_int_nil(next);
+
+               if (strNil(x)) {
+                       vals[p] = int_nil;
+                       nils = true;
+               } else {
+                       vals[p] = func(x);
+               }
        }
 
 bailout:
@@ -141,7 +145,7 @@ STRbatFromWChr(bat *res, const bat *l)
        BAT *bn = NULL, *b = NULL;
        BUN p, q;
        size_t buflen = MAX(strlen(str_nil) + 1, 8);
-       int *restrict vals;
+       int *restrict vals, x;
        str buf = GDKmalloc(buflen), msg = MAL_SUCCEED;
        bool nils = false;
 
@@ -161,13 +165,22 @@ STRbatFromWChr(bat *res, const bat *l)
 
        vals = Tloc(b, 0);
        for (p = 0; p < q ; p++) {
-               if ((msg = str_from_wchr(&buf, &buflen, vals[p])) != 
MAL_SUCCEED)
-                       goto bailout;
-               if (tfastins_nocheckVAR(bn, p, buf, Tsize(bn)) != GDK_SUCCEED) {
-                       msg = createException(MAL, "batstr.unicode", 
SQLSTATE(HY013) MAL_MALLOC_FAIL);
-                       goto bailout;
+               x = vals[p];
+
+               if (is_int_nil(x)) {
+                       if (tfastins_nocheckVAR(bn, p, str_nil, Tsize(bn)) != 
GDK_SUCCEED) {
+                               msg = createException(MAL, "batstr.unicode", 
SQLSTATE(HY013) MAL_MALLOC_FAIL);
+                               goto bailout;
+                       }
+                       nils = true;
+               } else {
+                       if ((msg = str_from_wchr(&buf, &buflen, vals[p])) != 
MAL_SUCCEED)
+                               goto bailout;
+                       if (tfastins_nocheckVAR(bn, p, buf, Tsize(bn)) != 
GDK_SUCCEED) {
+                               msg = createException(MAL, "batstr.unicode", 
SQLSTATE(HY013) MAL_MALLOC_FAIL);
+                               goto bailout;
+                       }
                }
-               nils |= strNil(buf);
        }
 
 bailout:
@@ -194,7 +207,7 @@ STRbatSpace(bat *res, const bat *l)
        BAT *bn = NULL, *b = NULL;
        BUN p, q;
        size_t buflen = INITIAL_STR_BUFFER_LENGTH;
-       int *restrict vals;
+       int *restrict vals, x;
        str buf = GDKmalloc(buflen), msg = MAL_SUCCEED;
        bool nils = false;
        char space[]= " ", *s = space;
@@ -215,13 +228,22 @@ STRbatSpace(bat *res, const bat *l)
 
        vals = Tloc(b, 0);
        for (p = 0; p < q ; p++) {
-               if ((msg = str_repeat(&buf, &buflen, s, vals[p])) != 
MAL_SUCCEED)
-                       goto bailout;
-               if (tfastins_nocheckVAR(bn, p, buf, Tsize(bn)) != GDK_SUCCEED) {
-                       msg = createException(MAL, "batstr.space", 
SQLSTATE(HY013) MAL_MALLOC_FAIL);
-                       goto bailout;
+               x = vals[p];
+
+               if (is_int_nil(x) || x < 0) {
+                       if (tfastins_nocheckVAR(bn, p, str_nil, Tsize(bn)) != 
GDK_SUCCEED) {
+                               msg = createException(MAL, "batstr.space", 
SQLSTATE(HY013) MAL_MALLOC_FAIL);
+                               goto bailout;
+                       }
+                       nils = true;
+               } else {
+                       if ((msg = str_repeat(&buf, &buflen, s, x)) != 
MAL_SUCCEED)
+                               goto bailout;
+                       if (tfastins_nocheckVAR(bn, p, buf, Tsize(bn)) != 
GDK_SUCCEED) {
+                               msg = createException(MAL, "batstr.space", 
SQLSTATE(HY013) MAL_MALLOC_FAIL);
+                               goto bailout;
+                       }
                }
-               nils |= strNil(buf);
        }
 
 bailout:
@@ -270,13 +292,20 @@ do_batstr_str(bat *res, const bat *l, co
        for (p = 0; p < q ; p++) {
                x = (str) BUNtail(bi, p);
 
-               if ((msg = func(&buf, &buflen, x)) != MAL_SUCCEED)
-                       goto bailout;
-               if (tfastins_nocheckVAR(bn, p, buf, Tsize(bn)) != GDK_SUCCEED) {
-                       msg = createException(MAL, name, SQLSTATE(HY013) 
MAL_MALLOC_FAIL);
-                       goto bailout;
+               if (strNil(x)) {
+                       if (tfastins_nocheckVAR(bn, p, str_nil, Tsize(bn)) != 
GDK_SUCCEED) {
+                               msg = createException(MAL, name, 
SQLSTATE(HY013) MAL_MALLOC_FAIL);
+                               goto bailout;
+                       }
+                       nils = true;
+               } else {
+                       if ((msg = (*func)(&buf, &buflen, x)) != MAL_SUCCEED)
+                               goto bailout;
+                       if (tfastins_nocheckVAR(bn, p, buf, Tsize(bn)) != 
GDK_SUCCEED) {
+                               msg = createException(MAL, name, 
SQLSTATE(HY013) MAL_MALLOC_FAIL);
+                               goto bailout;
+                       }
                }
-               nils |= strNil(buf);
        }
 
 bailout:
@@ -327,13 +356,20 @@ do_batstr_conststr_str(bat *res, const b
        for (p = 0; p < q ; p++) {
                x = (str) BUNtail(bi, p);
 
-               if ((msg = func(&buf, &buflen, x, y)) != MAL_SUCCEED)
-                       goto bailout;
-               if (tfastins_nocheckVAR(bn, p, buf, Tsize(bn)) != GDK_SUCCEED) {
-                       msg = createException(MAL, name, SQLSTATE(HY013) 
MAL_MALLOC_FAIL);
-                       goto bailout;
+               if (strNil(x) || strNil(y)) {
+                       if (tfastins_nocheckVAR(bn, p, str_nil, Tsize(bn)) != 
GDK_SUCCEED) {
+                               msg = createException(MAL, name, 
SQLSTATE(HY013) MAL_MALLOC_FAIL);
+                               goto bailout;
+                       }
+                       nils = true;
+               } else {
+                       if ((msg = (*func)(&buf, &buflen, x, y)) != MAL_SUCCEED)
+                               goto bailout;
+                       if (tfastins_nocheckVAR(bn, p, buf, Tsize(bn)) != 
GDK_SUCCEED) {
+                               msg = createException(MAL, name, 
SQLSTATE(HY013) MAL_MALLOC_FAIL);
+                               goto bailout;
+                       }
                }
-               nils |= strNil(buf);
        }
 
 bailout:
@@ -390,13 +426,20 @@ do_batstr_batstr_str(bat *res, const bat
                x = (str) BUNtail(lefti, p);
                y = (str) BUNtail(righti, p);
 
-               if ((msg = func(&buf, &buflen, x, y)) != MAL_SUCCEED)
-                       goto bailout;
-               if (tfastins_nocheckVAR(bn, p, buf, Tsize(bn)) != GDK_SUCCEED) {
-                       msg = createException(MAL, name, SQLSTATE(HY013) 
MAL_MALLOC_FAIL);
-                       goto bailout;
+               if (strNil(x) || strNil(y)) {
+                       if (tfastins_nocheckVAR(bn, p, str_nil, Tsize(bn)) != 
GDK_SUCCEED) {
+                               msg = createException(MAL, name, 
SQLSTATE(HY013) MAL_MALLOC_FAIL);
+                               goto bailout;
+                       }
+                       nils = true;
+               } else {
+                       if ((msg = (*func)(&buf, &buflen, x, y)) != MAL_SUCCEED)
+                               goto bailout;
+                       if (tfastins_nocheckVAR(bn, p, buf, Tsize(bn)) != 
GDK_SUCCEED) {
+                               msg = createException(MAL, name, 
SQLSTATE(HY013) MAL_MALLOC_FAIL);
+                               goto bailout;
+                       }
                }
-               nils |= strNil(buf);
        }
 
 bailout:
@@ -430,7 +473,7 @@ do_batstr_constint_str(bat *res, const b
        BUN p, q;
        size_t buflen = INITIAL_STR_BUFFER_LENGTH;
        str x, buf = GDKmalloc(buflen), msg = MAL_SUCCEED;
-       int nn = *n;
+       int y = *n;
        bool nils = false;
 
        if (!buf) {
@@ -451,13 +494,20 @@ do_batstr_constint_str(bat *res, const b
        for (p = 0; p < q ; p++) {
                x = (str) BUNtail(bi, p);
 
-               if ((msg = func(&buf, &buflen, x, nn)) != MAL_SUCCEED)
-                       goto bailout;
-               if (tfastins_nocheckVAR(bn, p, buf, Tsize(bn)) != GDK_SUCCEED) {
-                       msg = createException(MAL, name, SQLSTATE(HY013) 
MAL_MALLOC_FAIL);
-                       goto bailout;
+               if (strNil(x) || is_int_nil(y)) {
+                       if (tfastins_nocheckVAR(bn, p, str_nil, Tsize(bn)) != 
GDK_SUCCEED) {
+                               msg = createException(MAL, name, 
SQLSTATE(HY013) MAL_MALLOC_FAIL);
+                               goto bailout;
+                       }
+                       nils = true;
+               } else {
+                       if ((msg = (*func)(&buf, &buflen, x, y)) != MAL_SUCCEED)
+                               goto bailout;
+                       if (tfastins_nocheckVAR(bn, p, buf, Tsize(bn)) != 
GDK_SUCCEED) {
+                               msg = createException(MAL, name, 
SQLSTATE(HY013) MAL_MALLOC_FAIL);
+                               goto bailout;
+                       }
                }
-               nils |= strNil(buf);
        }
 
 bailout:
@@ -490,7 +540,7 @@ do_batstr_batint_str(bat *res, const bat
        size_t buflen = INITIAL_STR_BUFFER_LENGTH;
        str x, buf = GDKmalloc(buflen), msg = MAL_SUCCEED;
        bool nils = false;
-       int *restrict righti;
+       int *restrict righti, y;
 
        if (!buf) {
                msg = createException(MAL, name, SQLSTATE(HY013) 
MAL_MALLOC_FAIL);
@@ -514,14 +564,22 @@ do_batstr_batint_str(bat *res, const bat
        righti = Tloc(right, 0);
        for (p = 0; p < q ; p++) {
                x = (str) BUNtail(lefti, p);
+               y = righti[p];
 
-               if ((msg = func(&buf, &buflen, x, righti[p])) != MAL_SUCCEED)
-                       goto bailout;
-               if (tfastins_nocheckVAR(bn, p, buf, Tsize(bn)) != GDK_SUCCEED) {
-                       msg = createException(MAL, name, SQLSTATE(HY013) 
MAL_MALLOC_FAIL);
-                       goto bailout;
+               if (strNil(x) || is_int_nil(y)) {
+                       if (tfastins_nocheckVAR(bn, p, str_nil, Tsize(bn)) != 
GDK_SUCCEED) {
+                               msg = createException(MAL, name, 
SQLSTATE(HY013) MAL_MALLOC_FAIL);
+                               goto bailout;
+                       }
+                       nils = true;
+               } else {
+                       if ((msg = (*func)(&buf, &buflen, x, y)) != MAL_SUCCEED)
+                               goto bailout;
+                       if (tfastins_nocheckVAR(bn, p, buf, Tsize(bn)) != 
GDK_SUCCEED) {
+                               msg = createException(MAL, name, 
SQLSTATE(HY013) MAL_MALLOC_FAIL);
+                               goto bailout;
+                       }
                }
-               nils |= strNil(buf);
        }
 
 bailout:
@@ -554,8 +612,8 @@ do_batstr_constint_conststr_str(bat *res
        BAT *bn = NULL, *b = NULL;
        BUN p, q;
        size_t buflen = INITIAL_STR_BUFFER_LENGTH;
-       str x, ss2 = *s2, buf = GDKmalloc(buflen), msg = MAL_SUCCEED;
-       int nn = *n;
+       str x, z = *s2, buf = GDKmalloc(buflen), msg = MAL_SUCCEED;
+       int y = *n;
        bool nils = false;
 
        if (!buf) {
@@ -576,13 +634,20 @@ do_batstr_constint_conststr_str(bat *res
        for (p = 0; p < q ; p++) {
                x = (str) BUNtail(bi, p);
 
-               if ((msg = func(&buf, &buflen, x, nn, ss2)) != MAL_SUCCEED)
-                       goto bailout;
-               if (tfastins_nocheckVAR(bn, p, buf, Tsize(bn)) != GDK_SUCCEED) {
-                       msg = createException(MAL, name, SQLSTATE(HY013) 
MAL_MALLOC_FAIL);
-                       goto bailout;
+               if (strNil(x) || is_int_nil(y) || strNil(z)) {
+                       if (tfastins_nocheckVAR(bn, p, str_nil, Tsize(bn)) != 
GDK_SUCCEED) {
+                               msg = createException(MAL, name, 
SQLSTATE(HY013) MAL_MALLOC_FAIL);
+                               goto bailout;
+                       }
+                       nils = true;
_______________________________________________
checkin-list mailing list
[email protected]
https://www.monetdb.org/mailman/listinfo/checkin-list

Reply via email to