From: K.Kosako Date: Tue, 2 Oct 2018 05:38:08 +0000 (+0900) Subject: add OPTIMIZE_STR_CASE_FOLD_FAST X-Git-Tag: v6.9.1~18^2~27 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=f93aef5dfea2d53eed88afccfe6fc49f5a5019a3;p=onig add OPTIMIZE_STR_CASE_FOLD_FAST --- diff --git a/src/regexec.c b/src/regexec.c index 192af20..378e296 100644 --- a/src/regexec.c +++ b/src/regexec.c @@ -4116,8 +4116,8 @@ slow_search_backward_ic(OnigEncoding enc, int case_fold_flag, static UChar* sunday_quick_search_step_forward(regex_t* reg, - const UChar* target, const UChar* target_end, - const UChar* text, const UChar* text_end, + const UChar* target, const UChar* target_end, + const UChar* text, const UChar* text_end, const UChar* text_range) { const UChar *s, *se, *t, *p, *end; @@ -4188,6 +4188,53 @@ sunday_quick_search(regex_t* reg, const UChar* target, const UChar* target_end, return (UChar* )NULL; } +static UChar* +sunday_quick_search_case_fold(regex_t* reg, + const UChar* target, const UChar* target_end, + const UChar* text, const UChar* text_end, + const UChar* text_range) +{ + const UChar *s, *se, *p, *end; + const UChar *tail; + int skip, tlen1; + int map_offset; + int case_fold_flag; + OnigEncoding enc; + +#ifdef ONIG_DEBUG_SEARCH + fprintf(stderr, + "sunday_quick_search_case_fold: text: %p, text_end: %p, text_range: %p\n", text, text_end, text_range); +#endif + + enc = reg->enc; + case_fold_flag = reg->case_fold_flag; + + tail = target_end - 1; + tlen1 = (int )(tail - target); + end = text_range; + if (end + tlen1 > text_end) + end = text_end - tlen1; + + map_offset = reg->map_offset; + s = text; + + while (s < end) { + if (str_lower_case_match(enc, case_fold_flag, target, target_end, + s, text_end)) + return (UChar* )s; + + se = s + tlen1; + if (se + map_offset >= text_end) break; + skip = reg->map[*(se + map_offset)]; + p = s; + do { + s += enclen(reg->enc, s); + } while ((s - p) < skip && s < end); + } + + return (UChar* )NULL; +} + #else static UChar* @@ -4372,6 +4419,16 @@ forward_search_range(regex_t* reg, const UChar* str, const UChar* end, UChar* s, reg->exact, reg->exact_end, p, end, range); break; + case OPTIMIZE_STR_CASE_FOLD_FAST: +#ifdef USE_SUNDAY_QUICK_SEARCH_ALGORITHM + p = sunday_quick_search_case_fold(reg, reg->exact, reg->exact_end, p, end, + range); +#else + p = slow_search_ic(reg->enc, reg->case_fold_flag, + reg->exact, reg->exact_end, p, end, range); +#endif + break; + case OPTIMIZE_STR_FAST: #ifdef USE_SUNDAY_QUICK_SEARCH_ALGORITHM p = sunday_quick_search(reg, reg->exact, reg->exact_end, p, end, range); @@ -4503,6 +4560,7 @@ backward_search_range(regex_t* reg, const UChar* str, const UChar* end, break; case OPTIMIZE_STR_CASE_FOLD: + case OPTIMIZE_STR_CASE_FOLD_FAST: p = slow_search_backward_ic(reg->enc, reg->case_fold_flag, reg->exact, reg->exact_end, range, adjrange, end, p); diff --git a/src/regint.h b/src/regint.h index d791776..fb7a4a4 100644 --- a/src/regint.h +++ b/src/regint.h @@ -317,6 +317,7 @@ enum OptimizeType { OPTIMIZE_STR, /* Slow Search */ OPTIMIZE_STR_FAST, /* Sunday quick search or BMH */ OPTIMIZE_STR_FAST_STEP_FORWARD, /* Sunday quick search or BMH */ + OPTIMIZE_STR_CASE_FOLD_FAST, /* Sunday quick search (ignore case) */ OPTIMIZE_STR_CASE_FOLD, /* Slow Search (ignore case) */ OPTIMIZE_MAP /* char map */ };