summaryrefslogtreecommitdiffstats
path: root/runtime/stringbuf.c
diff options
context:
space:
mode:
authorRainer Gerhards <rgerhards@adiscon.com>2009-04-02 17:54:48 +0200
committerRainer Gerhards <rgerhards@adiscon.com>2009-04-02 17:54:48 +0200
commit4ab540e3ba25a13fd079490ac52438e55dc92672 (patch)
tree14586687d81fa45ecadfebb54e3e05b0e8b43716 /runtime/stringbuf.c
parent1d16216aa326296673cc8520a8df351c4d492dfe (diff)
downloadrsyslog-4ab540e3ba25a13fd079490ac52438e55dc92672.tar.gz
rsyslog-4ab540e3ba25a13fd079490ac52438e55dc92672.tar.xz
rsyslog-4ab540e3ba25a13fd079490ac52438e55dc92672.zip
fully integrated regex patch
Now have removed the previous method, as really nobody should call it any longer (and now nobody does ;)). Also did some other cleanup.
Diffstat (limited to 'runtime/stringbuf.c')
-rw-r--r--runtime/stringbuf.c41
1 files changed, 13 insertions, 28 deletions
diff --git a/runtime/stringbuf.c b/runtime/stringbuf.c
index 4a7cc4bd..35ec44c6 100644
--- a/runtime/stringbuf.c
+++ b/runtime/stringbuf.c
@@ -703,49 +703,34 @@ int rsCStrCaseInsensitveStartsWithSzStr(cstr_t *pCS1, uchar *psz, size_t iLenSz)
* never is a \0 *inside* a property string.
* Note that the function returns -1 if regexp functionality is not available.
* rgerhards: 2009-03-04: ERE support added, via parameter iType: 0 - BRE, 1 - ERE
+ * Arnaud Cornet/rgerhards: 2009-04-02: performance improvement by caching compiled regex
+ * If a caller does not need the cached version, it must still provide memory for it
+ * and must call rsCStrRegexDestruct() afterwards.
*/
-rsRetVal rsCStrSzStrMatchRegex(cstr_t *pCS1, uchar *psz, int iType)
+rsRetVal rsCStrSzStrMatchRegex(cstr_t *pCS1, uchar *psz, int iType, void *rc)
{
- regex_t preq;
+ regex_t **cache = (regex_t**) rc;
int ret;
DEFiRet;
- if(objUse(regexp, LM_REGEXP_FILENAME) == RS_RET_OK) {
- regexp.regcomp(&preq, (char*) rsCStrGetSzStr(pCS1), (iType == 1 ? REG_EXTENDED : 0) | REG_NOSUB);
- ret = regexp.regexec(&preq, (char*) psz, 0, NULL, 0);
- regexp.regfree(&preq);
- if(ret != 0)
- ABORT_FINALIZE(RS_RET_NOT_FOUND);
- } else {
- ABORT_FINALIZE(RS_RET_NOT_FOUND);
- }
-
-finalize_it:
- RETiRet;
-}
-
-/* same as above, only not braindead */
-int rsCStrSzStrMatchRegexCache(cstr_t *pCS1, uchar *psz, void *rc)
-{
- int ret;
- regex_t **cache = (regex_t**) rc;
-
- BEGINfunc
-
+ assert(pCS1 != NULL);
+ assert(psz != NULL);
assert(cache != NULL);
if(objUse(regexp, LM_REGEXP_FILENAME) == RS_RET_OK) {
if (*cache == NULL) {
*cache = calloc(sizeof(regex_t), 1);
- regexp.regcomp(*cache, (char*) rsCStrGetSzStr(pCS1), 0);
+ regexp.regcomp(*cache, (char*) rsCStrGetSzStr(pCS1), (iType == 1 ? REG_EXTENDED : 0) | REG_NOSUB);
}
ret = regexp.regexec(*cache, (char*) psz, 0, NULL, 0);
+ if(ret != 0)
+ ABORT_FINALIZE(RS_RET_NOT_FOUND);
} else {
- ret = 1; /* simulate "not found" */
+ ABORT_FINALIZE(RS_RET_NOT_FOUND);
}
- ENDfunc
- return ret;
+finalize_it:
+ RETiRet;
}