Changeset: b8a3eeaa2a5e for MonetDB
URL: http://dev.monetdb.org/hg/MonetDB?cmd=changeset;node=b8a3eeaa2a5e
Modified Files:
        monetdb5/modules/mal/pcre.c
Branch: default
Log Message:

Factor out PCRE compilation from BAT loop.


diffs (59 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
@@ -1252,28 +1252,36 @@ BATPCRElike3(bat *ret, int *bid, str *pa
                                i++;
                        }
                } else {
-                       if (*isens) {
-                               BATloop(strs, p, q) {
-                                       str s = (str)BUNtail(strsi, p);
+                       const char err[BUFSIZ], *err_p = err;
+                       int errpos = 0;
+                       int options = PCRE_UTF8;
+                       int pos;
+                       pcre *re;
 
-                                       res = PCREimatch(br + i, &s, &ppat);
-                                       i++;
+                       if ( !*isens)
+                               options |= PCRE_CASELESS;
+                       if ((re = pcre_compile(ppat, options, &err_p, &errpos, 
NULL)) == NULL) {
+                               throw(MAL, "pcre.match", OPERATION_FAILED
+                                               ": compilation of regular 
expression (%s) failed "
+                                               "at %d with '%s'", ppat, 
errpos, err_p);
+                       }
+
+                       BATloop(strs, p, q) {
+                               str s = (str)BUNtail(strsi, p);
+
+                               pos = pcre_exec(re, NULL, s, (int) strlen(s), 
0, 0, NULL, 0);
+
+                               if (pos >= 0)
+                                       br[i] = *not? FALSE:TRUE;
+                               else if (pos == -1)
+                                       br[i] = *not? TRUE: FALSE;
+                               else {
+                                       throw(MAL, "pcre.match", 
OPERATION_FAILED
+                                                       ": matching of regular 
expression (%s) failed with %d", ppat, pos);
                                }
-                       } else {
-                               BATloop(strs, p, q) {
-                                       str s = (str)BUNtail(strsi, p);
-
-                                       res = PCREmatch(br + i, &s, &ppat);
-                                       i++;
-                               }
+                               i++;
                        }
-                       if (*not) {
-                               i = 0;
-                               BATloop(strs, p, q) {
-                                       br[i] = !br[i];
-                                       i++;
-                               }
-                       }
+                       my_pcre_free(re);
                }
                BATaccessEnd(strs,USE_TAIL,MMAP_SEQUENTIAL);
                BATsetcount(r, i);
_______________________________________________
Checkin-list mailing list
[email protected]
http://mail.monetdb.org/mailman/listinfo/checkin-list

Reply via email to