summaryrefslogtreecommitdiffstats
path: root/contrib/tools/cython/Cython/Utility/Optimize.c
diff options
context:
space:
mode:
authorAnton Samokhvalov <[email protected]>2022-02-10 16:45:17 +0300
committerDaniil Cherednik <[email protected]>2022-02-10 16:45:17 +0300
commitd3a398281c6fd1d3672036cb2d63f842d2cb28c5 (patch)
treedd4bd3ca0f36b817e96812825ffaf10d645803f2 /contrib/tools/cython/Cython/Utility/Optimize.c
parent72cb13b4aff9bc9cf22e49251bc8fd143f82538f (diff)
Restoring authorship annotation for Anton Samokhvalov <[email protected]>. Commit 2 of 2.
Diffstat (limited to 'contrib/tools/cython/Cython/Utility/Optimize.c')
-rw-r--r--contrib/tools/cython/Cython/Utility/Optimize.c840
1 files changed, 420 insertions, 420 deletions
diff --git a/contrib/tools/cython/Cython/Utility/Optimize.c b/contrib/tools/cython/Cython/Utility/Optimize.c
index 34b6438f33e..d18c9b78ec6 100644
--- a/contrib/tools/cython/Cython/Utility/Optimize.c
+++ b/contrib/tools/cython/Cython/Utility/Optimize.c
@@ -1,122 +1,122 @@
-/*
- * Optional optimisations of built-in functions and methods.
- *
- * Required replacements of builtins are in Builtins.c.
- *
- * General object operations and protocols are in ObjectHandling.c.
- */
-
-/////////////// append.proto ///////////////
-
-static CYTHON_INLINE int __Pyx_PyObject_Append(PyObject* L, PyObject* x); /*proto*/
-
-/////////////// append ///////////////
-//@requires: ListAppend
-//@requires: ObjectHandling.c::PyObjectCallMethod1
-
-static CYTHON_INLINE int __Pyx_PyObject_Append(PyObject* L, PyObject* x) {
- if (likely(PyList_CheckExact(L))) {
- if (unlikely(__Pyx_PyList_Append(L, x) < 0)) return -1;
- } else {
- PyObject* retval = __Pyx_PyObject_CallMethod1(L, PYIDENT("append"), x);
- if (unlikely(!retval))
- return -1;
- Py_DECREF(retval);
- }
- return 0;
-}
-
-/////////////// ListAppend.proto ///////////////
-
+/*
+ * Optional optimisations of built-in functions and methods.
+ *
+ * Required replacements of builtins are in Builtins.c.
+ *
+ * General object operations and protocols are in ObjectHandling.c.
+ */
+
+/////////////// append.proto ///////////////
+
+static CYTHON_INLINE int __Pyx_PyObject_Append(PyObject* L, PyObject* x); /*proto*/
+
+/////////////// append ///////////////
+//@requires: ListAppend
+//@requires: ObjectHandling.c::PyObjectCallMethod1
+
+static CYTHON_INLINE int __Pyx_PyObject_Append(PyObject* L, PyObject* x) {
+ if (likely(PyList_CheckExact(L))) {
+ if (unlikely(__Pyx_PyList_Append(L, x) < 0)) return -1;
+ } else {
+ PyObject* retval = __Pyx_PyObject_CallMethod1(L, PYIDENT("append"), x);
+ if (unlikely(!retval))
+ return -1;
+ Py_DECREF(retval);
+ }
+ return 0;
+}
+
+/////////////// ListAppend.proto ///////////////
+
#if CYTHON_USE_PYLIST_INTERNALS && CYTHON_ASSUME_SAFE_MACROS
-static CYTHON_INLINE int __Pyx_PyList_Append(PyObject* list, PyObject* x) {
- PyListObject* L = (PyListObject*) list;
- Py_ssize_t len = Py_SIZE(list);
- if (likely(L->allocated > len) & likely(len > (L->allocated >> 1))) {
- Py_INCREF(x);
- PyList_SET_ITEM(list, len, x);
+static CYTHON_INLINE int __Pyx_PyList_Append(PyObject* list, PyObject* x) {
+ PyListObject* L = (PyListObject*) list;
+ Py_ssize_t len = Py_SIZE(list);
+ if (likely(L->allocated > len) & likely(len > (L->allocated >> 1))) {
+ Py_INCREF(x);
+ PyList_SET_ITEM(list, len, x);
__Pyx_SET_SIZE(list, len + 1);
- return 0;
- }
- return PyList_Append(list, x);
-}
-#else
-#define __Pyx_PyList_Append(L,x) PyList_Append(L,x)
-#endif
-
-/////////////// ListCompAppend.proto ///////////////
-
+ return 0;
+ }
+ return PyList_Append(list, x);
+}
+#else
+#define __Pyx_PyList_Append(L,x) PyList_Append(L,x)
+#endif
+
+/////////////// ListCompAppend.proto ///////////////
+
#if CYTHON_USE_PYLIST_INTERNALS && CYTHON_ASSUME_SAFE_MACROS
-static CYTHON_INLINE int __Pyx_ListComp_Append(PyObject* list, PyObject* x) {
- PyListObject* L = (PyListObject*) list;
- Py_ssize_t len = Py_SIZE(list);
- if (likely(L->allocated > len)) {
- Py_INCREF(x);
- PyList_SET_ITEM(list, len, x);
+static CYTHON_INLINE int __Pyx_ListComp_Append(PyObject* list, PyObject* x) {
+ PyListObject* L = (PyListObject*) list;
+ Py_ssize_t len = Py_SIZE(list);
+ if (likely(L->allocated > len)) {
+ Py_INCREF(x);
+ PyList_SET_ITEM(list, len, x);
__Pyx_SET_SIZE(list, len + 1);
- return 0;
- }
- return PyList_Append(list, x);
-}
-#else
-#define __Pyx_ListComp_Append(L,x) PyList_Append(L,x)
-#endif
-
-//////////////////// ListExtend.proto ////////////////////
-
-static CYTHON_INLINE int __Pyx_PyList_Extend(PyObject* L, PyObject* v) {
-#if CYTHON_COMPILING_IN_CPYTHON
- PyObject* none = _PyList_Extend((PyListObject*)L, v);
- if (unlikely(!none))
- return -1;
- Py_DECREF(none);
- return 0;
-#else
- return PyList_SetSlice(L, PY_SSIZE_T_MAX, PY_SSIZE_T_MAX, v);
-#endif
-}
-
-/////////////// pop.proto ///////////////
-
+ return 0;
+ }
+ return PyList_Append(list, x);
+}
+#else
+#define __Pyx_ListComp_Append(L,x) PyList_Append(L,x)
+#endif
+
+//////////////////// ListExtend.proto ////////////////////
+
+static CYTHON_INLINE int __Pyx_PyList_Extend(PyObject* L, PyObject* v) {
+#if CYTHON_COMPILING_IN_CPYTHON
+ PyObject* none = _PyList_Extend((PyListObject*)L, v);
+ if (unlikely(!none))
+ return -1;
+ Py_DECREF(none);
+ return 0;
+#else
+ return PyList_SetSlice(L, PY_SSIZE_T_MAX, PY_SSIZE_T_MAX, v);
+#endif
+}
+
+/////////////// pop.proto ///////////////
+
static CYTHON_INLINE PyObject* __Pyx__PyObject_Pop(PyObject* L); /*proto*/
-
+
#if CYTHON_USE_PYLIST_INTERNALS && CYTHON_ASSUME_SAFE_MACROS
-static CYTHON_INLINE PyObject* __Pyx_PyList_Pop(PyObject* L); /*proto*/
+static CYTHON_INLINE PyObject* __Pyx_PyList_Pop(PyObject* L); /*proto*/
#define __Pyx_PyObject_Pop(L) (likely(PyList_CheckExact(L)) ? \
__Pyx_PyList_Pop(L) : __Pyx__PyObject_Pop(L))
-
+
#else
#define __Pyx_PyList_Pop(L) __Pyx__PyObject_Pop(L)
#define __Pyx_PyObject_Pop(L) __Pyx__PyObject_Pop(L)
#endif
-/////////////// pop ///////////////
-//@requires: ObjectHandling.c::PyObjectCallMethod0
-
-static CYTHON_INLINE PyObject* __Pyx__PyObject_Pop(PyObject* L) {
- if (Py_TYPE(L) == &PySet_Type) {
- return PySet_Pop(L);
- }
- return __Pyx_PyObject_CallMethod0(L, PYIDENT("pop"));
-}
-
+/////////////// pop ///////////////
+//@requires: ObjectHandling.c::PyObjectCallMethod0
+
+static CYTHON_INLINE PyObject* __Pyx__PyObject_Pop(PyObject* L) {
+ if (Py_TYPE(L) == &PySet_Type) {
+ return PySet_Pop(L);
+ }
+ return __Pyx_PyObject_CallMethod0(L, PYIDENT("pop"));
+}
+
#if CYTHON_USE_PYLIST_INTERNALS && CYTHON_ASSUME_SAFE_MACROS
-static CYTHON_INLINE PyObject* __Pyx_PyList_Pop(PyObject* L) {
- /* Check that both the size is positive and no reallocation shrinking needs to be done. */
- if (likely(PyList_GET_SIZE(L) > (((PyListObject*)L)->allocated >> 1))) {
+static CYTHON_INLINE PyObject* __Pyx_PyList_Pop(PyObject* L) {
+ /* Check that both the size is positive and no reallocation shrinking needs to be done. */
+ if (likely(PyList_GET_SIZE(L) > (((PyListObject*)L)->allocated >> 1))) {
__Pyx_SET_SIZE(L, Py_SIZE(L) - 1);
- return PyList_GET_ITEM(L, PyList_GET_SIZE(L));
- }
+ return PyList_GET_ITEM(L, PyList_GET_SIZE(L));
+ }
return CALL_UNBOUND_METHOD(PyList_Type, "pop", L);
}
-#endif
-
-
-/////////////// pop_index.proto ///////////////
-
+#endif
+
+
+/////////////// pop_index.proto ///////////////
+
static PyObject* __Pyx__PyObject_PopNewIndex(PyObject* L, PyObject* py_ix); /*proto*/
static PyObject* __Pyx__PyObject_PopIndex(PyObject* L, PyObject* py_ix); /*proto*/
-
+
#if CYTHON_USE_PYLIST_INTERNALS && CYTHON_ASSUME_SAFE_MACROS
static PyObject* __Pyx__PyList_PopIndex(PyObject* L, PyObject* py_ix, Py_ssize_t ix); /*proto*/
@@ -127,13 +127,13 @@ static PyObject* __Pyx__PyList_PopIndex(PyObject* L, PyObject* py_ix, Py_ssize_t
__Pyx__PyObject_PopIndex(L, py_ix)))
#define __Pyx_PyList_PopIndex(L, py_ix, ix, is_signed, type, to_py_func) ( \
- __Pyx_fits_Py_ssize_t(ix, type, is_signed) ? \
+ __Pyx_fits_Py_ssize_t(ix, type, is_signed) ? \
__Pyx__PyList_PopIndex(L, py_ix, ix) : ( \
(unlikely((py_ix) == Py_None)) ? __Pyx__PyObject_PopNewIndex(L, to_py_func(ix)) : \
__Pyx__PyObject_PopIndex(L, py_ix)))
-
+
#else
-
+
#define __Pyx_PyList_PopIndex(L, py_ix, ix, is_signed, type, to_py_func) \
__Pyx_PyObject_PopIndex(L, py_ix, ix, is_signed, type, to_py_func)
@@ -142,135 +142,135 @@ static PyObject* __Pyx__PyList_PopIndex(PyObject* L, PyObject* py_ix, Py_ssize_t
__Pyx__PyObject_PopIndex(L, py_ix))
#endif
-/////////////// pop_index ///////////////
-//@requires: ObjectHandling.c::PyObjectCallMethod1
-
+/////////////// pop_index ///////////////
+//@requires: ObjectHandling.c::PyObjectCallMethod1
+
static PyObject* __Pyx__PyObject_PopNewIndex(PyObject* L, PyObject* py_ix) {
- PyObject *r;
- if (unlikely(!py_ix)) return NULL;
+ PyObject *r;
+ if (unlikely(!py_ix)) return NULL;
r = __Pyx__PyObject_PopIndex(L, py_ix);
- Py_DECREF(py_ix);
- return r;
-}
-
+ Py_DECREF(py_ix);
+ return r;
+}
+
static PyObject* __Pyx__PyObject_PopIndex(PyObject* L, PyObject* py_ix) {
return __Pyx_PyObject_CallMethod1(L, PYIDENT("pop"), py_ix);
}
#if CYTHON_USE_PYLIST_INTERNALS && CYTHON_ASSUME_SAFE_MACROS
static PyObject* __Pyx__PyList_PopIndex(PyObject* L, PyObject* py_ix, Py_ssize_t ix) {
- Py_ssize_t size = PyList_GET_SIZE(L);
- if (likely(size > (((PyListObject*)L)->allocated >> 1))) {
- Py_ssize_t cix = ix;
- if (cix < 0) {
- cix += size;
- }
+ Py_ssize_t size = PyList_GET_SIZE(L);
+ if (likely(size > (((PyListObject*)L)->allocated >> 1))) {
+ Py_ssize_t cix = ix;
+ if (cix < 0) {
+ cix += size;
+ }
if (likely(__Pyx_is_valid_index(cix, size))) {
- PyObject* v = PyList_GET_ITEM(L, cix);
+ PyObject* v = PyList_GET_ITEM(L, cix);
__Pyx_SET_SIZE(L, Py_SIZE(L) - 1);
- size -= 1;
- memmove(&PyList_GET_ITEM(L, cix), &PyList_GET_ITEM(L, cix+1), (size_t)(size-cix)*sizeof(PyObject*));
- return v;
- }
- }
+ size -= 1;
+ memmove(&PyList_GET_ITEM(L, cix), &PyList_GET_ITEM(L, cix+1), (size_t)(size-cix)*sizeof(PyObject*));
+ return v;
+ }
+ }
if (py_ix == Py_None) {
return __Pyx__PyObject_PopNewIndex(L, PyInt_FromSsize_t(ix));
} else {
return __Pyx__PyObject_PopIndex(L, py_ix);
}
}
-#endif
-
-
-/////////////// dict_getitem_default.proto ///////////////
-
-static PyObject* __Pyx_PyDict_GetItemDefault(PyObject* d, PyObject* key, PyObject* default_value); /*proto*/
-
-/////////////// dict_getitem_default ///////////////
-
-static PyObject* __Pyx_PyDict_GetItemDefault(PyObject* d, PyObject* key, PyObject* default_value) {
- PyObject* value;
+#endif
+
+
+/////////////// dict_getitem_default.proto ///////////////
+
+static PyObject* __Pyx_PyDict_GetItemDefault(PyObject* d, PyObject* key, PyObject* default_value); /*proto*/
+
+/////////////// dict_getitem_default ///////////////
+
+static PyObject* __Pyx_PyDict_GetItemDefault(PyObject* d, PyObject* key, PyObject* default_value) {
+ PyObject* value;
#if PY_MAJOR_VERSION >= 3 && !CYTHON_COMPILING_IN_PYPY
- value = PyDict_GetItemWithError(d, key);
- if (unlikely(!value)) {
- if (unlikely(PyErr_Occurred()))
- return NULL;
- value = default_value;
- }
- Py_INCREF(value);
+ value = PyDict_GetItemWithError(d, key);
+ if (unlikely(!value)) {
+ if (unlikely(PyErr_Occurred()))
+ return NULL;
+ value = default_value;
+ }
+ Py_INCREF(value);
// avoid C compiler warning about unused utility functions
if ((1));
-#else
- if (PyString_CheckExact(key) || PyUnicode_CheckExact(key) || PyInt_CheckExact(key)) {
- /* these presumably have safe hash functions */
- value = PyDict_GetItem(d, key);
- if (unlikely(!value)) {
- value = default_value;
- }
- Py_INCREF(value);
+#else
+ if (PyString_CheckExact(key) || PyUnicode_CheckExact(key) || PyInt_CheckExact(key)) {
+ /* these presumably have safe hash functions */
+ value = PyDict_GetItem(d, key);
+ if (unlikely(!value)) {
+ value = default_value;
+ }
+ Py_INCREF(value);
}
#endif
else {
- if (default_value == Py_None)
+ if (default_value == Py_None)
value = CALL_UNBOUND_METHOD(PyDict_Type, "get", d, key);
else
value = CALL_UNBOUND_METHOD(PyDict_Type, "get", d, key, default_value);
- }
- return value;
-}
-
-
-/////////////// dict_setdefault.proto ///////////////
-
-static CYTHON_INLINE PyObject *__Pyx_PyDict_SetDefault(PyObject *d, PyObject *key, PyObject *default_value, int is_safe_type); /*proto*/
-
-/////////////// dict_setdefault ///////////////
-
-static CYTHON_INLINE PyObject *__Pyx_PyDict_SetDefault(PyObject *d, PyObject *key, PyObject *default_value,
- CYTHON_UNUSED int is_safe_type) {
- PyObject* value;
-#if PY_VERSION_HEX >= 0x030400A0
- // we keep the method call at the end to avoid "unused" C compiler warnings
+ }
+ return value;
+}
+
+
+/////////////// dict_setdefault.proto ///////////////
+
+static CYTHON_INLINE PyObject *__Pyx_PyDict_SetDefault(PyObject *d, PyObject *key, PyObject *default_value, int is_safe_type); /*proto*/
+
+/////////////// dict_setdefault ///////////////
+
+static CYTHON_INLINE PyObject *__Pyx_PyDict_SetDefault(PyObject *d, PyObject *key, PyObject *default_value,
+ CYTHON_UNUSED int is_safe_type) {
+ PyObject* value;
+#if PY_VERSION_HEX >= 0x030400A0
+ // we keep the method call at the end to avoid "unused" C compiler warnings
if ((1)) {
- value = PyDict_SetDefault(d, key, default_value);
- if (unlikely(!value)) return NULL;
- Py_INCREF(value);
-#else
- if (is_safe_type == 1 || (is_safe_type == -1 &&
- /* the following builtins presumably have repeatably safe and fast hash functions */
+ value = PyDict_SetDefault(d, key, default_value);
+ if (unlikely(!value)) return NULL;
+ Py_INCREF(value);
+#else
+ if (is_safe_type == 1 || (is_safe_type == -1 &&
+ /* the following builtins presumably have repeatably safe and fast hash functions */
#if PY_MAJOR_VERSION >= 3 && !CYTHON_COMPILING_IN_PYPY
- (PyUnicode_CheckExact(key) || PyString_CheckExact(key) || PyLong_CheckExact(key)))) {
- value = PyDict_GetItemWithError(d, key);
- if (unlikely(!value)) {
- if (unlikely(PyErr_Occurred()))
- return NULL;
- if (unlikely(PyDict_SetItem(d, key, default_value) == -1))
- return NULL;
- value = default_value;
- }
- Py_INCREF(value);
-#else
- (PyString_CheckExact(key) || PyUnicode_CheckExact(key) || PyInt_CheckExact(key) || PyLong_CheckExact(key)))) {
- value = PyDict_GetItem(d, key);
- if (unlikely(!value)) {
- if (unlikely(PyDict_SetItem(d, key, default_value) == -1))
- return NULL;
- value = default_value;
- }
- Py_INCREF(value);
-#endif
-#endif
- } else {
+ (PyUnicode_CheckExact(key) || PyString_CheckExact(key) || PyLong_CheckExact(key)))) {
+ value = PyDict_GetItemWithError(d, key);
+ if (unlikely(!value)) {
+ if (unlikely(PyErr_Occurred()))
+ return NULL;
+ if (unlikely(PyDict_SetItem(d, key, default_value) == -1))
+ return NULL;
+ value = default_value;
+ }
+ Py_INCREF(value);
+#else
+ (PyString_CheckExact(key) || PyUnicode_CheckExact(key) || PyInt_CheckExact(key) || PyLong_CheckExact(key)))) {
+ value = PyDict_GetItem(d, key);
+ if (unlikely(!value)) {
+ if (unlikely(PyDict_SetItem(d, key, default_value) == -1))
+ return NULL;
+ value = default_value;
+ }
+ Py_INCREF(value);
+#endif
+#endif
+ } else {
value = CALL_UNBOUND_METHOD(PyDict_Type, "setdefault", d, key, default_value);
- }
- return value;
-}
-
-
-/////////////// py_dict_clear.proto ///////////////
-
-#define __Pyx_PyDict_Clear(d) (PyDict_Clear(d), 0)
-
+ }
+ return value;
+}
+
+
+/////////////// py_dict_clear.proto ///////////////
+
+#define __Pyx_PyDict_Clear(d) (PyDict_Clear(d), 0)
+
/////////////// py_dict_pop.proto ///////////////
@@ -293,27 +293,27 @@ static CYTHON_INLINE PyObject *__Pyx_PyDict_Pop(PyObject *d, PyObject *key, PyOb
}
-/////////////// dict_iter.proto ///////////////
-
-static CYTHON_INLINE PyObject* __Pyx_dict_iterator(PyObject* dict, int is_dict, PyObject* method_name,
- Py_ssize_t* p_orig_length, int* p_is_dict);
-static CYTHON_INLINE int __Pyx_dict_iter_next(PyObject* dict_or_iter, Py_ssize_t orig_length, Py_ssize_t* ppos,
- PyObject** pkey, PyObject** pvalue, PyObject** pitem, int is_dict);
-
-/////////////// dict_iter ///////////////
-//@requires: ObjectHandling.c::UnpackTuple2
-//@requires: ObjectHandling.c::IterFinish
-//@requires: ObjectHandling.c::PyObjectCallMethod0
-
-static CYTHON_INLINE PyObject* __Pyx_dict_iterator(PyObject* iterable, int is_dict, PyObject* method_name,
- Py_ssize_t* p_orig_length, int* p_source_is_dict) {
- is_dict = is_dict || likely(PyDict_CheckExact(iterable));
- *p_source_is_dict = is_dict;
+/////////////// dict_iter.proto ///////////////
+
+static CYTHON_INLINE PyObject* __Pyx_dict_iterator(PyObject* dict, int is_dict, PyObject* method_name,
+ Py_ssize_t* p_orig_length, int* p_is_dict);
+static CYTHON_INLINE int __Pyx_dict_iter_next(PyObject* dict_or_iter, Py_ssize_t orig_length, Py_ssize_t* ppos,
+ PyObject** pkey, PyObject** pvalue, PyObject** pitem, int is_dict);
+
+/////////////// dict_iter ///////////////
+//@requires: ObjectHandling.c::UnpackTuple2
+//@requires: ObjectHandling.c::IterFinish
+//@requires: ObjectHandling.c::PyObjectCallMethod0
+
+static CYTHON_INLINE PyObject* __Pyx_dict_iterator(PyObject* iterable, int is_dict, PyObject* method_name,
+ Py_ssize_t* p_orig_length, int* p_source_is_dict) {
+ is_dict = is_dict || likely(PyDict_CheckExact(iterable));
+ *p_source_is_dict = is_dict;
if (is_dict) {
-#if !CYTHON_COMPILING_IN_PYPY
- *p_orig_length = PyDict_Size(iterable);
- Py_INCREF(iterable);
- return iterable;
+#if !CYTHON_COMPILING_IN_PYPY
+ *p_orig_length = PyDict_Size(iterable);
+ Py_INCREF(iterable);
+ return iterable;
#elif PY_MAJOR_VERSION >= 3
// On PyPy3, we need to translate manually a few method names.
// This logic is not needed on CPython thanks to the fast case above.
@@ -334,93 +334,93 @@ static CYTHON_INLINE PyObject* __Pyx_dict_iterator(PyObject* iterable, int is_di
}
}
#endif
- }
- *p_orig_length = 0;
- if (method_name) {
- PyObject* iter;
- iterable = __Pyx_PyObject_CallMethod0(iterable, method_name);
- if (!iterable)
- return NULL;
-#if !CYTHON_COMPILING_IN_PYPY
- if (PyTuple_CheckExact(iterable) || PyList_CheckExact(iterable))
- return iterable;
-#endif
- iter = PyObject_GetIter(iterable);
- Py_DECREF(iterable);
- return iter;
- }
- return PyObject_GetIter(iterable);
-}
-
+ }
+ *p_orig_length = 0;
+ if (method_name) {
+ PyObject* iter;
+ iterable = __Pyx_PyObject_CallMethod0(iterable, method_name);
+ if (!iterable)
+ return NULL;
+#if !CYTHON_COMPILING_IN_PYPY
+ if (PyTuple_CheckExact(iterable) || PyList_CheckExact(iterable))
+ return iterable;
+#endif
+ iter = PyObject_GetIter(iterable);
+ Py_DECREF(iterable);
+ return iter;
+ }
+ return PyObject_GetIter(iterable);
+}
+
static CYTHON_INLINE int __Pyx_dict_iter_next(
PyObject* iter_obj, CYTHON_NCP_UNUSED Py_ssize_t orig_length, CYTHON_NCP_UNUSED Py_ssize_t* ppos,
PyObject** pkey, PyObject** pvalue, PyObject** pitem, int source_is_dict) {
- PyObject* next_item;
-#if !CYTHON_COMPILING_IN_PYPY
- if (source_is_dict) {
- PyObject *key, *value;
- if (unlikely(orig_length != PyDict_Size(iter_obj))) {
- PyErr_SetString(PyExc_RuntimeError, "dictionary changed size during iteration");
- return -1;
- }
- if (unlikely(!PyDict_Next(iter_obj, ppos, &key, &value))) {
- return 0;
- }
- if (pitem) {
- PyObject* tuple = PyTuple_New(2);
- if (unlikely(!tuple)) {
- return -1;
- }
- Py_INCREF(key);
- Py_INCREF(value);
- PyTuple_SET_ITEM(tuple, 0, key);
- PyTuple_SET_ITEM(tuple, 1, value);
- *pitem = tuple;
- } else {
- if (pkey) {
- Py_INCREF(key);
- *pkey = key;
- }
- if (pvalue) {
- Py_INCREF(value);
- *pvalue = value;
- }
- }
- return 1;
- } else if (PyTuple_CheckExact(iter_obj)) {
- Py_ssize_t pos = *ppos;
- if (unlikely(pos >= PyTuple_GET_SIZE(iter_obj))) return 0;
- *ppos = pos + 1;
- next_item = PyTuple_GET_ITEM(iter_obj, pos);
- Py_INCREF(next_item);
- } else if (PyList_CheckExact(iter_obj)) {
- Py_ssize_t pos = *ppos;
- if (unlikely(pos >= PyList_GET_SIZE(iter_obj))) return 0;
- *ppos = pos + 1;
- next_item = PyList_GET_ITEM(iter_obj, pos);
- Py_INCREF(next_item);
- } else
-#endif
- {
- next_item = PyIter_Next(iter_obj);
- if (unlikely(!next_item)) {
- return __Pyx_IterFinish();
- }
- }
- if (pitem) {
- *pitem = next_item;
- } else if (pkey && pvalue) {
- if (__Pyx_unpack_tuple2(next_item, pkey, pvalue, source_is_dict, source_is_dict, 1))
- return -1;
- } else if (pkey) {
- *pkey = next_item;
- } else {
- *pvalue = next_item;
- }
- return 1;
-}
-
-
+ PyObject* next_item;
+#if !CYTHON_COMPILING_IN_PYPY
+ if (source_is_dict) {
+ PyObject *key, *value;
+ if (unlikely(orig_length != PyDict_Size(iter_obj))) {
+ PyErr_SetString(PyExc_RuntimeError, "dictionary changed size during iteration");
+ return -1;
+ }
+ if (unlikely(!PyDict_Next(iter_obj, ppos, &key, &value))) {
+ return 0;
+ }
+ if (pitem) {
+ PyObject* tuple = PyTuple_New(2);
+ if (unlikely(!tuple)) {
+ return -1;
+ }
+ Py_INCREF(key);
+ Py_INCREF(value);
+ PyTuple_SET_ITEM(tuple, 0, key);
+ PyTuple_SET_ITEM(tuple, 1, value);
+ *pitem = tuple;
+ } else {
+ if (pkey) {
+ Py_INCREF(key);
+ *pkey = key;
+ }
+ if (pvalue) {
+ Py_INCREF(value);
+ *pvalue = value;
+ }
+ }
+ return 1;
+ } else if (PyTuple_CheckExact(iter_obj)) {
+ Py_ssize_t pos = *ppos;
+ if (unlikely(pos >= PyTuple_GET_SIZE(iter_obj))) return 0;
+ *ppos = pos + 1;
+ next_item = PyTuple_GET_ITEM(iter_obj, pos);
+ Py_INCREF(next_item);
+ } else if (PyList_CheckExact(iter_obj)) {
+ Py_ssize_t pos = *ppos;
+ if (unlikely(pos >= PyList_GET_SIZE(iter_obj))) return 0;
+ *ppos = pos + 1;
+ next_item = PyList_GET_ITEM(iter_obj, pos);
+ Py_INCREF(next_item);
+ } else
+#endif
+ {
+ next_item = PyIter_Next(iter_obj);
+ if (unlikely(!next_item)) {
+ return __Pyx_IterFinish();
+ }
+ }
+ if (pitem) {
+ *pitem = next_item;
+ } else if (pkey && pvalue) {
+ if (__Pyx_unpack_tuple2(next_item, pkey, pvalue, source_is_dict, source_is_dict, 1))
+ return -1;
+ } else if (pkey) {
+ *pkey = next_item;
+ } else {
+ *pvalue = next_item;
+ }
+ return 1;
+}
+
+
/////////////// set_iter.proto ///////////////
static CYTHON_INLINE PyObject* __Pyx_set_iterator(PyObject* iterable, int is_set,
@@ -558,105 +558,105 @@ static CYTHON_INLINE int __Pyx_PySet_Remove(PyObject *set, PyObject *key) {
}
-/////////////// unicode_iter.proto ///////////////
-
-static CYTHON_INLINE int __Pyx_init_unicode_iteration(
- PyObject* ustring, Py_ssize_t *length, void** data, int *kind); /* proto */
-
-/////////////// unicode_iter ///////////////
-
-static CYTHON_INLINE int __Pyx_init_unicode_iteration(
- PyObject* ustring, Py_ssize_t *length, void** data, int *kind) {
-#if CYTHON_PEP393_ENABLED
- if (unlikely(__Pyx_PyUnicode_READY(ustring) < 0)) return -1;
- *kind = PyUnicode_KIND(ustring);
- *length = PyUnicode_GET_LENGTH(ustring);
- *data = PyUnicode_DATA(ustring);
-#else
- *kind = 0;
- *length = PyUnicode_GET_SIZE(ustring);
- *data = (void*)PyUnicode_AS_UNICODE(ustring);
-#endif
- return 0;
-}
-
-/////////////// pyobject_as_double.proto ///////////////
-
-static double __Pyx__PyObject_AsDouble(PyObject* obj); /* proto */
-
-#if CYTHON_COMPILING_IN_PYPY
-#define __Pyx_PyObject_AsDouble(obj) \
-(likely(PyFloat_CheckExact(obj)) ? PyFloat_AS_DOUBLE(obj) : \
- likely(PyInt_CheckExact(obj)) ? \
- PyFloat_AsDouble(obj) : __Pyx__PyObject_AsDouble(obj))
-#else
-#define __Pyx_PyObject_AsDouble(obj) \
-((likely(PyFloat_CheckExact(obj))) ? \
- PyFloat_AS_DOUBLE(obj) : __Pyx__PyObject_AsDouble(obj))
-#endif
-
-/////////////// pyobject_as_double ///////////////
-
-static double __Pyx__PyObject_AsDouble(PyObject* obj) {
- PyObject* float_value;
+/////////////// unicode_iter.proto ///////////////
+
+static CYTHON_INLINE int __Pyx_init_unicode_iteration(
+ PyObject* ustring, Py_ssize_t *length, void** data, int *kind); /* proto */
+
+/////////////// unicode_iter ///////////////
+
+static CYTHON_INLINE int __Pyx_init_unicode_iteration(
+ PyObject* ustring, Py_ssize_t *length, void** data, int *kind) {
+#if CYTHON_PEP393_ENABLED
+ if (unlikely(__Pyx_PyUnicode_READY(ustring) < 0)) return -1;
+ *kind = PyUnicode_KIND(ustring);
+ *length = PyUnicode_GET_LENGTH(ustring);
+ *data = PyUnicode_DATA(ustring);
+#else
+ *kind = 0;
+ *length = PyUnicode_GET_SIZE(ustring);
+ *data = (void*)PyUnicode_AS_UNICODE(ustring);
+#endif
+ return 0;
+}
+
+/////////////// pyobject_as_double.proto ///////////////
+
+static double __Pyx__PyObject_AsDouble(PyObject* obj); /* proto */
+
+#if CYTHON_COMPILING_IN_PYPY
+#define __Pyx_PyObject_AsDouble(obj) \
+(likely(PyFloat_CheckExact(obj)) ? PyFloat_AS_DOUBLE(obj) : \
+ likely(PyInt_CheckExact(obj)) ? \
+ PyFloat_AsDouble(obj) : __Pyx__PyObject_AsDouble(obj))
+#else
+#define __Pyx_PyObject_AsDouble(obj) \
+((likely(PyFloat_CheckExact(obj))) ? \
+ PyFloat_AS_DOUBLE(obj) : __Pyx__PyObject_AsDouble(obj))
+#endif
+
+/////////////// pyobject_as_double ///////////////
+
+static double __Pyx__PyObject_AsDouble(PyObject* obj) {
+ PyObject* float_value;
#if !CYTHON_USE_TYPE_SLOTS
float_value = PyNumber_Float(obj); if ((0)) goto bad;
-#else
- PyNumberMethods *nb = Py_TYPE(obj)->tp_as_number;
- if (likely(nb) && likely(nb->nb_float)) {
- float_value = nb->nb_float(obj);
- if (likely(float_value) && unlikely(!PyFloat_Check(float_value))) {
- PyErr_Format(PyExc_TypeError,
- "__float__ returned non-float (type %.200s)",
- Py_TYPE(float_value)->tp_name);
- Py_DECREF(float_value);
- goto bad;
- }
- } else if (PyUnicode_CheckExact(obj) || PyBytes_CheckExact(obj)) {
-#if PY_MAJOR_VERSION >= 3
- float_value = PyFloat_FromString(obj);
-#else
- float_value = PyFloat_FromString(obj, 0);
-#endif
- } else {
- PyObject* args = PyTuple_New(1);
- if (unlikely(!args)) goto bad;
- PyTuple_SET_ITEM(args, 0, obj);
- float_value = PyObject_Call((PyObject*)&PyFloat_Type, args, 0);
- PyTuple_SET_ITEM(args, 0, 0);
- Py_DECREF(args);
- }
-#endif
- if (likely(float_value)) {
- double value = PyFloat_AS_DOUBLE(float_value);
- Py_DECREF(float_value);
- return value;
- }
-bad:
- return (double)-1;
-}
-
-
-/////////////// PyNumberPow2.proto ///////////////
-
-#define __Pyx_PyNumber_InPlacePowerOf2(a, b, c) __Pyx__PyNumber_PowerOf2(a, b, c, 1)
-#define __Pyx_PyNumber_PowerOf2(a, b, c) __Pyx__PyNumber_PowerOf2(a, b, c, 0)
-
-static PyObject* __Pyx__PyNumber_PowerOf2(PyObject *two, PyObject *exp, PyObject *none, int inplace); /*proto*/
-
-/////////////// PyNumberPow2 ///////////////
-
-static PyObject* __Pyx__PyNumber_PowerOf2(PyObject *two, PyObject *exp, PyObject *none, int inplace) {
-// in CPython, 1<<N is substantially faster than 2**N
-// see http://bugs.python.org/issue21420
+#else
+ PyNumberMethods *nb = Py_TYPE(obj)->tp_as_number;
+ if (likely(nb) && likely(nb->nb_float)) {
+ float_value = nb->nb_float(obj);
+ if (likely(float_value) && unlikely(!PyFloat_Check(float_value))) {
+ PyErr_Format(PyExc_TypeError,
+ "__float__ returned non-float (type %.200s)",
+ Py_TYPE(float_value)->tp_name);
+ Py_DECREF(float_value);
+ goto bad;
+ }
+ } else if (PyUnicode_CheckExact(obj) || PyBytes_CheckExact(obj)) {
+#if PY_MAJOR_VERSION >= 3
+ float_value = PyFloat_FromString(obj);
+#else
+ float_value = PyFloat_FromString(obj, 0);
+#endif
+ } else {
+ PyObject* args = PyTuple_New(1);
+ if (unlikely(!args)) goto bad;
+ PyTuple_SET_ITEM(args, 0, obj);
+ float_value = PyObject_Call((PyObject*)&PyFloat_Type, args, 0);
+ PyTuple_SET_ITEM(args, 0, 0);
+ Py_DECREF(args);
+ }
+#endif
+ if (likely(float_value)) {
+ double value = PyFloat_AS_DOUBLE(float_value);
+ Py_DECREF(float_value);
+ return value;
+ }
+bad:
+ return (double)-1;
+}
+
+
+/////////////// PyNumberPow2.proto ///////////////
+
+#define __Pyx_PyNumber_InPlacePowerOf2(a, b, c) __Pyx__PyNumber_PowerOf2(a, b, c, 1)
+#define __Pyx_PyNumber_PowerOf2(a, b, c) __Pyx__PyNumber_PowerOf2(a, b, c, 0)
+
+static PyObject* __Pyx__PyNumber_PowerOf2(PyObject *two, PyObject *exp, PyObject *none, int inplace); /*proto*/
+
+/////////////// PyNumberPow2 ///////////////
+
+static PyObject* __Pyx__PyNumber_PowerOf2(PyObject *two, PyObject *exp, PyObject *none, int inplace) {
+// in CPython, 1<<N is substantially faster than 2**N
+// see http://bugs.python.org/issue21420
#if !CYTHON_COMPILING_IN_PYPY
- Py_ssize_t shiftby;
+ Py_ssize_t shiftby;
#if PY_MAJOR_VERSION < 3
if (likely(PyInt_CheckExact(exp))) {
shiftby = PyInt_AS_LONG(exp);
} else
#endif
- if (likely(PyLong_CheckExact(exp))) {
+ if (likely(PyLong_CheckExact(exp))) {
#if CYTHON_USE_PYLONG_INTERNALS
const Py_ssize_t size = Py_SIZE(exp);
// tuned to optimise branch prediction
@@ -668,36 +668,36 @@ static PyObject* __Pyx__PyNumber_PowerOf2(PyObject *two, PyObject *exp, PyObject
goto fallback;
} else {
shiftby = PyLong_AsSsize_t(exp);
- }
- #else
- shiftby = PyLong_AsSsize_t(exp);
- #endif
- } else {
- goto fallback;
- }
- if (likely(shiftby >= 0)) {
- if ((size_t)shiftby <= sizeof(long) * 8 - 2) {
- long value = 1L << shiftby;
- return PyInt_FromLong(value);
+ }
+ #else
+ shiftby = PyLong_AsSsize_t(exp);
+ #endif
+ } else {
+ goto fallback;
+ }
+ if (likely(shiftby >= 0)) {
+ if ((size_t)shiftby <= sizeof(long) * 8 - 2) {
+ long value = 1L << shiftby;
+ return PyInt_FromLong(value);
#ifdef HAVE_LONG_LONG
} else if ((size_t)shiftby <= sizeof(unsigned PY_LONG_LONG) * 8 - 1) {
unsigned PY_LONG_LONG value = ((unsigned PY_LONG_LONG)1) << shiftby;
return PyLong_FromUnsignedLongLong(value);
#endif
- } else {
+ } else {
PyObject *result, *one = PyInt_FromLong(1L);
- if (unlikely(!one)) return NULL;
+ if (unlikely(!one)) return NULL;
result = PyNumber_Lshift(one, exp);
Py_DECREF(one);
return result;
- }
- } else if (shiftby == -1 && PyErr_Occurred()) {
- PyErr_Clear();
- }
-fallback:
-#endif
- return (inplace ? PyNumber_InPlacePower : PyNumber_Power)(two, exp, none);
-}
+ }
+ } else if (shiftby == -1 && PyErr_Occurred()) {
+ PyErr_Clear();
+ }
+fallback:
+#endif
+ return (inplace ? PyNumber_InPlacePower : PyNumber_Power)(two, exp, none);
+}
/////////////// PyIntCompare.proto ///////////////