Skip to content

Commit 1cb07b5

Browse files
k-takatanobu
authored andcommitted
Remove old code for BMH search
Remove the code for Boyer-Moore-Horspool search. Now we are using Sunday's quick search. k-takata/Onigmo@3d90724
1 parent 430a229 commit 1cb07b5

File tree

3 files changed

+0
-299
lines changed

3 files changed

+0
-299
lines changed

regcomp.c

Lines changed: 0 additions & 84 deletions
Original file line numberDiff line numberDiff line change
@@ -4213,89 +4213,6 @@ setup_tree(Node* node, regex_t* reg, int state, ScanEnv* env)
42134213
return r;
42144214
}
42154215

4216-
#ifndef USE_SUNDAY_QUICK_SEARCH
4217-
/* set skip map for Boyer-Moore search */
4218-
static int
4219-
set_bm_skip(UChar* s, UChar* end, regex_t* reg,
4220-
UChar skip[], int** int_skip, int ignore_case)
4221-
{
4222-
OnigDistance i, len;
4223-
int clen, flen, n, j, k;
4224-
UChar *p, buf[ONIGENC_MBC_CASE_FOLD_MAXLEN];
4225-
OnigCaseFoldCodeItem items[ONIGENC_GET_CASE_FOLD_CODES_MAX_NUM];
4226-
OnigEncoding enc = reg->enc;
4227-
4228-
len = end - s;
4229-
if (len < ONIG_CHAR_TABLE_SIZE) {
4230-
for (i = 0; i < ONIG_CHAR_TABLE_SIZE; i++) skip[i] = (UChar )len;
4231-
4232-
n = 0;
4233-
for (i = 0; i < len - 1; i += clen) {
4234-
p = s + i;
4235-
if (ignore_case)
4236-
n = ONIGENC_GET_CASE_FOLD_CODES_BY_STR(enc, reg->case_fold_flag,
4237-
p, end, items);
4238-
clen = enclen(enc, p, end);
4239-
if (p + clen > end)
4240-
clen = (int )(end - p);
4241-
4242-
for (j = 0; j < n; j++) {
4243-
if ((items[j].code_len != 1) || (items[j].byte_len != clen))
4244-
return 1; /* different length isn't supported. */
4245-
flen = ONIGENC_CODE_TO_MBC(enc, items[j].code[0], buf[j]);
4246-
if (flen != clen)
4247-
return 1; /* different length isn't supported. */
4248-
}
4249-
for (j = 0; j < clen; j++) {
4250-
skip[s[i + j]] = (UChar )(len - 1 - i - j);
4251-
for (k = 0; k < n; k++) {
4252-
skip[buf[k][j]] = (UChar )(len - 1 - i - j);
4253-
}
4254-
}
4255-
}
4256-
}
4257-
else {
4258-
# if OPT_EXACT_MAXLEN < ONIG_CHAR_TABLE_SIZE
4259-
/* This should not happen. */
4260-
return ONIGERR_TYPE_BUG;
4261-
# else
4262-
if (IS_NULL(*int_skip)) {
4263-
*int_skip = (int* )xmalloc(sizeof(int) * ONIG_CHAR_TABLE_SIZE);
4264-
if (IS_NULL(*int_skip)) return ONIGERR_MEMORY;
4265-
}
4266-
for (i = 0; i < ONIG_CHAR_TABLE_SIZE; i++) (*int_skip)[i] = (int )len;
4267-
4268-
n = 0;
4269-
for (i = 0; i < len - 1; i += clen) {
4270-
p = s + i;
4271-
if (ignore_case)
4272-
n = ONIGENC_GET_CASE_FOLD_CODES_BY_STR(enc, reg->case_fold_flag,
4273-
p, end, items);
4274-
clen = enclen(enc, p, end);
4275-
if (p + clen > end)
4276-
clen = (int )(end - p);
4277-
4278-
for (j = 0; j < n; j++) {
4279-
if ((items[j].code_len != 1) || (items[j].byte_len != clen))
4280-
return 1; /* different length isn't supported. */
4281-
flen = ONIGENC_CODE_TO_MBC(enc, items[j].code[0], buf[j]);
4282-
if (flen != clen)
4283-
return 1; /* different length isn't supported. */
4284-
}
4285-
for (j = 0; j < clen; j++) {
4286-
(*int_skip)[s[i + j]] = (int )(len - 1 - i - j);
4287-
for (k = 0; k < n; k++) {
4288-
(*int_skip)[buf[k][j]] = (int )(len - 1 - i - j);
4289-
}
4290-
}
4291-
}
4292-
# endif
4293-
}
4294-
return 0;
4295-
}
4296-
4297-
#else /* USE_SUNDAY_QUICK_SEARCH */
4298-
42994216
/* set skip map for Sunday's quick search */
43004217
static int
43014218
set_bm_skip(UChar* s, UChar* end, regex_t* reg,
@@ -4397,7 +4314,6 @@ set_bm_skip(UChar* s, UChar* end, regex_t* reg,
43974314
}
43984315
return (int)len;
43994316
}
4400-
#endif /* USE_SUNDAY_QUICK_SEARCH */
44014317

44024318
typedef struct {
44034319
OnigDistance min; /* min byte length */

regexec.c

Lines changed: 0 additions & 214 deletions
Original file line numberDiff line numberDiff line change
@@ -4377,219 +4377,6 @@ slow_search_backward_ic(OnigEncoding enc, int case_fold_flag,
43774377
return (UChar* )NULL;
43784378
}
43794379

4380-
#ifndef USE_SUNDAY_QUICK_SEARCH
4381-
/* Boyer-Moore-Horspool search applied to a multibyte string */
4382-
static UChar*
4383-
bm_search_notrev(regex_t* reg, const UChar* target, const UChar* target_end,
4384-
const UChar* text, const UChar* text_end,
4385-
const UChar* text_range)
4386-
{
4387-
const UChar *s, *se, *t, *p, *end;
4388-
const UChar *tail;
4389-
ptrdiff_t skip, tlen1;
4390-
4391-
# ifdef ONIG_DEBUG_SEARCH
4392-
fprintf(stderr, "bm_search_notrev: text: %"PRIuPTR" (%p), text_end: %"PRIuPTR" (%p), text_range: %"PRIuPTR" (%p)\n",
4393-
(uintptr_t )text, text, (uintptr_t )text_end, text_end, (uintptr_t )text_range, text_range);
4394-
# endif
4395-
4396-
tail = target_end - 1;
4397-
tlen1 = tail - target;
4398-
end = text_range;
4399-
if (end + tlen1 > text_end)
4400-
end = text_end - tlen1;
4401-
4402-
s = text;
4403-
4404-
if (IS_NULL(reg->int_map)) {
4405-
while (s < end) {
4406-
p = se = s + tlen1;
4407-
t = tail;
4408-
while (*p == *t) {
4409-
if (t == target) return (UChar* )s;
4410-
p--; t--;
4411-
}
4412-
skip = reg->map[*se];
4413-
t = s;
4414-
do {
4415-
s += enclen(reg->enc, s, end);
4416-
} while ((s - t) < skip && s < end);
4417-
}
4418-
}
4419-
else {
4420-
# if OPT_EXACT_MAXLEN >= ONIG_CHAR_TABLE_SIZE
4421-
while (s < end) {
4422-
p = se = s + tlen1;
4423-
t = tail;
4424-
while (*p == *t) {
4425-
if (t == target) return (UChar* )s;
4426-
p--; t--;
4427-
}
4428-
skip = reg->int_map[*se];
4429-
t = s;
4430-
do {
4431-
s += enclen(reg->enc, s, end);
4432-
} while ((s - t) < skip && s < end);
4433-
}
4434-
# endif
4435-
}
4436-
4437-
return (UChar* )NULL;
4438-
}
4439-
4440-
/* Boyer-Moore-Horspool search */
4441-
static UChar*
4442-
bm_search(regex_t* reg, const UChar* target, const UChar* target_end,
4443-
const UChar* text, const UChar* text_end, const UChar* text_range)
4444-
{
4445-
const UChar *s, *t, *p, *end;
4446-
const UChar *tail;
4447-
4448-
# ifdef ONIG_DEBUG_SEARCH
4449-
fprintf(stderr, "bm_search: text: %"PRIuPTR" (%p), text_end: %"PRIuPTR" (%p), text_range: %"PRIuPTR" (%p)\n",
4450-
(uintptr_t )text, text, (uintptr_t )text_end, text_end, (uintptr_t )text_range, text_range);
4451-
# endif
4452-
4453-
end = text_range + (target_end - target) - 1;
4454-
if (end > text_end)
4455-
end = text_end;
4456-
4457-
tail = target_end - 1;
4458-
s = text + (target_end - target) - 1;
4459-
if (IS_NULL(reg->int_map)) {
4460-
while (s < end) {
4461-
p = s;
4462-
t = tail;
4463-
# ifdef ONIG_DEBUG_SEARCH
4464-
fprintf(stderr, "bm_search_loop: pos: %"PRIdPTR" %s\n",
4465-
(intptr_t )(s - text), s);
4466-
# endif
4467-
while (*p == *t) {
4468-
if (t == target) return (UChar* )p;
4469-
p--; t--;
4470-
}
4471-
s += reg->map[*s];
4472-
}
4473-
}
4474-
else { /* see int_map[] */
4475-
# if OPT_EXACT_MAXLEN >= ONIG_CHAR_TABLE_SIZE
4476-
while (s < end) {
4477-
p = s;
4478-
t = tail;
4479-
while (*p == *t) {
4480-
if (t == target) return (UChar* )p;
4481-
p--; t--;
4482-
}
4483-
s += reg->int_map[*s];
4484-
}
4485-
# endif
4486-
}
4487-
return (UChar* )NULL;
4488-
}
4489-
4490-
/* Boyer-Moore-Horspool search applied to a multibyte string (ignore case) */
4491-
static UChar*
4492-
bm_search_notrev_ic(regex_t* reg, const UChar* target, const UChar* target_end,
4493-
const UChar* text, const UChar* text_end,
4494-
const UChar* text_range)
4495-
{
4496-
const UChar *s, *se, *t, *end;
4497-
const UChar *tail;
4498-
ptrdiff_t skip, tlen1;
4499-
OnigEncoding enc = reg->enc;
4500-
int case_fold_flag = reg->case_fold_flag;
4501-
4502-
# ifdef ONIG_DEBUG_SEARCH
4503-
fprintf(stderr, "bm_search_notrev_ic: text: %d (%p), text_end: %d (%p), text_range: %d (%p)\n",
4504-
(int )text, text, (int )text_end, text_end, (int )text_range, text_range);
4505-
# endif
4506-
4507-
tail = target_end - 1;
4508-
tlen1 = tail - target;
4509-
end = text_range;
4510-
if (end + tlen1 > text_end)
4511-
end = text_end - tlen1;
4512-
4513-
s = text;
4514-
4515-
if (IS_NULL(reg->int_map)) {
4516-
while (s < end) {
4517-
se = s + tlen1;
4518-
if (str_lower_case_match(enc, case_fold_flag, target, target_end,
4519-
s, se + 1))
4520-
return (UChar* )s;
4521-
skip = reg->map[*se];
4522-
t = s;
4523-
do {
4524-
s += enclen(reg->enc, s, end);
4525-
} while ((s - t) < skip && s < end);
4526-
}
4527-
}
4528-
else {
4529-
# if OPT_EXACT_MAXLEN >= ONIG_CHAR_TABLE_SIZE
4530-
while (s < end) {
4531-
se = s + tlen1;
4532-
if (str_lower_case_match(enc, case_fold_flag, target, target_end,
4533-
s, se + 1))
4534-
return (UChar* )s;
4535-
skip = reg->int_map[*se];
4536-
t = s;
4537-
do {
4538-
s += enclen(reg->enc, s, end);
4539-
} while ((s - t) < skip && s < end);
4540-
}
4541-
# endif
4542-
}
4543-
4544-
return (UChar* )NULL;
4545-
}
4546-
4547-
/* Boyer-Moore-Horspool search (ignore case) */
4548-
static UChar*
4549-
bm_search_ic(regex_t* reg, const UChar* target, const UChar* target_end,
4550-
const UChar* text, const UChar* text_end, const UChar* text_range)
4551-
{
4552-
const UChar *s, *p, *end;
4553-
const UChar *tail;
4554-
OnigEncoding enc = reg->enc;
4555-
int case_fold_flag = reg->case_fold_flag;
4556-
4557-
# ifdef ONIG_DEBUG_SEARCH
4558-
fprintf(stderr, "bm_search_ic: text: %d (%p), text_end: %d (%p), text_range: %d (%p)\n",
4559-
(int )text, text, (int )text_end, text_end, (int )text_range, text_range);
4560-
# endif
4561-
4562-
end = text_range + (target_end - target) - 1;
4563-
if (end > text_end)
4564-
end = text_end;
4565-
4566-
tail = target_end - 1;
4567-
s = text + (target_end - target) - 1;
4568-
if (IS_NULL(reg->int_map)) {
4569-
while (s < end) {
4570-
p = s - (target_end - target) + 1;
4571-
if (str_lower_case_match(enc, case_fold_flag, target, target_end,
4572-
p, s + 1))
4573-
return (UChar* )p;
4574-
s += reg->map[*s];
4575-
}
4576-
}
4577-
else { /* see int_map[] */
4578-
# if OPT_EXACT_MAXLEN >= ONIG_CHAR_TABLE_SIZE
4579-
while (s < end) {
4580-
p = s - (target_end - target) + 1;
4581-
if (str_lower_case_match(enc, case_fold_flag, target, target_end,
4582-
p, s + 1))
4583-
return (UChar* )p;
4584-
s += reg->int_map[*s];
4585-
}
4586-
# endif
4587-
}
4588-
return (UChar* )NULL;
4589-
}
4590-
4591-
#else /* USE_SUNDAY_QUICK_SEARCH */
4592-
45934380
/* Sunday's quick search applied to a multibyte string */
45944381
static UChar*
45954382
bm_search_notrev(regex_t* reg, const UChar* target, const UChar* target_end,
@@ -4808,7 +4595,6 @@ bm_search_ic(regex_t* reg, const UChar* target, const UChar* target_end,
48084595
}
48094596
return (UChar* )NULL;
48104597
}
4811-
#endif /* USE_SUNDAY_QUICK_SEARCH */
48124598

48134599
#ifdef USE_INT_MAP_BACKWARD
48144600
static int

regint.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,6 @@
8686
/* #define USE_OP_PUSH_OR_JUMP_EXACT */
8787
#define USE_QTFR_PEEK_NEXT
8888
#define USE_ST_LIBRARY
89-
#define USE_SUNDAY_QUICK_SEARCH
9089

9190
#define INIT_MATCH_STACK_SIZE 160
9291
#define DEFAULT_MATCH_STACK_LIMIT_SIZE 0 /* unlimited */

0 commit comments

Comments
 (0)