From 7522bffc322d419dc4ccb806278964029e756125 Mon Sep 17 00:00:00 2001 From: "K.Kosako" Date: Tue, 19 Feb 2019 13:37:24 +0900 Subject: [PATCH] disable OP_PUSH_OR_JUMP_EXACT1 --- src/regcomp.c | 17 ++++++++++++----- src/regexec.c | 8 ++++++++ src/regint.h | 8 +++++++- 3 files changed, 27 insertions(+), 6 deletions(-) diff --git a/src/regcomp.c b/src/regcomp.c index f44ac5c..69c73c7 100644 --- a/src/regcomp.c +++ b/src/regcomp.c @@ -811,9 +811,12 @@ compile_length_quantifier_node(QuantNode* qn, regex_t* reg) } if (qn->greedy) { +#ifdef USE_OP_PUSH_OR_JUMP_EXACT if (IS_NOT_NULL(qn->head_exact)) len += SIZE_OP_PUSH_OR_JUMP_EXACT1 + mod_tlen + SIZE_OP_JUMP; - else if (IS_NOT_NULL(qn->next_head_exact)) + else +#endif + if (IS_NOT_NULL(qn->next_head_exact)) len += SIZE_OP_PUSH_IF_PEEK_NEXT + mod_tlen + SIZE_OP_JUMP; else len += SIZE_OP_PUSH + mod_tlen + SIZE_OP_JUMP; @@ -888,9 +891,12 @@ compile_quantifier_node(QuantNode* qn, regex_t* reg, ScanEnv* env) r = add_op(reg, OP_JUMP); if (r != 0) return r; if (qn->greedy) { +#ifdef USE_OP_PUSH_OR_JUMP_EXACT if (IS_NOT_NULL(qn->head_exact)) COP(reg)->jump.addr = SIZE_OP_PUSH_OR_JUMP_EXACT1 + SIZE_INC_OP; - else if (IS_NOT_NULL(qn->next_head_exact)) + else +#endif + if (IS_NOT_NULL(qn->next_head_exact)) COP(reg)->jump.addr = SIZE_OP_PUSH_IF_PEEK_NEXT + SIZE_INC_OP; else COP(reg)->jump.addr = SIZE_OP_PUSH + SIZE_INC_OP; @@ -905,6 +911,7 @@ compile_quantifier_node(QuantNode* qn, regex_t* reg, ScanEnv* env) } if (qn->greedy) { +#ifdef USE_OP_PUSH_OR_JUMP_EXACT if (IS_NOT_NULL(qn->head_exact)) { r = add_op(reg, OP_PUSH_OR_JUMP_EXACT1); if (r != 0) return r; @@ -916,7 +923,9 @@ compile_quantifier_node(QuantNode* qn, regex_t* reg, ScanEnv* env) addr = -(mod_tlen + (int )SIZE_OP_PUSH_OR_JUMP_EXACT1); } - else if (IS_NOT_NULL(qn->next_head_exact)) { + else +#endif + if (IS_NOT_NULL(qn->next_head_exact)) { r = add_op(reg, OP_PUSH_IF_PEEK_NEXT); if (r != 0) return r; COP(reg)->push_if_peek_next.addr = SIZE_INC_OP + mod_tlen + SIZE_OP_JUMP; @@ -4450,7 +4459,6 @@ setup_quant(Node* node, regex_t* reg, int state, ScanEnv* env) } } -#ifdef USE_OP_PUSH_OR_JUMP_EXACT if (qn->greedy && (qn->body_empty_info == QUANT_BODY_IS_NOT_EMPTY)) { if (NODE_TYPE(body) == NODE_QUANT) { QuantNode* tqn = QUANT_(body); @@ -4463,7 +4471,6 @@ setup_quant(Node* node, regex_t* reg, int state, ScanEnv* env) qn->head_exact = get_head_value_node(NODE_BODY(node), 1, reg); } } -#endif return r; } diff --git a/src/regexec.c b/src/regexec.c index 99272b0..80c98cb 100644 --- a/src/regexec.c +++ b/src/regexec.c @@ -215,7 +215,9 @@ static OpInfoType OpInfo[] = { { OP_PUSH, "push" }, { OP_PUSH_SUPER, "push-super" }, { OP_POP_OUT, "pop-out" }, +#ifdef USE_OP_PUSH_OR_JUMP_EXACT { OP_PUSH_OR_JUMP_EXACT1, "push-or-jump-e1" }, +#endif { OP_PUSH_IF_PEEK_NEXT, "push-if-peek-next" }, { OP_REPEAT, "repeat" }, { OP_REPEAT_NG, "repeat-ng" }, @@ -461,12 +463,14 @@ onig_print_compiled_byte_code(FILE* f, Operation* p, Operation* start, OnigEncod p_rel_addr(f, addr, p, start); break; +#ifdef USE_OP_PUSH_OR_JUMP_EXACT case OP_PUSH_OR_JUMP_EXACT1: addr = p->push_or_jump_exact1.addr; fputc(':', f); p_rel_addr(f, addr, p, start); p_string(f, 1, &(p->push_or_jump_exact1.c)); break; +#endif case OP_PUSH_IF_PEEK_NEXT: addr = p->push_if_peek_next.addr; @@ -2513,7 +2517,9 @@ match_at(regex_t* reg, const UChar* str, const UChar* end, &&L_PUSH, &&L_PUSH_SUPER, &&L_POP_OUT, +#ifdef USE_OP_PUSH_OR_JUMP_EXACT &&L_PUSH_OR_JUMP_EXACT1, +#endif &&L_PUSH_IF_PEEK_NEXT, &&L_REPEAT, &&L_REPEAT_NG, @@ -3699,6 +3705,7 @@ match_at(regex_t* reg, const UChar* str, const UChar* end, INC_OP; JUMP_OUT; + #ifdef USE_OP_PUSH_OR_JUMP_EXACT CASE_OP(PUSH_OR_JUMP_EXACT1) { UChar c; @@ -3713,6 +3720,7 @@ match_at(regex_t* reg, const UChar* str, const UChar* end, } p += addr; JUMP_OUT; +#endif CASE_OP(PUSH_IF_PEEK_NEXT) { diff --git a/src/regint.h b/src/regint.h index c10b80a..30df0a5 100644 --- a/src/regint.h +++ b/src/regint.h @@ -72,7 +72,7 @@ #endif /* internal config */ -#define USE_OP_PUSH_OR_JUMP_EXACT +/* #define USE_OP_PUSH_OR_JUMP_EXACT */ #define USE_QUANT_PEEK_NEXT #define USE_ST_LIBRARY @@ -565,7 +565,9 @@ enum OpCode { OP_PUSH, OP_PUSH_SUPER, OP_POP_OUT, +#ifdef USE_OP_PUSH_OR_JUMP_EXACT OP_PUSH_OR_JUMP_EXACT1, /* if match exact then push, else jump. */ +#endif OP_PUSH_IF_PEEK_NEXT, /* if match exact then push, else none. */ OP_REPEAT, /* {n,m} */ OP_REPEAT_NG, /* {n,m}? (non greedy) */ @@ -662,7 +664,9 @@ typedef int ModeType; #define SIZE_OP_PUSH (SIZE_OPCODE + SIZE_RELADDR) #define SIZE_OP_PUSH_SUPER (SIZE_OPCODE + SIZE_RELADDR) #define SIZE_OP_POP_OUT SIZE_OPCODE +#ifdef USE_OP_PUSH_OR_JUMP_EXACT #define SIZE_OP_PUSH_OR_JUMP_EXACT1 (SIZE_OPCODE + SIZE_RELADDR + 1) +#endif #define SIZE_OP_PUSH_IF_PEEK_NEXT (SIZE_OPCODE + SIZE_RELADDR + 1) #define SIZE_OP_REPEAT_INC (SIZE_OPCODE + SIZE_MEMNUM) #define SIZE_OP_REPEAT_INC_NG (SIZE_OPCODE + SIZE_MEMNUM) @@ -706,7 +710,9 @@ typedef int ModeType; #define SIZE_OP_PUSH 1 #define SIZE_OP_PUSH_SUPER 1 #define SIZE_OP_POP_OUT 1 +#ifdef USE_OP_PUSH_OR_JUMP_EXACT #define SIZE_OP_PUSH_OR_JUMP_EXACT1 1 +#endif #define SIZE_OP_PUSH_IF_PEEK_NEXT 1 #define SIZE_OP_REPEAT 1 #define SIZE_OP_REPEAT_INC 1 -- 2.40.0