Commit d5e107a9 authored by gabrieldemarmiesse's avatar gabrieldemarmiesse

Refactoring of the extend function to make it simpler.

parent b9f7a142
......@@ -38,11 +38,9 @@ cdef class Queue:
self.append(value)
cdef extend_ints(self, int* values, size_t count):
cdef size_t i
for i in range(count):
if not cqueue.queue_push_tail(
self._c_queue, <void*> values[i]):
raise MemoryError()
cdef int value
for value in values[:count]: # It is possible to slice pointers in Cython.
self.append(value)
cpdef int peek(self) except? -1:
cdef int value = <Py_ssize_t> cqueue.queue_peek_head(self._c_queue)
......
......@@ -342,11 +342,9 @@ Adding an ``extend()`` method should now be straight forward::
cdef extend(self, int* values, size_t count):
"""Append all ints to the queue.
"""
cdef size_t i
for i in range(count):
if not cqueue.queue_push_tail(
self._c_queue, <void*>values[i]):
raise MemoryError()
cdef int value
for value in values[:count]: # It is possible to slice pointers in Cython.
self.append(value)
This becomes handy when reading values from a C array, for example.
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment