Removed weak optimization for ignorecase skipping

This commit is contained in:
Bruce Hill 2021-09-24 23:14:38 -07:00
parent 1b777a569e
commit 849257dde0

16
match.c
View File

@ -269,19 +269,9 @@ static match_t *_next_match(match_context_t *ctx, const char *str, pat_t *pat, p
// Performance optimization: if the pattern starts with a string literal,
// we can just rely on the highly optimized memmem() implementation to skip
// past areas where we know we won't find a match.
if (!skip && first->type == BP_STRING && first->min_matchlen > 0) {
if (ctx->ignorecase) {
char c1 = first->args.string[0];
char *upper = memchr(str, toupper(c1), (size_t)(str - ctx->end));
char *lower = isalpha(c1) ? memchr(str, tolower(c1), (size_t)(str - ctx->end)) : NULL;
if (upper && lower)
str = upper < lower ? upper : lower;
else if (upper) str = upper;
else if (lower) str = lower;
} else {
char *found = memmem(str, (size_t)(ctx->end - str), first->args.string, first->min_matchlen);
str = found ? found : ctx->end;
}
if (!skip && first->type == BP_STRING && first->min_matchlen > 0 && !ctx->ignorecase) {
char *found = memmem(str, (size_t)(ctx->end - str), first->args.string, first->min_matchlen);
str = found ? found : ctx->end;
}
if (str > ctx->end) return NULL;