diff options
author | Zbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl> | 2012-06-28 10:58:09 +0200 |
---|---|---|
committer | Zbyszek Jędrzejewski-Szmek <zbyszek@in.waw.pl> | 2012-07-10 10:26:33 +0200 |
commit | d624e014bcdf6f5833f0b34118c651ae2c4581e2 (patch) | |
tree | 5dc0bf6ba4891c70d95bf0eae0ec70b668bb8210 /journald.c | |
parent | 78a234c6d3b82775a41c866b3a242d7829851b63 (diff) | |
download | python-systemd-d624e014bcdf6f5833f0b34118c651ae2c4581e2.tar.gz |
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.
Diffstat (limited to 'journald.c')
-rw-r--r-- | journald.c | 9 |
1 files changed, 5 insertions, 4 deletions
@@ -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. |