summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJakob Kaivo <jkk@ung.org>2022-04-25 19:33:05 -0400
committerJakob Kaivo <jkk@ung.org>2022-04-25 19:33:05 -0400
commit0c72419d193ca13edc8302cd8c151bbe80a4716f (patch)
tree650e3d9994c06336930f959c62fc89055661ed35
parent341c8545ca2e2b1af908af506d0e472d68327593 (diff)
only compile the regex once
-rw-r--r--includes.c17
1 files changed, 8 insertions, 9 deletions
diff --git a/includes.c b/includes.c
index 103c8fd..cbef99a 100644
--- a/includes.c
+++ b/includes.c
@@ -51,19 +51,18 @@ static struct majefile * find_inc(const struct majefile *file, const regex_t * r
struct majefile *find_includes(const struct majefile *source)
{
- regex_t re;
- int rc = regcomp(&re,
- "#[[:space:]]*include[[:space:]]+.*\"(.*)\"",
- REG_EXTENDED | REG_NEWLINE);
- if (rc != 0) {
- fprintf(stderr, "maje: regcomp() failed\n");
- abort();
+ static regex_t re = { .re_nsub = (size_t)-1 };
+ if (re.re_nsub == (size_t)-1) {
+ if (regcomp(&re,
+ "#[[:space:]]*include[[:space:]]+.*\"(.*)\"",
+ REG_EXTENDED | REG_NEWLINE) != 0) {
+ fprintf(stderr, "maje: regcomp(#include) failed\n");
+ abort();
+ }
}
struct majefile *ret = find_inc(source, &re);
- regfree(&re);
-
if (ret != NULL) {
while (ret->prev != NULL) {
ret = ret->prev;