summaryrefslogtreecommitdiffhomepage
path: root/src/cregex.c
diff options
context:
space:
mode:
authorTyge Løvset <[email protected]>2022-12-14 20:44:29 +0100
committerTyge Løvset <[email protected]>2022-12-14 20:44:29 +0100
commitf11245f8114581d67e549b36c756683c890dae4e (patch)
treea75851f8b13d7154409f5e6e74db8084e5e7f443 /src/cregex.c
parent992812341a98c889297db8df0f8a34f1c59d07bb (diff)
downloadSTC-modified-f11245f8114581d67e549b36c756683c890dae4e.tar.gz
STC-modified-f11245f8114581d67e549b36c756683c890dae4e.zip
cregex optimizations.
Diffstat (limited to 'src/cregex.c')
-rw-r--r--src/cregex.c30
1 files changed, 16 insertions, 14 deletions
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];