summaryrefslogtreecommitdiff
path: root/lib/regex
diff options
context:
space:
mode:
authorOri Bernstein <ori@eigenstate.org>2017-12-27 22:04:40 -0800
committerOri Bernstein <ori@eigenstate.org>2017-12-27 22:04:40 -0800
commitc191c8825c094e3563094104b80df47c735c95fa (patch)
treea0935083c704b3251b0264e2f47b1f6107751f0b /lib/regex
parent17b6a133ca281986b0dfb9a1ced306e4fc99eb92 (diff)
downloadmc-c191c8825c094e3563094104b80df47c735c95fa.tar.gz
Limit the size of the thread cache.
And clean it up on exit.
Diffstat (limited to 'lib/regex')
-rw-r--r--lib/regex/interp.myr22
-rw-r--r--lib/regex/types.myr4
2 files changed, 18 insertions, 8 deletions
diff --git a/lib/regex/interp.myr b/lib/regex/interp.myr
index bb1eea0..c91b14f 100644
--- a/lib/regex/interp.myr
+++ b/lib/regex/interp.myr
@@ -22,6 +22,7 @@ pkg regex =
/* Ugly: for performance. std.option() should be used instead when unions get faster. */
const Zthr = (0 : rethread#)
+const Maxfree = 128
const exec = {re, str
var thr, m
@@ -164,13 +165,14 @@ const cleanup = {re
next = thr.next
thrfree(re, thr)
;;
- for thr = re.freed; thr != Zthr; thr = next
+ for thr = re.free; thr != Zthr; thr = next
next = thr.next
thrfree(re, thr)
;;
re.runq = Zthr
re.expired = Zthr
- re.freed = Zthr
+ re.free = Zthr
+ re.nfree = 0
re.nexttid = 0
re.nthr = 0
}
@@ -445,9 +447,10 @@ const finish = {re, thr
const mkthread = {re, ip
var thr : rethread#
- if re.freed != Zthr
- thr = re.freed
- re.freed = thr.next
+ if re.free != Zthr
+ thr = re.free
+ re.free = thr.next
+ re.nfree--
else
thr = std.alloc()
;;
@@ -462,8 +465,13 @@ const mkthread = {re, ip
}
const thrfree = {re, thr
- thr.next = re.freed
- re.freed = thr
+ if re.nfree >= Maxfree
+ std.free(thr)
+ else
+ thr.next = re.free
+ re.free = thr
+ re.nfree++
+ ;;
}
const within = {re, str
diff --git a/lib/regex/types.myr b/lib/regex/types.myr
index d06cfe1..75db777 100644
--- a/lib/regex/types.myr
+++ b/lib/regex/types.myr
@@ -23,7 +23,8 @@ pkg regex =
runq : rethread#
expired : rethread#
expiredtail : rethread#
- freed : rethread#
+ free : rethread#
+ nfree : std.size
proglen : std.size
prog : reinst[:]
nthr : std.size
@@ -72,6 +73,7 @@ pkg regex =
mgroup : std.size[2][32] /* match starts */
;;
+
pkglocal type reinst = union
/* direct consumers */
`Ibyte byte