Skip to content

Commit

Permalink
Use PyBytes_AsStringAndSize()
Browse files Browse the repository at this point in the history
Let Python give us the length of the "bytes" it already knows, instead
of doing an strlen(). This improves performance a bit.
  • Loading branch information
spbnick committed May 17, 2024
1 parent ed88d05 commit 3580e9d
Showing 1 changed file with 5 additions and 2 deletions.
7 changes: 5 additions & 2 deletions jq.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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):
Expand Down

0 comments on commit 3580e9d

Please sign in to comment.