Commit 0ab8b1ce authored by Stefan Behnel's avatar Stefan Behnel

Avoid excessive inlining of __Pyx_GetBufferAndValidate() helper and only...

Avoid excessive inlining of __Pyx_GetBufferAndValidate() helper and only inline the initial None check through a macro.
Assumption is that explicit None assignments to buffer variables are somewhat common to clear data and NULL checks can be eliminated, but everything else takes substantial time anyway.
parent 267858d2
...@@ -157,8 +157,14 @@ static void __Pyx_ReleaseBuffer(Py_buffer *view) { ...@@ -157,8 +157,14 @@ static void __Pyx_ReleaseBuffer(Py_buffer *view) {
The alignment code is copied from _struct.c in Python. The alignment code is copied from _struct.c in Python.
}} }}
static CYTHON_INLINE int __Pyx_GetBufferAndValidate(Py_buffer* buf, PyObject* obj, #define __Pyx_GetBufferAndValidate(buf, obj, dtype, flags, nd, cast, stack) \
((obj == Py_None || obj == NULL) ? \
(__Pyx_ZeroBuffer(buf), 0) : \
__Pyx__GetBufferAndValidate(buf, obj, dtype, flags, nd, cast, stack))
static int __Pyx__GetBufferAndValidate(Py_buffer* buf, PyObject* obj,
__Pyx_TypeInfo* dtype, int flags, int nd, int cast, __Pyx_BufFmt_StackElem* stack); __Pyx_TypeInfo* dtype, int flags, int nd, int cast, __Pyx_BufFmt_StackElem* stack);
static CYTHON_INLINE void __Pyx_ZeroBuffer(Py_buffer* buf);
static CYTHON_INLINE void __Pyx_SafeReleaseBuffer(Py_buffer* info); static CYTHON_INLINE void __Pyx_SafeReleaseBuffer(Py_buffer* info);
static const char* __Pyx_BufFmt_CheckString(__Pyx_BufFmt_Context* ctx, const char* ts); static const char* __Pyx_BufFmt_CheckString(__Pyx_BufFmt_Context* ctx, const char* ts);
static void __Pyx_BufFmt_Init(__Pyx_BufFmt_Context* ctx, static void __Pyx_BufFmt_Init(__Pyx_BufFmt_Context* ctx,
...@@ -733,21 +739,17 @@ static CYTHON_INLINE void __Pyx_ZeroBuffer(Py_buffer* buf) { ...@@ -733,21 +739,17 @@ static CYTHON_INLINE void __Pyx_ZeroBuffer(Py_buffer* buf) {
buf->suboffsets = __Pyx_minusones; buf->suboffsets = __Pyx_minusones;
} }
static CYTHON_INLINE int __Pyx_GetBufferAndValidate( static int __Pyx__GetBufferAndValidate(
Py_buffer* buf, PyObject* obj, __Pyx_TypeInfo* dtype, int flags, Py_buffer* buf, PyObject* obj, __Pyx_TypeInfo* dtype, int flags,
int nd, int cast, __Pyx_BufFmt_StackElem* stack) int nd, int cast, __Pyx_BufFmt_StackElem* stack)
{ {
if (obj == Py_None || obj == NULL) {
__Pyx_ZeroBuffer(buf);
return 0;
}
buf->buf = NULL; buf->buf = NULL;
if (__Pyx_GetBuffer(obj, buf, flags) == -1) { if (unlikely(__Pyx_GetBuffer(obj, buf, flags) == -1)) {
__Pyx_ZeroBuffer(buf); __Pyx_ZeroBuffer(buf);
return -1; return -1;
} }
// From this point on, we have acquired the buffer and must release it on errors. // From this point on, we have acquired the buffer and must release it on errors.
if (buf->ndim != nd) { if (unlikely(buf->ndim != nd)) {
PyErr_Format(PyExc_ValueError, PyErr_Format(PyExc_ValueError,
"Buffer has wrong number of dimensions (expected %d, got %d)", "Buffer has wrong number of dimensions (expected %d, got %d)",
nd, buf->ndim); nd, buf->ndim);
...@@ -758,7 +760,7 @@ static CYTHON_INLINE int __Pyx_GetBufferAndValidate( ...@@ -758,7 +760,7 @@ static CYTHON_INLINE int __Pyx_GetBufferAndValidate(
__Pyx_BufFmt_Init(&ctx, stack, dtype); __Pyx_BufFmt_Init(&ctx, stack, dtype);
if (!__Pyx_BufFmt_CheckString(&ctx, buf->format)) goto fail; if (!__Pyx_BufFmt_CheckString(&ctx, buf->format)) goto fail;
} }
if ((unsigned)buf->itemsize != dtype->size) { if (unlikely((unsigned)buf->itemsize != dtype->size)) {
PyErr_Format(PyExc_ValueError, PyErr_Format(PyExc_ValueError,
"Item size of buffer (%" CYTHON_FORMAT_SSIZE_T "d byte%s) does not match size of '%s' (%" CYTHON_FORMAT_SSIZE_T "d byte%s)", "Item size of buffer (%" CYTHON_FORMAT_SSIZE_T "d byte%s) does not match size of '%s' (%" CYTHON_FORMAT_SSIZE_T "d byte%s)",
buf->itemsize, (buf->itemsize > 1) ? "s" : "", buf->itemsize, (buf->itemsize > 1) ? "s" : "",
...@@ -773,7 +775,7 @@ fail:; ...@@ -773,7 +775,7 @@ fail:;
} }
static CYTHON_INLINE void __Pyx_SafeReleaseBuffer(Py_buffer* info) { static CYTHON_INLINE void __Pyx_SafeReleaseBuffer(Py_buffer* info) {
if (info->buf == NULL) return; if (unlikely(info->buf == NULL)) return;
if (info->suboffsets == __Pyx_minusones) info->suboffsets = NULL; if (info->suboffsets == __Pyx_minusones) info->suboffsets = NULL;
__Pyx_ReleaseBuffer(info); __Pyx_ReleaseBuffer(info);
} }
......
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