do not hold regex memory after config
This commit is contained in:
4
config.c
4
config.c
@@ -68,6 +68,8 @@ configure()
|
|||||||
char tmp[1024];
|
char tmp[1024];
|
||||||
const char *home = getenv("HOME");
|
const char *home = getenv("HOME");
|
||||||
|
|
||||||
|
regex_cache_init();
|
||||||
|
|
||||||
settings.border = BORDER;
|
settings.border = BORDER;
|
||||||
settings.border_blur = strdup(BORDER_BLUR);
|
settings.border_blur = strdup(BORDER_BLUR);
|
||||||
settings.border_focus = strdup(BORDER_FOCUS);
|
settings.border_focus = strdup(BORDER_FOCUS);
|
||||||
@@ -428,5 +430,7 @@ configure()
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
fclose(file);
|
fclose(file);
|
||||||
|
|
||||||
|
regex_cache_empty();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
32
regex.c
32
regex.c
@@ -35,6 +35,7 @@ typedef struct {
|
|||||||
} RegexCache;
|
} RegexCache;
|
||||||
|
|
||||||
RegexCache regex_cache[REGEX_CACHE];
|
RegexCache regex_cache[REGEX_CACHE];
|
||||||
|
char *regex_matches[REGEX_GROUPS];
|
||||||
|
|
||||||
regex_t*
|
regex_t*
|
||||||
regex(const char *pattern)
|
regex(const char *pattern)
|
||||||
@@ -115,7 +116,13 @@ regex(const char *pattern)
|
|||||||
}
|
}
|
||||||
|
|
||||||
void
|
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++)
|
for (int i = 0; i < REGEX_CACHE; i++)
|
||||||
{
|
{
|
||||||
@@ -131,8 +138,6 @@ flush_regex_cache()
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
char *regex_matches[REGEX_GROUPS];
|
|
||||||
|
|
||||||
int
|
int
|
||||||
regex_match(const char *pattern, const char *subject)
|
regex_match(const char *pattern, const char *subject)
|
||||||
{
|
{
|
||||||
@@ -151,24 +156,3 @@ regex_match(const char *pattern, const char *subject)
|
|||||||
}
|
}
|
||||||
return r;
|
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;
|
|
||||||
}
|
|
||||||
|
|||||||
Reference in New Issue
Block a user