summaryrefslogtreecommitdiffstats
path: root/runtime/parser.c
diff options
context:
space:
mode:
authorRainer Gerhards <rgerhards@adiscon.com>2009-06-16 11:36:05 +0200
committerRainer Gerhards <rgerhards@adiscon.com>2009-06-16 11:36:05 +0200
commitf7579e68a67364c8040966be57c2eae4c9550ee5 (patch)
treeb0e0eb7e54f6fb5db3b6600d0f3fe72a4a0f271e /runtime/parser.c
parent015d17ca70e81ad998e32cdfeed3cd925fd7dedc (diff)
downloadrsyslog-f7579e68a67364c8040966be57c2eae4c9550ee5.tar.gz
rsyslog-f7579e68a67364c8040966be57c2eae4c9550ee5.tar.xz
rsyslog-f7579e68a67364c8040966be57c2eae4c9550ee5.zip
done various optimizations to the stringbuf and its users
Diffstat (limited to 'runtime/parser.c')
-rw-r--r--runtime/parser.c19
1 files changed, 18 insertions, 1 deletions
diff --git a/runtime/parser.c b/runtime/parser.c
index 64e03094..13fb51ec 100644
--- a/runtime/parser.c
+++ b/runtime/parser.c
@@ -205,8 +205,16 @@ sanitizeMessage(msg_t *pMsg)
}
}
}
- if(bNeedSanitize == 0)
+ if(bNeedSanitize == 0) {
+ /* what a shame - we do not have a \0 byte...
+ * TODO: think about adding it or otherwise be able to use it...
+ */
+ uchar *pRaw;
+ CHKmalloc(pRaw = realloc(pMsg->pszRawMsg, pMsg->iLenRawMsg + 1));
+ pRaw[pMsg->iLenRawMsg] = '\0';
+ pMsg->pszRawMsg = pRaw;
FINALIZE;
+ }
/* now copy over the message and sanitize it */
/* TODO: can we get cheaper memory alloc? {alloca()?}*/
@@ -276,6 +284,7 @@ rsRetVal parseMsg(msg_t *pMsg)
DEFiRet;
uchar *msg;
int pri;
+ int iPriText;
CHKiRet(sanitizeMessage(pMsg));
@@ -285,11 +294,19 @@ rsRetVal parseMsg(msg_t *pMsg)
/* pull PRI */
pri = DEFUPRI;
msg = pMsg->pszRawMsg;
+ iPriText = 0;
if(*msg == '<') {
+ /* while we process the PRI, we also fill the PRI textual representation
+ * inside the msg object. This may not be ideal from an OOP point of view,
+ * but it offers us performance...
+ */
pri = 0;
while(isdigit((int) *++msg)) {
+ pMsg->bufPRI[iPriText++ % 4] = *msg; /* mod 4 to guard against malformed messages! */
pri = 10 * pri + (*msg - '0');
}
+ pMsg->bufPRI[iPriText % 4] = '\0';
+ pMsg->iLenPRI = iPriText % 4;
if(*msg == '>')
++msg;
if(pri & ~(LOG_FACMASK|LOG_PRIMASK))