Skip to content

Commit

Permalink
Type open_http's nbytes as Py_ssize_t
Browse files Browse the repository at this point in the history
Python typically defines size values as `Py_ssize_t`. Leverage this with
`nbytes`. Also as `Py_ssize_t` is `signed` it can take negative values.
So pick make the `nbytes` default value `-1`. Update internal checks for
`nbytes` being passed similarly. This eliminates the overhead associated
with a Python object.
  • Loading branch information
jakirkham committed Oct 16, 2024
1 parent a34d6bf commit 1ce0902
Showing 1 changed file with 4 additions and 4 deletions.
8 changes: 4 additions & 4 deletions python/kvikio/kvikio/_lib/remote_handle.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

from typing import Optional

from cython cimport Py_ssize_t
from cython.operator cimport dereference as deref
from libc.stdint cimport uintptr_t
from libcpp.memory cimport make_unique, unique_ptr
Expand Down Expand Up @@ -56,17 +57,16 @@ cdef class RemoteFile:
def open_http(
cls,
url: str,
nbytes: Optional[int],
nbytes: Py_ssize_t = -1,
):
cdef RemoteFile ret = RemoteFile()
cdef unique_ptr[cpp_HttpEndpoint] ep = make_unique[cpp_HttpEndpoint](
_to_string(url)
)
if nbytes is None:
if nbytes >= 0:
ret._handle = make_unique[cpp_RemoteHandle](move(ep))
return ret
cdef size_t n = nbytes
ret._handle = make_unique[cpp_RemoteHandle](move(ep), n)
ret._handle = make_unique[cpp_RemoteHandle](move(ep), nbytes)
return ret

def nbytes(self) -> int:
Expand Down

0 comments on commit 1ce0902

Please sign in to comment.