aboutsummaryrefslogtreecommitdiff
path: root/match.c
diff options
context:
space:
mode:
authorBruce Hill <bruce@bruce-hill.com>2021-09-24 23:14:38 -0700
committerBruce Hill <bruce@bruce-hill.com>2021-09-24 23:14:38 -0700
commit849257dde0365abe43680997edc0ce60100b1a64 (patch)
tree47b97a14d3266aeda1d96d1ec9f7caf0779be2f7 /match.c
parent1b777a569e10252e3006923c51fe53810ee57660 (diff)
Removed weak optimization for ignorecase skipping
Diffstat (limited to 'match.c')
-rw-r--r--match.c16
1 files changed, 3 insertions, 13 deletions
diff --git a/match.c b/match.c
index 870b4d0..77f5a75 100644
--- a/match.c
+++ b/match.c
@@ -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;