From 158600b15c1850024b456c1c600bd9961d99315c Mon Sep 17 00:00:00 2001 From: Sean Pringle Date: Wed, 31 Dec 2014 14:18:46 +1000 Subject: [PATCH] do not hold regex memory after config --- config.c | 4 ++++ regex.c | 32 ++++++++------------------------ 2 files changed, 12 insertions(+), 24 deletions(-) diff --git a/config.c b/config.c index 44a19c6..0e6275c 100644 --- a/config.c +++ b/config.c @@ -68,6 +68,8 @@ configure() char tmp[1024]; const char *home = getenv("HOME"); + regex_cache_init(); + settings.border = BORDER; settings.border_blur = strdup(BORDER_BLUR); settings.border_focus = strdup(BORDER_FOCUS); @@ -428,5 +430,7 @@ configure() } } fclose(file); + + regex_cache_empty(); } } diff --git a/regex.c b/regex.c index 96ffefc..4579cd8 100644 --- a/regex.c +++ b/regex.c @@ -35,6 +35,7 @@ typedef struct { } RegexCache; RegexCache regex_cache[REGEX_CACHE]; +char *regex_matches[REGEX_GROUPS]; regex_t* regex(const char *pattern) @@ -115,7 +116,13 @@ regex(const char *pattern) } void -flush_regex_cache() +regex_cache_init() +{ + memset(regex_cache, 0, sizeof(regex_cache)); +} + +void +regex_cache_empty() { for (int i = 0; i < REGEX_CACHE; i++) { @@ -131,8 +138,6 @@ flush_regex_cache() } } -char *regex_matches[REGEX_GROUPS]; - int regex_match(const char *pattern, const char *subject) { @@ -151,24 +156,3 @@ regex_match(const char *pattern, const char *subject) } return r; } - -int -regex_split(char *pattern, char **subject) -{ - int r = 0; regmatch_t pmatch; - regex_t *re = regex(pattern); - if (re && *subject) - { - r = regexec(re, *subject, 1, &pmatch, 0) == 0 ?-1:0; - if (r) - { - memset(*subject + pmatch.rm_so, 0, pmatch.rm_eo - pmatch.rm_so); - *subject += pmatch.rm_eo; - } - else - { - *subject += strlen(*subject); - } - } - return r; -}