summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorm-d-w <mw9050@gmail.com>2013-06-10 16:13:36 -0400
committerm-d-w <mw9050@gmail.com>2013-06-10 16:13:36 -0400
commit1a252e6a21098e42d289c2a14ae5bee7d58c1a18 (patch)
tree159d245b44a592080d4bfa6fc1dd1e2d5e7f6bdf
parenta1cce4df157f74ff2ce662072cf652e473942c3c (diff)
downloadnumpy-1a252e6a21098e42d289c2a14ae5bee7d58c1a18.tar.gz
ENH: Optimize array creation by avoiding errors
-rw-r--r--numpy/core/src/multiarray/common.c17
1 files changed, 11 insertions, 6 deletions
diff --git a/numpy/core/src/multiarray/common.c b/numpy/core/src/multiarray/common.c
index 1f9b520e8..b5d9d6542 100644
--- a/numpy/core/src/multiarray/common.c
+++ b/numpy/core/src/multiarray/common.c
@@ -45,17 +45,22 @@
* Returns attribute value on success, 0 on failure.
*/
PyObject *
-PyArray_GetAttrString_SuppressException(PyObject *v, char *name)
+PyArray_GetAttrString_SuppressException(PyObject *obj, char *name)
{
- PyTypeObject *tp = Py_TYPE(v);
+ PyTypeObject *tp = Py_TYPE(obj);
PyObject *res = (PyObject *)NULL;
- if (tp != &PyList_Type && tp != &PyTuple_Type && v != Py_None) {
+ if (// Is not trivial type
+ obj != Py_None &&
+ !PyList_CheckExact(obj) &&
+ !PyTuple_CheckExact(obj)) {
+ // Attribute referenced by (char *)name
if (tp->tp_getattr != NULL) {
- res = (*tp->tp_getattr)(v, name);
+ res = (*tp->tp_getattr)(obj, name);
if (res == NULL) {
PyErr_Clear();
}
}
+ // Attribute referenced by (PyObject *)name
else if (tp->tp_getattro != NULL) {
#if defined(NPY_PY3K)
PyObject *w = PyUnicode_InternFromString(name);
@@ -64,8 +69,8 @@ PyArray_GetAttrString_SuppressException(PyObject *v, char *name)
#endif
if (w == NULL)
return (PyObject *)NULL;
- Py_XDECREF(w);
- res = (*tp->tp_getattro)(v, w);
+ Py_DECREF(w);
+ res = (*tp->tp_getattro)(obj, w);
if (res == NULL) {
PyErr_Clear();
}