Commit 6a99c289 authored by Stefan Behnel's avatar Stefan Behnel

Split an inline helper function to reduce excessive inlining.

parent 524b5755
...@@ -204,51 +204,61 @@ static CYTHON_INLINE const char* __Pyx_PyObject_AsString(PyObject* o) { ...@@ -204,51 +204,61 @@ static CYTHON_INLINE const char* __Pyx_PyObject_AsString(PyObject* o) {
return __Pyx_PyObject_AsStringAndSize(o, &ignore); return __Pyx_PyObject_AsStringAndSize(o, &ignore);
} }
// Py3.7 returns a "const char*" for unicode strings
static CYTHON_INLINE const char* __Pyx_PyObject_AsStringAndSize(PyObject* o, Py_ssize_t *length) {
#if CYTHON_COMPILING_IN_CPYTHON && (__PYX_DEFAULT_STRING_ENCODING_IS_ASCII || __PYX_DEFAULT_STRING_ENCODING_IS_DEFAULT) #if CYTHON_COMPILING_IN_CPYTHON && (__PYX_DEFAULT_STRING_ENCODING_IS_ASCII || __PYX_DEFAULT_STRING_ENCODING_IS_DEFAULT)
if (
#if PY_MAJOR_VERSION < 3 && __PYX_DEFAULT_STRING_ENCODING_IS_ASCII
__Pyx_sys_getdefaultencoding_not_ascii &&
#endif
PyUnicode_Check(o)) {
#if PY_VERSION_HEX < 0x03030000 #if PY_VERSION_HEX < 0x03030000
char* defenc_c; static const char* __Pyx_PyUnicode_AsStringAndSize(PyObject* o, Py_ssize_t *length) {
// borrowed reference, cached internally in 'o' by CPython char* defenc_c;
PyObject* defenc = _PyUnicode_AsDefaultEncodedString(o, NULL); // borrowed reference, cached internally in 'o' by CPython
if (!defenc) return NULL; PyObject* defenc = _PyUnicode_AsDefaultEncodedString(o, NULL);
defenc_c = PyBytes_AS_STRING(defenc); if (!defenc) return NULL;
defenc_c = PyBytes_AS_STRING(defenc);
#if __PYX_DEFAULT_STRING_ENCODING_IS_ASCII #if __PYX_DEFAULT_STRING_ENCODING_IS_ASCII
{ {
char* end = defenc_c + PyBytes_GET_SIZE(defenc); char* end = defenc_c + PyBytes_GET_SIZE(defenc);
char* c; char* c;
for (c = defenc_c; c < end; c++) { for (c = defenc_c; c < end; c++) {
if ((unsigned char) (*c) >= 128) { if ((unsigned char) (*c) >= 128) {
// raise the error // raise the error
PyUnicode_AsASCIIString(o); PyUnicode_AsASCIIString(o);
return NULL; return NULL;
}
} }
} }
}
#endif /*__PYX_DEFAULT_STRING_ENCODING_IS_ASCII*/ #endif /*__PYX_DEFAULT_STRING_ENCODING_IS_ASCII*/
*length = PyBytes_GET_SIZE(defenc); *length = PyBytes_GET_SIZE(defenc);
return defenc_c; return defenc_c;
}
#else /* PY_VERSION_HEX < 0x03030000 */ #else /* PY_VERSION_HEX < 0x03030000 */
if (__Pyx_PyUnicode_READY(o) == -1) return NULL;
static CYTHON_INLINE const char* __Pyx_PyUnicode_AsStringAndSize(PyObject* o, Py_ssize_t *length) {
if (unlikely(__Pyx_PyUnicode_READY(o) == -1)) return NULL;
#if __PYX_DEFAULT_STRING_ENCODING_IS_ASCII #if __PYX_DEFAULT_STRING_ENCODING_IS_ASCII
if (PyUnicode_IS_ASCII(o)) { if (likely(PyUnicode_IS_ASCII(o))) {
// cached for the lifetime of the object // cached for the lifetime of the object
*length = PyUnicode_GET_LENGTH(o); *length = PyUnicode_GET_LENGTH(o);
return PyUnicode_AsUTF8(o); return PyUnicode_AsUTF8(o);
} else { } else {
// raise the error // raise the error
PyUnicode_AsASCIIString(o); PyUnicode_AsASCIIString(o);
return NULL; return NULL;
} }
#else /* __PYX_DEFAULT_STRING_ENCODING_IS_ASCII */ #else /* __PYX_DEFAULT_STRING_ENCODING_IS_ASCII */
return PyUnicode_AsUTF8AndSize(o, length); return PyUnicode_AsUTF8AndSize(o, length);
#endif /* __PYX_DEFAULT_STRING_ENCODING_IS_ASCII */ #endif /* __PYX_DEFAULT_STRING_ENCODING_IS_ASCII */
}
#endif /* PY_VERSION_HEX < 0x03030000 */ #endif /* PY_VERSION_HEX < 0x03030000 */
#endif
// Py3.7 returns a "const char*" for unicode strings
static CYTHON_INLINE const char* __Pyx_PyObject_AsStringAndSize(PyObject* o, Py_ssize_t *length) {
#if CYTHON_COMPILING_IN_CPYTHON && (__PYX_DEFAULT_STRING_ENCODING_IS_ASCII || __PYX_DEFAULT_STRING_ENCODING_IS_DEFAULT)
if (
#if PY_MAJOR_VERSION < 3 && __PYX_DEFAULT_STRING_ENCODING_IS_ASCII
__Pyx_sys_getdefaultencoding_not_ascii &&
#endif
PyUnicode_Check(o)) {
return __Pyx_PyUnicode_AsStringAndSize(o, length);
} else } else
#endif /* __PYX_DEFAULT_STRING_ENCODING_IS_ASCII || __PYX_DEFAULT_STRING_ENCODING_IS_DEFAULT */ #endif /* __PYX_DEFAULT_STRING_ENCODING_IS_ASCII || __PYX_DEFAULT_STRING_ENCODING_IS_DEFAULT */
......
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