From d624e014bcdf6f5833f0b34118c651ae2c4581e2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Zbigniew=20J=C4=99drzejewski-Szmek?= Date: Thu, 28 Jun 2012 10:58:09 +0200 Subject: Use PyString_AsStringAndSize to avoid strlen This should make the operation microscopically faster. A second difference is that strings with embedded NULLs will now be allowed, although I'm not really sure what is the impact of that change. --- journald.c | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) (limited to 'journald.c') diff --git a/journald.c b/journald.c index b106c52..1bd3889 100644 --- a/journald.c +++ b/journald.c @@ -16,15 +16,16 @@ journald_send(PyObject *self, PyObject *args) { // Iterate through the Python arguments and fill the iovector. for (i = 0; i < argc; ++i) { PyObject *item = PyTuple_GetItem(args, i); - char * stritem = PyString_AsString(item); - if (stritem == NULL) { - // PyString_AsString has already raised TypeError at this + char *stritem; + Py_ssize_t length; + if (PyString_AsStringAndSize(item, &stritem, &length)) { + // PyString_AsS&S has already raised TypeError at this // point. We can just free iov and return NULL. free(iov); return NULL; } iov[i].iov_base = stritem; - iov[i].iov_len = strlen(stritem); + iov[i].iov_len = length; } // Send the iovector to journald. -- cgit v1.2.1