diff options
author | Rainer Gerhards <rgerhards@adiscon.com> | 2009-04-02 16:16:57 +0200 |
---|---|---|
committer | Rainer Gerhards <rgerhards@adiscon.com> | 2009-04-02 16:16:57 +0200 |
commit | a86e42028afeba1daca262b590bfd49d9c393b90 (patch) | |
tree | c9276d5a21fbe13b2c819137d705f696ea15ea1d /runtime | |
parent | eb807027af9e126a212b0630c5873dddae48963b (diff) | |
download | rsyslog-a86e42028afeba1daca262b590bfd49d9c393b90.tar.gz rsyslog-a86e42028afeba1daca262b590bfd49d9c393b90.tar.xz rsyslog-a86e42028afeba1daca262b590bfd49d9c393b90.zip |
improved performance of regexp-based filters
Thanks to Arnaud Cornet for providing the idea and initial patch.
Diffstat (limited to 'runtime')
-rw-r--r-- | runtime/stringbuf.c | 30 | ||||
-rw-r--r-- | runtime/stringbuf.h | 2 |
2 files changed, 32 insertions, 0 deletions
diff --git a/runtime/stringbuf.c b/runtime/stringbuf.c index a5dc625a..c0a19ae4 100644 --- a/runtime/stringbuf.c +++ b/runtime/stringbuf.c @@ -724,6 +724,36 @@ finalize_it: RETiRet; } +/* same as above, only not braindead */ +int rsCStrSzStrMatchRegexCache(cstr_t *pCS1, uchar *psz, void **rc) +{ + int ret; + + BEGINfunc + + if(objUse(regexp, LM_REGEXP_FILENAME) == RS_RET_OK) { + regex_t **cache = rc; + if (*cache == NULL) { + *cache = calloc(sizeof(regex_t), 1); + regexp.regcomp(*cache, (char*) rsCStrGetSzStr(pCS1), 0); + } + ret = regexp.regexec(*cache, (char*) psz, 0, NULL, 0); + } else { + ret = 1; /* simulate "not found" */ + } + + ENDfunc + return ret; +} + +/* free a cached compiled regex */ +void rsRegexDestruct(void **rc) { + regex_t **cache = rc; + regexp.regfree(*cache); + free(*cache); + *cache = NULL; +} + /* compare a rsCStr object with a classical sz string. This function * is almost identical to rsCStrZsStrCmp(), but it also takes an offset diff --git a/runtime/stringbuf.h b/runtime/stringbuf.h index f3e08439..4b0fb065 100644 --- a/runtime/stringbuf.h +++ b/runtime/stringbuf.h @@ -137,6 +137,8 @@ int rsCStrStartsWithSzStr(cstr_t *pCS1, uchar *psz, size_t iLenSz); int rsCStrCaseInsensitveStartsWithSzStr(cstr_t *pCS1, uchar *psz, size_t iLenSz); int rsCStrSzStrStartsWithCStr(cstr_t *pCS1, uchar *psz, size_t iLenSz); rsRetVal rsCStrSzStrMatchRegex(cstr_t *pCS1, uchar *psz, int iType); +int rsCStrSzStrMatchRegexCache(cstr_t *pCS1, uchar *psz, void **cache); +void rsRegexDestruct(void **rc); rsRetVal rsCStrConvertToNumber(cstr_t *pStr, number_t *pNumber); rsRetVal rsCStrConvertToBool(cstr_t *pStr, number_t *pBool); rsRetVal rsCStrAppendCStr(cstr_t *pThis, cstr_t *pstrAppend); |