summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorRainer Gerhards <rgerhards@adiscon.com>2009-06-26 14:22:00 +0200
committerRainer Gerhards <rgerhards@adiscon.com>2009-06-26 14:22:00 +0200
commit1f361c5eb9028e7750a1c84811c9c3ac5cdd0a31 (patch)
tree3856e590007aeb16bc251bd2256b55669113fd52
parent6be06d50e328c4b8c79b263e176e6b4e384a03f9 (diff)
downloadrsyslog-1f361c5eb9028e7750a1c84811c9c3ac5cdd0a31.tar.gz
rsyslog-1f361c5eb9028e7750a1c84811c9c3ac5cdd0a31.tar.xz
rsyslog-1f361c5eb9028e7750a1c84811c9c3ac5cdd0a31.zip
some optimization, declared some frequently called small stringbuf functions inline
-rw-r--r--runtime/stringbuf.c57
-rw-r--r--runtime/stringbuf.h65
2 files changed, 62 insertions, 60 deletions
diff --git a/runtime/stringbuf.c b/runtime/stringbuf.c
index f3824831..88f5a3a2 100644
--- a/runtime/stringbuf.c
+++ b/runtime/stringbuf.c
@@ -343,42 +343,6 @@ uchar* rsCStrGetSzStr(cstr_t *pThis)
}
-/* Converts the CStr object to a classical sz string and returns that.
- * Same restrictions as in cstrGetSzStr() applies (see there!). This
- * function here guarantees that a valid string is returned, even if
- * the CStr object currently holds a NULL pointer string buffer. If so,
- * "" is returned.
- * rgerhards 2005-10-19
- * WARNING: The returned pointer MUST NOT be freed, as it may be
- * obtained from that constant memory pool (in case of NULL!)
- */
-uchar* cstrGetSzStrNoNULL(cstr_t *pThis)
-{
- rsCHECKVALIDOBJECT(pThis, OIDrsCStr);
- if(pThis->pBuf == NULL)
- return (uchar*) "";
- else
- return cstrGetSzStr(pThis);
-}
-
-/* Returns the cstr data as a classical C sz string. We use that the
- * Finalizer did properly terminate our string (but we may stil be NULL).
- * So it is vital that the finalizer is called BEFORe this function here!
- * The caller must not free or otherwise manipulate the returned string and must not
- * destroy the CStr object as long as the ascii string is used.
- * This function may return NULL, if the string is currently NULL. This
- * is a feature, not a bug. If you need non-NULL in any case, use
- * cstrGetSzStrNoNULL() instead.
- * Note that due to the new single-buffer interface this function almost does nothing!
- * rgerhards, 2006-09-16
- */
-uchar* cstrGetSzStr(cstr_t *pThis)
-{
- rsCHECKVALIDOBJECT(pThis, OIDrsCStr);
- return(pThis->pBuf);
-}
-
-
/* Converts the CStr object to a classical zero-terminated C string,
* returns that string and destroys the CStr object. The returned string
* MUST be freed by the caller. The function might return NULL if
@@ -426,27 +390,6 @@ finalize_it:
}
-/* Finalize the string object. This must be called after all data is added to it
- * but before that data is used.
- * rgerhards, 2009-06-16
- */
-rsRetVal
-cstrFinalize(cstr_t *pThis)
-{
- DEFiRet;
- rsCHECKVALIDOBJECT(pThis, OIDrsCStr);
-
- if(pThis->iStrLen > 0) {
- /* terminate string only if one exists */
- CHKiRet(cstrAppendChar(pThis, '\0'));
- --pThis->iStrLen; /* do NOT count the \0 byte */
- }
-
-finalize_it:
- RETiRet;
-}
-
-
/* return the length of the current string
* 2005-09-09 rgerhards
* Please note: this is only a function in a debug build.
diff --git a/runtime/stringbuf.h b/runtime/stringbuf.h
index 4fbd9a9b..86c7e943 100644
--- a/runtime/stringbuf.h
+++ b/runtime/stringbuf.h
@@ -74,7 +74,7 @@ void rsCStrDestruct(cstr_t **ppThis);
rsRetVal rsCStrExtendBuf(cstr_t *pThis, size_t iMinNeeded); /* our helper, NOT a public interface! */
static inline rsRetVal cstrAppendChar(cstr_t *pThis, uchar c)
{
- rsRetVal iRet;
+ rsRetVal iRet = RS_RET_OK;
rsCHECKVALIDOBJECT(pThis, OIDrsCStr);
@@ -89,6 +89,67 @@ finalize_it:
return iRet;
}
+
+/* some inline functions for things that are really frequently called... */
+
+/* Finalize the string object. This must be called after all data is added to it
+ * but before that data is used.
+ * rgerhards, 2009-06-16
+ */
+static inline rsRetVal
+cstrFinalize(cstr_t *pThis)
+{
+ rsRetVal iRet = RS_RET_OK;
+ rsCHECKVALIDOBJECT(pThis, OIDrsCStr);
+
+ if(pThis->iStrLen > 0) {
+ /* terminate string only if one exists */
+ CHKiRet(cstrAppendChar(pThis, '\0'));
+ --pThis->iStrLen; /* do NOT count the \0 byte */
+ }
+
+finalize_it:
+ return iRet;
+}
+
+
+/* Returns the cstr data as a classical C sz string. We use that the
+ * Finalizer did properly terminate our string (but we may stil be NULL).
+ * So it is vital that the finalizer is called BEFORe this function here!
+ * The caller must not free or otherwise manipulate the returned string and must not
+ * destroy the CStr object as long as the ascii string is used.
+ * This function may return NULL, if the string is currently NULL. This
+ * is a feature, not a bug. If you need non-NULL in any case, use
+ * cstrGetSzStrNoNULL() instead.
+ * Note that due to the new single-buffer interface this function almost does nothing!
+ * rgerhards, 2006-09-16
+ */
+static inline uchar* cstrGetSzStr(cstr_t *pThis)
+{
+ rsCHECKVALIDOBJECT(pThis, OIDrsCStr);
+ return(pThis->pBuf);
+}
+
+
+/* Converts the CStr object to a classical sz string and returns that.
+ * Same restrictions as in cstrGetSzStr() applies (see there!). This
+ * function here guarantees that a valid string is returned, even if
+ * the CStr object currently holds a NULL pointer string buffer. If so,
+ * "" is returned.
+ * rgerhards 2005-10-19
+ * WARNING: The returned pointer MUST NOT be freed, as it may be
+ * obtained from that constant memory pool (in case of NULL!)
+ */
+static inline uchar* cstrGetSzStrNoNULL(cstr_t *pThis)
+{
+ rsCHECKVALIDOBJECT(pThis, OIDrsCStr);
+ if(pThis->pBuf == NULL)
+ return (uchar*) "";
+ else
+ return cstrGetSzStr(pThis);
+}
+
+
/**
* Truncate "n" number of characters from the end of the
* string. The buffer remains unchanged, just the
@@ -148,8 +209,6 @@ rsRetVal rsCStrConvertToBool(cstr_t *pStr, number_t *pBool);
/* new calling interface */
rsRetVal cstrFinalize(cstr_t *pThis);
rsRetVal cstrConvSzStrAndDestruct(cstr_t *pThis, uchar **ppSz, int bRetNULL);
-uchar* cstrGetSzStr(cstr_t *pThis);
-uchar* cstrGetSzStrNoNULL(cstr_t *pThis);
rsRetVal cstrAppendCStr(cstr_t *pThis, cstr_t *pstrAppend);
/* now come inline-like functions */