ref: a3725097f53ab8521e31807b606cee84f0ce4173
parent: 7a401624c21a52bd3f8abf0e98667fad56712be3
parent: 7e3a4b9cfc50c4fc11ab20f5e736a8a468b6f0ad
author: cinap_lenrek <cinap_lenrek@felloff.net>
date: Mon Dec 8 20:42:02 EST 2025
merge
--- a/sys/src/libregexp/regexec.c
+++ b/sys/src/libregexp/regexec.c
@@ -19,7 +19,6 @@
char *sp, *ep, endc;
int i, matchgen, gen;
- memset(p->threads, 0, sizeof(Rethread)*p->nthr);
if(msize > NSUBEXPM)
msize = NSUBEXPM;
if(p->startinst->gen != 0) {@@ -27,17 +26,6 @@
ci->gen = 0;
}
- clist = lists;
- clist->head = nil;
- clist->tail = &clist->head;
- nlist = lists + 1;
- nlist->head = nil;
- nlist->tail = &nlist->head;
-
- pool = p->threads;
- avail = nil;
- gen = matchgen = 0;
-
sp = str;
ep = nil;
endc = '\0';
@@ -51,20 +39,35 @@
}
}
+ avail = nil;
+ pool = p->threads;
+
+ clist = lists;
+ clist->head = nil;
+ clist->tail = &clist->head;
+ nlist = lists + 1;
+ nlist->head = nil;
+ nlist->tail = &nlist->head;
+
+ gen = matchgen = 0;
for(r = L'☺'; r != L'\0'; sp += i) {- i = chartorune(&r, sp);
+ if((r = *sp) < Runeself)
+ i = 1;
+ else
+ i = chartorune(&r, sp);
gen++;
if(matchgen == 0) { if(avail == nil) {assert(pool < p->threads + p->nthr);
+ memset(pool, 0, sizeof(Rethread));
t = pool++;
} else {+ if(msize > 0)
+ memset(avail->sem, 0, sizeof(Resub)*msize);
t = avail;
avail = avail->next;
}
t->i = p->startinst;
- if(msize > 0)
- memset(t->sem, 0, sizeof(Resub)*msize);
t->next = nil;
t->gen = gen;
*clist->tail = t;
@@ -79,16 +82,34 @@
goto Done;
ci->gen = gen;
switch(ci->op) {+ default:
+ abort();
case ORUNE:
- if(r != ci->r)
- goto Done;
- case OANY: /* fallthrough */
- next = t->next;
- t->i = ci + 1;
- t->next = nil;
- *nlist->tail = t;
- nlist->tail = &t->next;
- goto Next;
+ if(r != ci->r) {+ Done:
+ next = t->next;
+ t->next = avail;
+ avail = t;
+ } else {+ case OANY:
+ ci++;
+ Switch:
+ next = t->next;
+ t->next = nil;
+ t->i = ci;
+ *nlist->tail = t;
+ nlist->tail = &t->next;
+ }
+ if(next == nil)
+ break;
+ if(matchgen && next->gen > matchgen) {+ *clist->tail = avail;
+ avail = next;
+ break;
+ }
+ t = next;
+ ci = t->i;
+ goto Again;
case OCLASS:
Class:
if(r < ci->r)
@@ -97,12 +118,8 @@
ci++;
goto Class;
}
- next = t->next;
- t->i = ci->a;
- t->next = nil;
- *nlist->tail = t;
- nlist->tail = &t->next;
- goto Next;
+ ci = ci->a;
+ goto Switch;
case ONOTNL:
if(r != L'\n') {ci++;
@@ -127,14 +144,15 @@
case OSPLIT:
if(avail == nil) {assert(pool < p->threads + p->nthr);
+ memset(pool, 0, sizeof(Rethread));
next = pool++;
} else {next = avail;
avail = avail->next;
}
- next->i = ci->b;
if(msize > 0)
memcpy(next->sem, t->sem, sizeof(Resub)*msize);
+ next->i = ci->b;
next->next = t->next;
next->gen = t->gen;
t->next = next;
@@ -157,21 +175,6 @@
if(ci->sub < msize)
t->sem[ci->sub].ep = sp;
ci++;
- goto Again;
- Done:
- next = t->next;
- t->next = avail;
- avail = t;
- Next:
- if(next == nil)
- break;
- if(matchgen && next->gen > matchgen) {- *clist->tail = avail;
- avail = next;
- break;
- }
- t = next;
- ci = t->i;
goto Again;
}
tmp = clist;
--- a/sys/src/libregexp/rregexec.c
+++ b/sys/src/libregexp/rregexec.c
@@ -18,7 +18,6 @@
Rune *rsp, *rep, endr, r;
int matchgen, gen;
- memset(p->threads, 0, sizeof(Rethread)*p->nthr);
if(msize > NSUBEXPM)
msize = NSUBEXPM;
if(p->startinst->gen != 0) {@@ -26,17 +25,6 @@
ci->gen = 0;
}
- clist = lists;
- clist->head = nil;
- clist->tail = &clist->head;
- nlist = lists + 1;
- nlist->head = nil;
- nlist->tail = &nlist->head;
-
- pool = p->threads;
- avail = nil;
- gen = matchgen = 0;
-
rsp = str;
rep = nil;
endr = L'\0';
@@ -50,6 +38,17 @@
}
}
+ avail = nil;
+ pool = p->threads;
+
+ clist = lists;
+ clist->head = nil;
+ clist->tail = &clist->head;
+ nlist = lists + 1;
+ nlist->head = nil;
+ nlist->tail = &nlist->head;
+
+ gen = matchgen = 0;
for(r = L'☺'; r != L'\0'; rsp++) {r = *rsp;
gen++;
@@ -56,14 +55,15 @@
if(matchgen == 0) { if(avail == nil) {assert(pool < p->threads + p->nthr);
+ memset(pool, 0, sizeof(Rethread));
t = pool++;
} else {+ if(msize > 0)
+ memset(avail->sem, 0, sizeof(Resub)*msize);
t = avail;
avail = avail->next;
}
t->i = p->startinst;
- if(msize > 0)
- memset(t->sem, 0, sizeof(Resub)*msize);
t->next = nil;
t->gen = gen;
*clist->tail = t;
@@ -78,16 +78,34 @@
goto Done;
ci->gen = gen;
switch(ci->op) {+ default:
+ abort();
case ORUNE:
- if(r != ci->r)
- goto Done;
- case OANY: /* fallthrough */
- next = t->next;
- t->i = ci + 1;
- t->next = nil;
- *nlist->tail = t;
- nlist->tail = &t->next;
- goto Next;
+ if(r != ci->r) {+ Done:
+ next = t->next;
+ t->next = avail;
+ avail = t;
+ } else {+ case OANY:
+ ci++;
+ Switch:
+ next = t->next;
+ t->next = nil;
+ t->i = ci;
+ *nlist->tail = t;
+ nlist->tail = &t->next;
+ }
+ if(next == nil)
+ break;
+ if(matchgen && next->gen > matchgen) {+ *clist->tail = avail;
+ avail = next;
+ break;
+ }
+ t = next;
+ ci = t->i;
+ goto Again;
case OCLASS:
Class:
if(r < ci->r)
@@ -96,12 +114,8 @@
ci++;
goto Class;
}
- next = t->next;
- t->i = ci->a;
- t->next = nil;
- *nlist->tail = t;
- nlist->tail = &t->next;
- goto Next;
+ ci = ci->a;
+ goto Switch;
case ONOTNL:
if(r != L'\n') {ci++;
@@ -126,14 +140,15 @@
case OSPLIT:
if(avail == nil) {assert(pool < p->threads + p->nthr);
+ memset(pool, 0, sizeof(Rethread));
next = pool++;
} else {next = avail;
avail = avail->next;
}
- next->i = ci->b;
if(msize > 0)
memcpy(next->sem, t->sem, sizeof(Resub)*msize);
+ next->i = ci->b;
next->next = t->next;
next->gen = t->gen;
t->next = next;
@@ -156,21 +171,6 @@
if(ci->sub < msize)
t->sem[ci->sub].rep = rsp;
ci++;
- goto Again;
- Done:
- next = t->next;
- t->next = avail;
- avail = t;
- Next:
- if(next == nil)
- break;
- if(matchgen && next->gen > matchgen) {- *clist->tail = avail;
- avail = next;
- break;
- }
- t = next;
- ci = t->i;
goto Again;
}
tmp = clist;
--
⑨