From f11245f8114581d67e549b36c756683c890dae4e Mon Sep 17 00:00:00 2001 From: Tyge Løvset Date: Wed, 14 Dec 2022 20:44:29 +0100 Subject: cregex optimizations. --- src/cregex.c | 30 ++++++++++++++++-------------- 1 file changed, 16 insertions(+), 14 deletions(-) (limited to 'src/cregex.c') diff --git a/src/cregex.c b/src/cregex.c index 71b1ee87..61f85339 100644 --- a/src/cregex.c +++ b/src/cregex.c @@ -191,30 +191,31 @@ chartorune(_Rune *rune, const char *s) static const char* utfrune(const char *s, _Rune c) { - _Rune r; - if (c < 128) /* ascii */ return strchr((char *)s, (int)c); - - for (;;) { - int n = chartorune(&r, s); + int n; + for (_Rune r = *s; r; s += n, r = *(unsigned char*)s) { + if (r < 128) { n = 1; continue; } + n = chartorune(&r, s); if (r == c) return s; - if ((r == 0) | (n == 0)) return NULL; - s += n; } + return NULL; } static const char* utfruneicase(const char *s, _Rune c) { - _Rune r; - c = utf8_casefold(c); - for (;;) { - int n = chartorune(&r, s); + _Rune r = *s; + int n; + if (c < 128) for (c = tolower(c); r; ++s, r = *(unsigned char*)s) { + if (r < 128 && tolower(r) == c) return s; + } + else for (c = utf8_casefold(c); r; s += n, r = *(unsigned char*)s) { + if (r < 128) { n = 1; continue; } + n = chartorune(&r, s); if (utf8_casefold(r) == c) return s; - if ((r == 0) | (n == 0)) return NULL; - s += n; } + return NULL; } /************ @@ -979,7 +980,8 @@ _regexec1(const _Reprog *progp, /* program to run */ break; } } - n = chartorune(&r, s); + r = *(unsigned char*)s; + n = r < 128 ? 1 : chartorune(&r, s); /* switch run lists */ tl = j->relist[flag]; -- cgit v1.2.3