Skip to content

Commit 3580e9d

Browse files
committed
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.
1 parent ed88d05 commit 3580e9d

File tree

1 file changed

+5
-2
lines changed

1 file changed

+5
-2
lines changed

jq.pyx

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import json
33
import threading
44

55
from cpython.bytes cimport PyBytes_AsString
6+
from cpython.bytes cimport PyBytes_AsStringAndSize
67
from libc.float cimport DBL_MAX
78
from libc.math cimport INFINITY, modf
89

@@ -335,8 +336,10 @@ cdef class _ResultIterator(object):
335336
self._slurp = slurp
336337
self._ready = False
337338
cdef jv_parser* parser = jv_parser_new(0)
338-
cdef char* cbytes_input = PyBytes_AsString(bytes_input)
339-
jv_parser_set_buf(parser, cbytes_input, len(bytes_input), 0)
339+
cdef char* cbytes_input
340+
cdef ssize_t clen_input
341+
PyBytes_AsStringAndSize(bytes_input, &cbytes_input, &clen_input)
342+
jv_parser_set_buf(parser, cbytes_input, clen_input, 0)
340343
self._parser = parser
341344

342345
def __iter__(self):

0 commit comments

Comments
 (0)