Changeset: f9e6ed6d016a for MonetDB
URL: https://dev.monetdb.org/hg/MonetDB?cmd=changeset;node=f9e6ed6d016a
Modified Files:
monetdb5/modules/mal/pcre.c
Branch: Jun2020
Log Message:
One more cleanup, removed old code for case insentive regex matching with no
special characters which would use pcre. It can fallback into strcmp instead
diffs (182 lines):
diff --git a/monetdb5/modules/mal/pcre.c b/monetdb5/modules/mal/pcre.c
--- a/monetdb5/modules/mal/pcre.c
+++ b/monetdb5/modules/mal/pcre.c
@@ -1737,7 +1737,7 @@ PCREsql2pcre(str *ret, const str *pat, c
}
static inline str
-choose_like_path(char **ppat, bool *use_re, bool *use_strcmp, bool *empty,
const str *pat, const str *esc, const bit *caseignore)
+choose_like_path(char **ppat, bool *use_re, bool *use_strcmp, bool *empty,
const str *pat, const str *esc)
{
str res = MAL_SUCCEED;
*use_re = false;
@@ -1760,11 +1760,8 @@ choose_like_path(char **ppat, bool *use_
if (strNil(*ppat)) {
GDKfree(*ppat);
*ppat = NULL;
- if (*caseignore) {
- if (!(*ppat = GDKmalloc(strlen(*pat) +
3)))
- throw(MAL,
"algebra.likeselect", SQLSTATE(HY013) MAL_MALLOC_FAIL);
- stpcpy(stpcpy(stpcpy(*ppat, "^"),
*pat), "$");
- }
+ *use_re = true;
+ *use_strcmp = true;
}
}
}
@@ -1777,46 +1774,28 @@ PCRElike4(bit *ret, const str *s, const
str res = MAL_SUCCEED;
char *ppat = NULL;
bool use_re = false, use_strcmp = false, isnull = false;
- uint32_t *wpat = NULL;
struct RE *re = NULL;
- if ((res = choose_like_path(&ppat, &use_re, &use_strcmp, &isnull, pat,
esc, isens)) != MAL_SUCCEED)
+ if ((res = choose_like_path(&ppat, &use_re, &use_strcmp, &isnull, pat,
esc)) != MAL_SUCCEED)
return res;
- if (strNil(*s)) {
+ if (strNil(*s) || isnull) {
*ret = bit_nil;
} else if (use_re) {
if (use_strcmp) {
- if (*isens) {
- if (!(wpat = utf8stoucs(*pat))) {
- res = createException(MAL,
"pcre.like4", SQLSTATE(HY013) MAL_MALLOC_FAIL);
- goto bailout;
- }
- *ret = mywstrcasecmp(*s, wpat) == 0;
- } else {
- *ret = strcmp(*s, *pat) == 0;
- }
+ *ret = *isens ? mystrcasecmp(*s, *pat) == 0 :
strcmp(*s, *pat) == 0;
} else {
- if (!(re = re_create(*pat, *isens, (unsigned char)
**esc))) {
+ if (!(re = re_create(*pat, *isens, (unsigned char)
**esc)))
res = createException(MAL, "pcre.like4",
SQLSTATE(HY013) MAL_MALLOC_FAIL);
- goto bailout;
- }
- *ret = *isens ? re_match_ignore(*s, re) :
re_match_no_ignore(*s, re);
+ else
+ *ret = *isens ? re_match_ignore(*s, re) :
re_match_no_ignore(*s, re);
}
- } else if (ppat == NULL) {
- /* no pattern and no special characters: can use normal strcmp
*/
- if (isnull)
- *ret = bit_nil;
- else
- *ret = *isens ? mystrcasecmp(*s, *pat) == 0 :
strcmp(*s, *pat) == 0;
} else {
res = *isens ? PCREimatch(ret, s, &ppat) : PCREmatch(ret, s,
&ppat);
}
-bailout:
if (re)
re_destroy(re);
- GDKfree(wpat);
GDKfree(ppat);
return res;
}
@@ -2031,40 +2010,16 @@ BATPCRElike3(bat *ret, const bat *bid, c
if (!(b = BATdescriptor(*bid)))
throw(MAL, "pcre.like3", SQLSTATE(HY002)
RUNTIME_OBJECT_MISSING);
- if ((res = choose_like_path(&ppat, &use_re, &use_strcmp, &allnulls,
pat, esc, isens)) != MAL_SUCCEED) {
+ if ((res = choose_like_path(&ppat, &use_re, &use_strcmp, &allnulls,
pat, esc)) != MAL_SUCCEED) {
BBPunfix(b->batCacheid);
return res;
}
if (use_re) {
res = re_like_proj(&bn, b, *pat, (bool) *isens, (bool) *not,
use_strcmp, (unsigned char) **esc);
- } else if (ppat == NULL) {
- /* no pattern and no special characters: can use normal strcmp
loop */
- BUN q = BATcount(b);
- bn = COLnew(b->hseqbase, TYPE_bit, q, TRANSIENT);
- if (bn == NULL) {
+ } else if (allnulls) {
+ if (!(bn = BATconstant(b->hseqbase, TYPE_bit,
ATOMnilptr(TYPE_bit), BATcount(b), TRANSIENT)))
res = createException(MAL, "pcre.like3",
SQLSTATE(HY013) MAL_MALLOC_FAIL);
- } else {
- bit *res = (bit*)Tloc(bn, 0);
-
- if (allnulls) {
- for (BUN p = 0; p < q; p++)
- res[p] = bit_nil;
- bn->tnonil = false;
- bn->tnil = true;
- bn->tsorted = true;
- bn->trevsorted = true;
- } else {
- BATiter bi = bat_iterator(b);
- const char *dpat = *pat, *restrict v;
-
- if (*not)
- proj_scanloop(strcmp(v, dpat) != 0);
- else
- proj_scanloop(strcmp(v, dpat) == 0);
- }
- BATsetcount(bn, q);
- }
} else {
res = pcre_like(&bn, b, ppat, (bool) *isens, (bool) *not);
}
@@ -2160,20 +2115,15 @@ PCRElikeselect2(bat *ret, const bat *bid
throw(MAL, "algebra.likeselect", SQLSTATE(HY002)
RUNTIME_OBJECT_MISSING);
}
- if ((res = choose_like_path(&ppat, &use_re, &use_strcmp, &empty, pat,
esc, caseignore)) != MAL_SUCCEED) {
+ if ((res = choose_like_path(&ppat, &use_re, &use_strcmp, &empty, pat,
esc)) != MAL_SUCCEED) {
BBPunfix(b->batCacheid);
return res;
}
if (use_re) {
res = re_likeselect(&bn, b, s, *pat, (bool) *caseignore, (bool)
*anti, use_strcmp, (unsigned char) **esc);
- } else if (ppat == NULL) {
- /* no pattern and no special characters: can use normal select
*/
- if (empty)
- bn = BATdense(0, 0, 0);
- else
- bn = BATselect(b, s, *pat, NULL, true, true, *anti);
- if (bn == NULL)
+ } else if (empty) {
+ if (!(bn = BATdense(0, 0, 0)))
res = createException(MAL, "algebra.likeselect",
SQLSTATE(HY013) MAL_MALLOC_FAIL);
} else {
res = pcre_likeselect(&bn, b, s, ppat, (bool) *caseignore,
(bool) *anti);
@@ -2256,12 +2206,13 @@ pcrejoin(BAT *r1, BAT *r2, BAT *l, BAT *
int errcode = -1;
#endif
- if (caseignore)
+ if (caseignore) {
#ifdef HAVE_LIBPCRE
pcreopt |= PCRE_CASELESS;
#else
- options |= REG_ICASE;
+ options |= REG_ICASE;
#endif
+ }
TRC_DEBUG(ALGO,
"pcrejoin(l=%s#" BUNFMT "[%s]%s%s,"
@@ -2311,7 +2262,7 @@ pcrejoin(BAT *r1, BAT *r2, BAT *l, BAT *
use_strcmp = false;
empty = false;
- if ((msg = choose_like_path(&pcrepat, &use_re, &use_strcmp,
&empty, (const str*)&vr, (const str*)&esc, (const bit*)&caseignore)))
+ if ((msg = choose_like_path(&pcrepat, &use_re, &use_strcmp,
&empty, (const str*)&vr, (const str*)&esc)))
goto bailout;
if (empty) {
continue;
@@ -2381,9 +2332,6 @@ pcrejoin(BAT *r1, BAT *r2, BAT *l, BAT *
continue;
}
}
- } else if (!pcrere) {
- if (strcmp(vl, vr) != 0)
- continue;
} else {
assert(pcrere);
#ifdef HAVE_LIBPCRE
_______________________________________________
checkin-list mailing list
[email protected]
https://www.monetdb.org/mailman/listinfo/checkin-list