| LEFT | RIGHT |
| 1 /* Range object implementation */ | 1 /* Range object implementation */ |
| 2 | 2 |
| 3 #include "Python.h" | 3 #include "Python.h" |
| 4 #include "structmember.h" | 4 #include "structmember.h" |
| 5 | 5 |
| 6 /* Support objects whose length is > PY_SSIZE_T_MAX. | 6 /* Support objects whose length is > PY_SSIZE_T_MAX. |
| 7 | 7 |
| 8 This could be sped up for small PyLongs if they fit in an Py_ssize_t. | 8 This could be sped up for small PyLongs if they fit in an Py_ssize_t. |
| 9 This only matters on Win64. Though we could use PY_LONG_LONG which | 9 This only matters on Win64. Though we could use PY_LONG_LONG which |
| 10 would presumably help perf. | 10 would presumably help perf. |
| (...skipping 104 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 115 static void | 115 static void |
| 116 range_dealloc(rangeobject *r) | 116 range_dealloc(rangeobject *r) |
| 117 { | 117 { |
| 118 Py_DECREF(r->start); | 118 Py_DECREF(r->start); |
| 119 Py_DECREF(r->stop); | 119 Py_DECREF(r->stop); |
| 120 Py_DECREF(r->step); | 120 Py_DECREF(r->step); |
| 121 Py_DECREF(r->length); | 121 Py_DECREF(r->length); |
| 122 PyObject_Del(r); | 122 PyObject_Del(r); |
| 123 } | 123 } |
| 124 | 124 |
| 125 /*Return number of items in range (lo, hi, step), when arguments are |
| 126 * PyLong objects. step > 0 required. Return a PyLong with the length. |
| 127 * Return NULL when there is an error.*/ |
| 125 static PyObject * | 128 static PyObject * |
| 126 range_compute_length(PyObject *start, PyObject *stop, PyObject *step) | 129 range_compute_length(PyObject *start, PyObject *stop, PyObject *step) |
| 127 { | 130 { |
| 128 /* ------------------------------------------------------------- | 131 /* ------------------------------------------------------------- |
| 129 Algorithm is equal to that of get_len_of_range(), but it operates | 132 Algorithm is equal to that of get_len_of_range(), but it operates |
| 130 on PyObjects (which are assumed to be PyLong or PyInt objects). | 133 on PyObjects (which are assumed to be PyLong or PyInt objects). |
| 131 ---------------------------------------------------------------*/ | 134 ---------------------------------------------------------------*/ |
| 132 int cmp_result, cmp_call; | 135 int cmp_result, cmp_call; |
| 133 PyObject *lo, *hi; | 136 PyObject *lo, *hi; |
| 134 PyObject *diff = NULL; | 137 PyObject *diff = NULL; |
| (...skipping 520 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 655 return NULL; | 658 return NULL; |
| 656 } | 659 } |
| 657 | 660 |
| 658 return (PyObject *)it; | 661 return (PyObject *)it; |
| 659 | 662 |
| 660 create_failure: | 663 create_failure: |
| 661 Py_XDECREF(len); | 664 Py_XDECREF(len); |
| 662 PyObject_Del(it); | 665 PyObject_Del(it); |
| 663 return NULL; | 666 return NULL; |
| 664 } | 667 } |
| LEFT | RIGHT |