From a50b33803d1cd5a67c0fea6392b8f98d006db537 Mon Sep 17 00:00:00 2001 From: "K.Kosako" Date: Tue, 19 Feb 2019 17:19:54 +0900 Subject: [PATCH] reduce Operation size --- src/regcomp.c | 13 +++++++++++-- src/regexec.c | 8 ++++---- src/regint.h | 4 ++-- 3 files changed, 17 insertions(+), 8 deletions(-) diff --git a/src/regcomp.c b/src/regcomp.c index 69c73c7..2fdb6c9 100644 --- a/src/regcomp.c +++ b/src/regcomp.c @@ -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); diff --git a/src/regexec.c b/src/regexec.c index 2991036..2beea4e 100644 --- a/src/regexec.c +++ b/src/regexec.c @@ -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++; diff --git a/src/regint.h b/src/regint.h index 6800e6d..63214cf 100644 --- a/src/regint.h +++ b/src/regint.h @@ -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; -- 2.40.0