Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
579 changes: 579 additions & 0 deletions benchmarks/decode_benchmark.py

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions cassandra/bytesio.pxd
Original file line number Diff line number Diff line change
Expand Up @@ -17,4 +17,5 @@ cdef class BytesIOReader:
cdef char *buf_ptr
cdef Py_ssize_t pos
cdef Py_ssize_t size
cdef Py_ssize_t _initial_offset
cdef char *read(self, Py_ssize_t n = ?) except NULL
12 changes: 9 additions & 3 deletions cassandra/bytesio.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,18 @@ cdef class BytesIOReader:
"""
This class provides efficient support for reading bytes from a 'bytes' buffer,
by returning char * values directly without allocating intermediate objects.

An optional offset allows reading from the middle of an existing buffer,
avoiding a copy when only a suffix of the bytes is needed.
"""

def __init__(self, bytes buf):
def __init__(self, bytes buf, Py_ssize_t offset=0):
if offset < 0 or offset > len(buf):
raise ValueError("offset %d out of range for buffer of length %d" % (offset, len(buf)))
self.buf = buf
self.size = len(buf)
self.buf_ptr = self.buf
self._initial_offset = offset
self.size = len(buf) - offset
self.buf_ptr = <char*>self.buf + offset

cdef char *read(self, Py_ssize_t n = -1) except NULL:
"""Read at most size bytes from the file
Expand Down
Loading
Loading