/* Advance left block/index pair */
leftindex++;
if (leftindex == BLOCKLEN) {
- assert (leftblock->rightlink != NULL);
+ if (leftblock->rightlink == NULL)
+ break;
leftblock = leftblock->rightlink;
leftindex = 0;
}
/* Step backwards with the right block/index pair */
rightindex--;
if (rightindex == -1) {
- assert (rightblock->leftlink != NULL);
+ if (rightblock->leftlink == NULL)
+ break;
rightblock = rightblock->leftlink;
rightindex = BLOCKLEN - 1;
}
{
block *leftblock = deque->leftblock;
Py_ssize_t leftindex = deque->leftindex;
- Py_ssize_t n = (deque->len);
+ Py_ssize_t n = deque->len;
Py_ssize_t i;
Py_ssize_t count = 0;
PyObject *item;
/* Advance left block/index pair */
leftindex++;
if (leftindex == BLOCKLEN) {
- assert (leftblock->rightlink != NULL);
+ if (leftblock->rightlink == NULL) /* can occur when i==n-1 */
+ break;
leftblock = leftblock->rightlink;
leftindex = 0;
}
PyDoc_STRVAR(deque_doc,
"deque(iterable[, maxlen]) --> deque object\n\
\n\
-Build an ordered collection accessible from endpoints only.");
+Build an ordered collection with optimized access from its endpoints.");
static PyTypeObject deque_type = {
PyVarObject_HEAD_INIT(NULL, 0)
{
int status = Py_ReprEnter(dd->default_factory);
if (status != 0) {
- if (status < 0)
+ if (status < 0) {
+ Py_DECREF(baserepr);
return NULL;
+ }
defrepr = PyString_FromString("...");
}
else