]> granicus.if.org Git - onig/commitdiff
reduce Operation size
authorK.Kosako <kosako@sofnec.co.jp>
Tue, 19 Feb 2019 08:19:54 +0000 (17:19 +0900)
committerK.Kosako <kosako@sofnec.co.jp>
Thu, 28 Feb 2019 05:28:18 +0000 (14:28 +0900)
src/regcomp.c
src/regexec.c
src/regint.h

index 69c73c7f96d357050b0824aa4bccf6af5f359070..2fdb6c9996c8ba73f628ce7a477de84b3db94418 100644 (file)
@@ -195,11 +195,16 @@ ops_free(regex_t* reg)
       xfree(op->exact.s);
       break;
 
+    case OP_CCLASS_NOT: case OP_CCLASS:
+      xfree(op->cclass.bsp);
+      break;
+
     case OP_CCLASS_MB_NOT: case OP_CCLASS_MB:
       xfree(op->cclass_mb.mb);
       break;
     case OP_CCLASS_MIX_NOT: case OP_CCLASS_MIX:
       xfree(op->cclass_mix.mb);
+      xfree(op->cclass_mix.bsp);
       break;
 
     case OP_BACKREF1: case OP_BACKREF2: case OP_BACKREF_N: case OP_BACKREF_N_IC:
@@ -667,7 +672,9 @@ compile_cclass_node(CClassNode* cc, regex_t* reg)
     r = add_op(reg, IS_NCCLASS_NOT(cc) ? OP_CCLASS_NOT : OP_CCLASS);
     if (r != 0) return r;
 
-    xmemcpy(COP(reg)->cclass.bs, cc->bs, SIZE_BITSET);
+    COP(reg)->cclass.bsp = xmalloc(SIZE_BITSET);
+    CHECK_NULL_RETURN_MEMERR(COP(reg)->cclass.bsp);
+    xmemcpy(COP(reg)->cclass.bsp, cc->bs, SIZE_BITSET);
   }
   else {
     void* p;
@@ -684,7 +691,9 @@ compile_cclass_node(CClassNode* cc, regex_t* reg)
       r = add_op(reg, IS_NCCLASS_NOT(cc) ? OP_CCLASS_MIX_NOT : OP_CCLASS_MIX);
       if (r != 0) return r;
 
-      xmemcpy(COP(reg)->cclass_mix.bs, cc->bs, SIZE_BITSET);
+      COP(reg)->cclass_mix.bsp = xmalloc(SIZE_BITSET);
+      CHECK_NULL_RETURN_MEMERR(COP(reg)->cclass_mix.bsp);
+      xmemcpy(COP(reg)->cclass_mix.bsp, cc->bs, SIZE_BITSET);
 
       p = set_multi_byte_cclass(cc->mbuf, reg);
       CHECK_NULL_RETURN_MEMERR(p);
index 2991036262870de380baf232632b48c84e64bbcd..2beea4ea5fa06eccb9a2cfd9641b74dcb50dfbea 100644 (file)
@@ -2946,7 +2946,7 @@ match_at(regex_t* reg, const UChar* str, const UChar* end,
 
     CASE_OP(CCLASS)
       DATA_ENSURE(1);
-      if (BITSET_AT(p->cclass.bs, *s) == 0) goto fail;
+      if (BITSET_AT(p->cclass.bsp, *s) == 0) goto fail;
       s += enclen(encode, s);   /* OP_CCLASS can match mb-code. \D, \S */
       INC_OP;
       NEXT_OUT;
@@ -2977,7 +2977,7 @@ match_at(regex_t* reg, const UChar* str, const UChar* end,
         goto cclass_mb;
       }
       else {
-        if (BITSET_AT(p->cclass_mix.bs, *s) == 0)
+        if (BITSET_AT(p->cclass_mix.bsp, *s) == 0)
           goto fail;
 
         s++;
@@ -2987,7 +2987,7 @@ match_at(regex_t* reg, const UChar* str, const UChar* end,
 
     CASE_OP(CCLASS_NOT)
       DATA_ENSURE(1);
-      if (BITSET_AT(p->cclass.bs, *s) != 0) goto fail;
+      if (BITSET_AT(p->cclass.bsp, *s) != 0) goto fail;
       s += enclen(encode, s);
       INC_OP;
       NEXT_OUT;
@@ -3027,7 +3027,7 @@ match_at(regex_t* reg, const UChar* str, const UChar* end,
         goto cclass_mb_not;
       }
       else {
-        if (BITSET_AT(p->cclass_mix.bs, *s) != 0)
+        if (BITSET_AT(p->cclass_mix.bsp, *s) != 0)
           goto fail;
 
         s++;
index 6800e6d35cf246a0780168261b6e8c9aeecdeafa..63214cfdf670d19157f1da388e5887ba11e16217 100644 (file)
@@ -821,14 +821,14 @@ typedef struct {
       LengthType len; /* char byte length */
     } exact_len_n; /* EXACTMBN */
     struct {
-      BitSet bs;
+      BitSetRef bsp;
     } cclass;
     struct {
       void*  mb;
     } cclass_mb;
     struct {
       void*  mb; /* mb must be same position with cclass_mb for match_at(). */
-      BitSet bs;
+      BitSetRef bsp;
     } cclass_mix;
     struct {
       UChar c;