ruby-changes:74422
From: TSUYUSATO <ko1@a...>
Date: Wed, 9 Nov 2022 23:22:06 +0900 (JST)
Subject: [ruby-changes:74422] d84edce689 (master): Increment num_fail on OP_POP too
https://git.ruby-lang.org/ruby.git/commit/?id=d84edce689 From d84edce689b8634d9a627a2b73434b9115dd5c72 Mon Sep 17 00:00:00 2001 From: TSUYUSATO Kitsune <make.just.on@g...> Date: Tue, 4 Oct 2022 12:28:55 +0900 Subject: Increment num_fail on OP_POP too --- regexec.c | 19 +++++++++++++++---- 1 file changed, 15 insertions(+), 4 deletions(-) diff --git a/regexec.c b/regexec.c index e098cc734a..1633871647 100644 --- a/regexec.c +++ b/regexec.c @@ -1077,13 +1077,13 @@ stack_double(OnigStackType** arg_stk_base, OnigStackType** arg_stk_end, https://github.com/ruby/ruby/blob/trunk/regexec.c#L1077 int index = key >> 3;\ int mask = 1 << (key & 7);\ if ((match_cache)[index] & mask) {\ - /*fprintf(stderr, "Use cache (pos: %d, p: %p, pc: %d, cache index: %d, key: %d, index: %d, mask: %d)\n", pos, p, (int)(p - pstart), cache_index, key, index, mask);*/\ + /* fprintf(stderr, "Use cache (pos: %d, p: %p, pc: %d, cache index: %d, key: %d, index: %d, mask: %d)\n", pos, p, (int)(p - pstart), cache_index, key, index, mask); */\ goto fail;\ }\ - /*fprintf(stderr, "Add cache (pos: %d, p: %p, pc: %d, cache index: %d, key: %d, index: %d, mask: %d)\n", pos, p, (int)(p - pstart), cache_index, key, index, mask);*/\ + /* fprintf(stderr, "Add cache (pos: %d, p: %p, pc: %d, cache index: %d, key: %d, index: %d, mask: %d)\n", pos, p, (int)(p - pstart), cache_index, key, index, mask); */\ (match_cache)[index] |= mask;\ } else {\ - /*fprintf(stderr, "Miss cache (pos: %d, p: %p, pc: %d, cache index: %d)\n", pos, p, (int)(p - pstart), cache_index);*/\ + /* fprintf(stderr, "Miss cache (pos: %d, p: %p, pc: %d, cache index: %d)\n", pos, p, (int)(p - pstart), cache_index); */\ }\ }\ } while (0) @@ -3291,6 +3291,9 @@ match_at(regex_t* reg, const UChar* str, const UChar* end, https://github.com/ruby/ruby/blob/trunk/regexec.c#L3291 CASE(OP_POP) MOP_IN(OP_POP); STACK_POP_ONE; + /* We need to increment num_fail here, for invoking a cache optimization correctly, */ + /* because Onigmo makes a loop, which is pairwise disjoint to the following set, as atomic. */ + msa->num_fail++; MOP_OUT; JUMP; @@ -3582,11 +3585,12 @@ match_at(regex_t* reg, const UChar* str, const UChar* end, https://github.com/ruby/ruby/blob/trunk/regexec.c#L3585 pkeep = stk->u.state.pkeep; #ifdef USE_CACHE_MATCH_OPT - if (++msa->num_fail == (int)(end - str) + 1 && msa->num_cache_opcode == NUM_CACHE_OPCODE_UNINIT) { + if (++msa->num_fail >= (int)(end - str) + 1 && msa->num_cache_opcode == NUM_CACHE_OPCODE_UNINIT) { msa->enable_cache_match_opt = 1; if (msa->num_cache_opcode == NUM_CACHE_OPCODE_UNINIT) { msa->num_cache_opcode = count_num_cache_opcode(reg); } + // fprintf(stderr, "num_cache_opcode: %d\n", msa->num_cache_opcode); if (msa->num_cache_opcode == NUM_CACHE_OPCODE_FAIL || msa->num_cache_opcode == 0) { msa->enable_cache_match_opt = 0; goto fail_match_cache_opt; @@ -3599,6 +3603,13 @@ match_at(regex_t* reg, const UChar* str, const UChar* end, https://github.com/ruby/ruby/blob/trunk/regexec.c#L3603 } init_cache_index_table(reg, table); msa->cache_index_table = table; + /* + fprintf(stderr, "table = {%p", table); + for (int i = 1; i < msa->num_cache_opcode; i++) { + fprintf(stderr, ", %p", table+i); + } + fprintf(stderr, "}\n"); + */ } // TODO: check arithemetic overflow. int match_cache_size8 = msa->num_cache_opcode * ((int)(end - str) + 1); -- cgit v1.2.3 -- ML: ruby-changes@q... Info: http://www.atdot.net/~ko1/quickml/