summaryrefslogtreecommitdiff
path: root/jq.pyx
diff options
context:
space:
mode:
authorNikolai Kondrashov <Nikolai.Kondrashov@redhat.com>2020-09-09 17:31:08 +0300
committerMichael Williamson <mike@zwobble.org>2024-06-08 12:13:35 +0100
commitfe19d174b69325d6791e4871f1077e17d9085cbf (patch)
tree8873926f76d4db596ed330a73c8bf851a4786cef /jq.pyx
parent3fa4e4a462b57a480fb2036b1e1e599a2cad83b3 (diff)
Use PyBytes_AsStringAndSize()
Let Python give us the length of the "bytes" it already knows, instead of doing an strlen(). This improves performance a bit.
Diffstat (limited to 'jq.pyx')
-rw-r--r--jq.pyx7
1 files changed, 5 insertions, 2 deletions
diff --git a/jq.pyx b/jq.pyx
index 0f580c4..f42efdf 100644
--- a/jq.pyx
+++ b/jq.pyx
@@ -3,6 +3,7 @@ import json
import threading
from cpython.bytes cimport PyBytes_AsString
+from cpython.bytes cimport PyBytes_AsStringAndSize
from libc.float cimport DBL_MAX
from libc.math cimport INFINITY, modf
@@ -335,8 +336,10 @@ cdef class _ResultIterator(object):
self._slurp = slurp
self._ready = False
cdef jv_parser* parser = jv_parser_new(0)
- cdef char* cbytes_input = PyBytes_AsString(bytes_input)
- jv_parser_set_buf(parser, cbytes_input, len(bytes_input), 0)
+ cdef char* cbytes_input
+ cdef ssize_t clen_input
+ PyBytes_AsStringAndSize(bytes_input, &cbytes_input, &clen_input)
+ jv_parser_set_buf(parser, cbytes_input, clen_input, 0)
self._parser = parser
def __iter__(self):