return r;
}
+#ifdef USE_SUNDAY_QUICK_SEARCH_ALGORITHM
+static int
+set_bmh_skip(UChar* s, UChar* end, OnigEncoding enc ARG_UNUSED, UChar skip[])
+{
+ int i, len;
+
+ len = (int )(end - s);
+ if (len + 1 >= ONIG_CHAR_TABLE_SIZE)
+ return ONIGERR_PARSER_BUG;
+
+ for (i = 0; i < ONIG_CHAR_TABLE_SIZE; i++) skip[i] = (UChar )(len + 1);
+
+ for (i = 0; i < len; i++)
+ skip[s[i]] = len - i;
+
+ return 0;
+}
+#else
/* set skip map for Boyer-Moore-Horspool search */
static int
set_bmh_skip(UChar* s, UChar* end, OnigEncoding enc ARG_UNUSED, UChar skip[])
return ONIGERR_PARSER_BUG;
}
}
+#endif /* USE_SUNDAY_QUICK_SEARCH_ALGORITHM */
+
#define OPT_EXACT_MAXLEN 24
return (UChar* )NULL;
}
+#ifdef USE_SUNDAY_QUICK_SEARCH_ALGORITHM
+
+static UChar*
+bmh_search_forward(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, *t, *p, *end;
+ const UChar *tail;
+ int skip, tlen1;
+
+#ifdef ONIG_DEBUG_SEARCH
+ fprintf(stderr,
+ "bmh_search_forward: text: %p, text_end: %p, text_range: %p\n",
+ text, text_end, text_range);
+#endif
+
+ tail = target_end - 1;
+ tlen1 = (int )(tail - target);
+ end = text_range;
+ if (end + tlen1 > text_end)
+ end = text_end - tlen1;
+
+ s = text;
+
+ while (s < end) {
+ p = se = s + tlen1;
+ t = tail;
+ while (*p == *t) {
+ if (t == target) return (UChar* )s;
+ p--; t--;
+ }
+ if (se + 1 >= text_end) break;
+ skip = reg->map[*(se + 1)];
+ t = s;
+ do {
+ s += enclen(reg->enc, s);
+ } while ((s - t) < skip && s < end);
+ }
+
+ return (UChar* )NULL;
+}
+
+static UChar*
+bmh_search(regex_t* reg, const UChar* target, const UChar* target_end,
+ const UChar* text, const UChar* text_end, const UChar* text_range)
+{
+ const UChar *s, *t, *p, *end;
+ const UChar *tail;
+
+ end = text_range + (target_end - target);
+ if (end > text_end)
+ end = text_end;
+
+ tail = target_end - 1;
+ s = text + (tail - target);
+
+ while (s < end) {
+ p = s;
+ t = tail;
+ while (*p == *t) {
+ if (t == target) return (UChar* )p;
+ p--; t--;
+ }
+ if (s + 1 >= text_end) break;
+ s += reg->map[*(s + 1)];
+ }
+
+ return (UChar* )NULL;
+}
+
+#else
+
static UChar*
bmh_search_forward(regex_t* reg, const UChar* target, const UChar* target_end,
const UChar* text, const UChar* text_end,
return (UChar* )NULL;
}
+#endif /* USE_SUNDAY_QUICK_SEARCH_ALGORITHM */
static UChar*
map_search(OnigEncoding enc, UChar map[],