From: K.Kosako Date: Fri, 21 Sep 2018 06:50:41 +0000 (+0900) Subject: remove int_map member from re_pattern_buffer X-Git-Tag: v6.9.1~18^2~67 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=3d5a17fc6d925f68355a9f8fd117ace1aa2bd116;p=onig remove int_map member from re_pattern_buffer --- diff --git a/src/regcomp.c b/src/regcomp.c index 4512feb..8bc6897 100644 --- a/src/regcomp.c +++ b/src/regcomp.c @@ -4554,8 +4554,7 @@ setup_tree(Node* node, regex_t* reg, int state, ScanEnv* env) /* set skip map for Boyer-Moore search */ static int -set_bm_skip(UChar* s, UChar* end, OnigEncoding enc ARG_UNUSED, - UChar skip[], int** int_skip) +set_bm_skip(UChar* s, UChar* end, OnigEncoding enc ARG_UNUSED, UChar skip[]) { int i, len; @@ -4565,18 +4564,12 @@ set_bm_skip(UChar* s, UChar* end, OnigEncoding enc ARG_UNUSED, for (i = 0; i < len - 1; i++) skip[s[i]] = len - 1 - i; + + return 0; } else { - if (IS_NULL(*int_skip)) { - *int_skip = (int* )xmalloc(sizeof(int) * ONIG_CHAR_TABLE_SIZE); - if (IS_NULL(*int_skip)) return ONIGERR_MEMORY; - } - for (i = 0; i < ONIG_CHAR_TABLE_SIZE; i++) (*int_skip)[i] = len; - - for (i = 0; i < len - 1; i++) - (*int_skip)[s[i]] = len - 1 - i; + return ONIGERR_PARSER_BUG; } - return 0; } #define OPT_EXACT_MAXLEN 24 @@ -5563,7 +5556,7 @@ set_optimize_exact(regex_t* reg, OptExact* e) if (e->len >= 3 || (e->len >= 2 && allow_reverse)) { r = set_bm_skip(reg->exact, reg->exact_end, reg->enc, - reg->map, &(reg->int_map)); + reg->map); if (r != 0) return r; reg->optimize = (allow_reverse != 0 @@ -5909,7 +5902,6 @@ onig_free_body(regex_t* reg) if (IS_NOT_NULL(reg)) { if (IS_NOT_NULL(reg->p)) xfree(reg->p); if (IS_NOT_NULL(reg->exact)) xfree(reg->exact); - if (IS_NOT_NULL(reg->int_map)) xfree(reg->int_map); if (IS_NOT_NULL(reg->int_map_backward)) xfree(reg->int_map_backward); if (IS_NOT_NULL(reg->repeat_range)) xfree(reg->repeat_range); if (IS_NOT_NULL(REG_EXTP(reg))) { @@ -6166,7 +6158,6 @@ onig_reg_init(regex_t* reg, OnigOptionType option, OnigCaseFoldType case_fold_fl (reg)->syntax = syntax; (reg)->optimize = 0; (reg)->exact = (UChar* )NULL; - (reg)->int_map = (int* )NULL; (reg)->int_map_backward = (int* )NULL; REG_EXTPL(reg) = NULL; diff --git a/src/regexec.c b/src/regexec.c index ae03424..aff504f 100644 --- a/src/regexec.c +++ b/src/regexec.c @@ -4134,35 +4134,18 @@ bm_search_notrev(regex_t* reg, const UChar* target, const UChar* target_end, s = text; - if (IS_NULL(reg->int_map)) { - while (s < end) { - p = se = s + tlen1; - t = tail; - while (*p == *t) { - if (t == target) return (UChar* )s; - p--; t--; - } - skip = reg->map[*se]; - t = s; - do { - s += enclen(reg->enc, s); - } while ((s - t) < skip && s < end); - } - } - else { - while (s < end) { - p = se = s + tlen1; - t = tail; - while (*p == *t) { - if (t == target) return (UChar* )s; - p--; t--; - } - skip = reg->int_map[*se]; - t = s; - do { - s += enclen(reg->enc, s); - } while ((s - t) < skip && s < end); + while (s < end) { + p = se = s + tlen1; + t = tail; + while (*p == *t) { + if (t == target) return (UChar* )s; + p--; t--; } + skip = reg->map[*se]; + t = s; + do { + s += enclen(reg->enc, s); + } while ((s - t) < skip && s < end); } return (UChar* )NULL; @@ -4181,28 +4164,17 @@ bm_search(regex_t* reg, const UChar* target, const UChar* target_end, tail = target_end - 1; s = text + (target_end - target) - 1; - if (IS_NULL(reg->int_map)) { - while (s < end) { - p = s; - t = tail; - while (*p == *t) { - if (t == target) return (UChar* )p; - p--; t--; - } - s += reg->map[*s]; - } - } - else { /* see int_map[] */ - while (s < end) { - p = s; - t = tail; - while (*p == *t) { - if (t == target) return (UChar* )p; - p--; t--; - } - s += reg->int_map[*s]; + + while (s < end) { + p = s; + t = tail; + while (*p == *t) { + if (t == target) return (UChar* )p; + p--; t--; } + s += reg->map[*s]; } + return (UChar* )NULL; } diff --git a/src/regint.h b/src/regint.h index 1ab6f30..cd1cc7b 100644 --- a/src/regint.h +++ b/src/regint.h @@ -299,7 +299,6 @@ struct re_pattern_buffer { unsigned char *exact; unsigned char *exact_end; unsigned char map[ONIG_CHAR_TABLE_SIZE]; /* used as BM skip or char-map */ - int *int_map; /* BM skip for exact_len > 255 */ int *int_map_backward; /* BM skip for backward search */ OnigLen dmin; /* min-distance of exact or map */ OnigLen dmax; /* max-distance of exact or map */