Changeset: b599dc7c4ccb for MonetDB
URL: https://dev.monetdb.org/hg/MonetDB/rev/b599dc7c4ccb
Modified Files:
        monetdb5/modules/mal/pcre.c
Branch: default
Log Message:

make sure we only allocate once for all the pcre2_substitute calls done from 
pcre_replace_bat


diffs (41 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
@@ -26,7 +26,7 @@
 #include "mal_exception.h"
 
 #include <wchar.h>
-#include <wctype.h>
+//#include <wctype.h>
 
 #ifdef HAVE_LIBPCRE
 #define PCRE2_CODE_UNIT_WIDTH 8
@@ -449,7 +449,7 @@ pcre_replace_bat(BAT **res, BAT *origin_
        BUN p, q;
        PCRE2_SIZE len_replacement = (PCRE2_SIZE) strlen(replacement);
        PCRE2_SPTR origin_str;
-       PCRE2_SIZE max_dest_size = 0;
+       PCRE2_SIZE max_dest_size = 0, init_size = 0;
 
        while (*flags) {
                switch (*flags) {
@@ -499,7 +499,7 @@ pcre_replace_bat(BAT **res, BAT *origin_
 
        /* the buffer for all destination strings is allocated only once,
         * and extended when needed */
-       max_dest_size = len_replacement + 1;
+       init_size = max_dest_size = 64*1024;
        tmpres = GDKmalloc(max_dest_size);
        if (tmpbat == NULL || tmpres == NULL) {
                pcre2_match_data_free(match_data);
@@ -525,6 +525,10 @@ pcre_replace_bat(BAT **res, BAT *origin_
                        throw(MAL, global ? "batpcre.replace" : 
"batpcre.replace_first",
                                  SQLSTATE(HY013) MAL_MALLOC_FAIL);
                }
+               if (max_dest_size <= init_size)
+                       max_dest_size = init_size;
+               else /* buffer is enlarged */
+                       init_size = max_dest_size;
        }
        bat_iterator_end(&origin_strsi);
        pcre2_match_data_free(match_data);
_______________________________________________
checkin-list mailing list -- [email protected]
To unsubscribe send an email to [email protected]

Reply via email to