Skip to content

Commit

Permalink
replace "int" usage by safer "Py_ssize_t" types to avoid unnecessary …
Browse files Browse the repository at this point in the history
…range limitations
  • Loading branch information
Stefan Behnel committed May 5, 2014
1 parent 049b728 commit 4cb8eb9
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 20 deletions.
22 changes: 11 additions & 11 deletions cytoolz/itertoolz.pxd
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,8 @@ cdef class interleave:
cdef list iters
cdef list newiters
cdef tuple pass_exceptions
cdef int i
cdef int n
cdef Py_ssize_t i
cdef Py_ssize_t n


cdef class _unique_key:
Expand All @@ -54,13 +54,13 @@ cpdef object isiterable(object x)
cpdef object isdistinct(object seq)


cpdef object take(int n, object seq)
cpdef object take(Py_ssize_t n, object seq)


cpdef object drop(int n, object seq)
cpdef object drop(Py_ssize_t n, object seq)


cpdef object take_nth(int n, object seq)
cpdef object take_nth(Py_ssize_t n, object seq)


cpdef object first(object seq)
Expand All @@ -69,7 +69,7 @@ cpdef object first(object seq)
cpdef object second(object seq)


cpdef object nth(int n, object seq)
cpdef object nth(Py_ssize_t n, object seq)


cpdef object last(object seq)
Expand Down Expand Up @@ -109,14 +109,14 @@ cdef class iterate:
cdef class sliding_window:
cdef object iterseq
cdef tuple prev
cdef int n
cdef Py_ssize_t n


cpdef object partition(int n, object seq, object pad=*)
cpdef object partition(Py_ssize_t n, object seq, object pad=*)


cdef class partition_all:
cdef int n
cdef Py_ssize_t n
cdef object iterseq


Expand All @@ -137,14 +137,14 @@ cdef class _pluck_index_default:
cdef class _pluck_list:
cdef list ind
cdef object iterseqs
cdef int n
cdef Py_ssize_t n


cdef class _pluck_list_default:
cdef list ind
cdef object iterseqs
cdef object default
cdef int n
cdef Py_ssize_t n


cpdef object pluck(object ind, object seqs, object default=*)
16 changes: 7 additions & 9 deletions cytoolz/itertoolz.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -439,7 +439,7 @@ cpdef object isdistinct(object seq):
return len(seq) == len(set(seq))


cpdef object take(int n, object seq):
cpdef object take(Py_ssize_t n, object seq):
"""
The first n elements of a sequence
Expand All @@ -449,7 +449,7 @@ cpdef object take(int n, object seq):
return islice(seq, n)


cpdef object drop(int n, object seq):
cpdef object drop(Py_ssize_t n, object seq):
"""
The sequence following the first n elements
Expand All @@ -458,20 +458,18 @@ cpdef object drop(int n, object seq):
"""
if n < 0:
raise ValueError('n argument for drop() must be non-negative')
cdef int i
cdef Py_ssize_t i
cdef object iter_seq
i = 0
iter_seq = iter(seq)
try:
while i < n:
i += 1
for i in range(n):
next(iter_seq)
except StopIteration:
pass
return iter_seq


cpdef object take_nth(int n, object seq):
cpdef object take_nth(Py_ssize_t n, object seq):
"""
Every nth item in seq
Expand Down Expand Up @@ -503,7 +501,7 @@ cpdef object second(object seq):
return next(seq)


cpdef object nth(int n, object seq):
cpdef object nth(Py_ssize_t n, object seq):
"""
The nth element in a sequence
Expand Down Expand Up @@ -858,7 +856,7 @@ cdef class sliding_window:
no_pad = '__no__pad__'


cpdef object partition(int n, object seq, object pad=no_pad):
cpdef object partition(Py_ssize_t n, object seq, object pad=no_pad):
"""
Partition sequence into tuples of length n
Expand Down

0 comments on commit 4cb8eb9

Please sign in to comment.