equal
deleted
inserted
replaced
410 return NULL; |
410 return NULL; |
411 |
411 |
412 Py_RETURN_NONE; |
412 Py_RETURN_NONE; |
413 } |
413 } |
414 |
414 |
|
415 static void _index_clearcaches(indexObject *self) |
|
416 { |
|
417 if (self->cache) { |
|
418 Py_ssize_t i; |
|
419 |
|
420 for (i = 0; i < self->raw_length; i++) { |
|
421 Py_XDECREF(self->cache[i]); |
|
422 self->cache[i] = NULL; |
|
423 } |
|
424 free(self->cache); |
|
425 self->cache = NULL; |
|
426 } |
|
427 if (self->offsets) { |
|
428 free(self->offsets); |
|
429 self->offsets = NULL; |
|
430 } |
|
431 } |
|
432 |
|
433 static PyObject *index_clearcaches(indexObject *self) |
|
434 { |
|
435 _index_clearcaches(self); |
|
436 Py_RETURN_NONE; |
|
437 } |
|
438 |
415 static int index_assign_subscript(indexObject *self, PyObject *item, |
439 static int index_assign_subscript(indexObject *self, PyObject *item, |
416 PyObject *value) |
440 PyObject *value) |
417 { |
441 { |
418 Py_ssize_t start, stop, step, slicelength; |
442 Py_ssize_t start, stop, step, slicelength; |
419 Py_ssize_t length = index_length(self); |
443 Py_ssize_t length = index_length(self); |
544 PyTuple_GET_ITEM(args, 0)); |
568 PyTuple_GET_ITEM(args, 0)); |
545 } |
569 } |
546 |
570 |
547 static void index_dealloc(indexObject *self) |
571 static void index_dealloc(indexObject *self) |
548 { |
572 { |
|
573 _index_clearcaches(self); |
549 Py_DECREF(self->data); |
574 Py_DECREF(self->data); |
550 if (self->cache) { |
|
551 Py_ssize_t i; |
|
552 |
|
553 for (i = 0; i < self->raw_length; i++) |
|
554 Py_XDECREF(self->cache[i]); |
|
555 } |
|
556 Py_XDECREF(self->added); |
575 Py_XDECREF(self->added); |
557 free(self->offsets); |
|
558 PyObject_Del(self); |
576 PyObject_Del(self); |
559 } |
577 } |
560 |
578 |
561 static PySequenceMethods index_sequence_methods = { |
579 static PySequenceMethods index_sequence_methods = { |
562 (lenfunc)index_length, /* sq_length */ |
580 (lenfunc)index_length, /* sq_length */ |
570 NULL, /* mp_subscript */ |
588 NULL, /* mp_subscript */ |
571 (objobjargproc)index_assign_subscript, /* mp_ass_subscript */ |
589 (objobjargproc)index_assign_subscript, /* mp_ass_subscript */ |
572 }; |
590 }; |
573 |
591 |
574 static PyMethodDef index_methods[] = { |
592 static PyMethodDef index_methods[] = { |
|
593 {"clearcaches", (PyCFunction)index_clearcaches, METH_NOARGS, |
|
594 "clear the index caches"}, |
575 {"insert", (PyCFunction)index_insert, METH_VARARGS, |
595 {"insert", (PyCFunction)index_insert, METH_VARARGS, |
576 "insert an index entry"}, |
596 "insert an index entry"}, |
577 {NULL} /* Sentinel */ |
597 {NULL} /* Sentinel */ |
578 }; |
598 }; |
579 |
599 |