diff options
| author | Eric Wieser <wieser.eric@gmail.com> | 2018-02-01 21:10:52 -0800 |
|---|---|---|
| committer | Eric Wieser <wieser.eric@gmail.com> | 2018-02-04 12:06:52 -0800 |
| commit | 74e8690a2ee1b4b5c5ca4b0c505cbf44298b7fe8 (patch) | |
| tree | 70fb768de1364b626c3eb37999a404c4065b6ed8 /numpy/core/src | |
| parent | ae76158a5aec8f78a9527ef94f65aa34d5901248 (diff) | |
| download | numpy-74e8690a2ee1b4b5c5ca4b0c505cbf44298b7fe8.tar.gz | |
MAINT: Use PyUString_InternFromString to avoid constructing the strings on each call
Diffstat (limited to 'numpy/core/src')
| -rw-r--r-- | numpy/core/src/multiarray/common.h | 13 | ||||
| -rw-r--r-- | numpy/core/src/multiarray/item_selection.c | 5 | ||||
| -rw-r--r-- | numpy/core/src/multiarray/multiarraymodule.c | 6 | ||||
| -rw-r--r-- | numpy/core/src/multiarray/multiarraymodule.h | 2 | ||||
| -rw-r--r-- | numpy/core/src/multiarray/shape.c | 5 |
5 files changed, 13 insertions, 18 deletions
diff --git a/numpy/core/src/multiarray/common.h b/numpy/core/src/multiarray/common.h index 4b670b851..ae9b960c8 100644 --- a/numpy/core/src/multiarray/common.h +++ b/numpy/core/src/multiarray/common.h @@ -2,7 +2,6 @@ #define _NPY_PRIVATE_COMMON_H_ #include <numpy/npy_common.h> #include <numpy/npy_cpu.h> -#include <numpy/npy_3kcompat.h> #include <numpy/ndarraytypes.h> #include <limits.h> @@ -182,18 +181,6 @@ check_and_adjust_axis(int *axis, int ndim) { return check_and_adjust_axis_msg(axis, ndim, Py_None); } -static NPY_INLINE int -check_and_adjust_axis_cmsg(int *axis, int ndim, char const *cmsg) -{ - int ret; - PyObject *msg = PyUString_FromString(cmsg); - if (msg == NULL) { - return -1; - } - ret = check_and_adjust_axis_msg(axis, ndim, msg); - Py_DECREF(msg); - return ret; -} /* diff --git a/numpy/core/src/multiarray/item_selection.c b/numpy/core/src/multiarray/item_selection.c index 208b96687..eb9ef5915 100644 --- a/numpy/core/src/multiarray/item_selection.c +++ b/numpy/core/src/multiarray/item_selection.c @@ -14,6 +14,7 @@ #include "npy_pycompat.h" +#include "multiarraymodule.h" #include "common.h" #include "arrayobject.h" #include "ctors.h" @@ -1818,10 +1819,10 @@ PyArray_Diagonal(PyArrayObject *self, int offset, int axis1, int axis2) } /* Handle negative axes with standard Python indexing rules */ - if (check_and_adjust_axis_cmsg(&axis1, ndim, "axis1") < 0) { + if (check_and_adjust_axis_msg(&axis1, ndim, npy_ma_str_axis1) < 0) { return NULL; } - if (check_and_adjust_axis_cmsg(&axis2, ndim, "axis2") < 0) { + if (check_and_adjust_axis_msg(&axis2, ndim, npy_ma_str_axis2) < 0) { return NULL; } if (axis1 == axis2) { diff --git a/numpy/core/src/multiarray/multiarraymodule.c b/numpy/core/src/multiarray/multiarraymodule.c index 00ea958ef..3e322c7e2 100644 --- a/numpy/core/src/multiarray/multiarraymodule.c +++ b/numpy/core/src/multiarray/multiarraymodule.c @@ -4690,6 +4690,8 @@ NPY_VISIBILITY_HIDDEN PyObject * npy_ma_str_order = NULL; NPY_VISIBILITY_HIDDEN PyObject * npy_ma_str_copy = NULL; NPY_VISIBILITY_HIDDEN PyObject * npy_ma_str_dtype = NULL; NPY_VISIBILITY_HIDDEN PyObject * npy_ma_str_ndmin = NULL; +NPY_VISIBILITY_HIDDEN PyObject * npy_ma_str_axis1 = NULL; +NPY_VISIBILITY_HIDDEN PyObject * npy_ma_str_axis2 = NULL; static int intern_strings(void) @@ -4704,12 +4706,14 @@ intern_strings(void) npy_ma_str_copy = PyUString_InternFromString("copy"); npy_ma_str_dtype = PyUString_InternFromString("dtype"); npy_ma_str_ndmin = PyUString_InternFromString("ndmin"); + npy_ma_str_axis1 = PyUString_InternFromString("axis1"); + npy_ma_str_axis2 = PyUString_InternFromString("axis2"); return npy_ma_str_array && npy_ma_str_array_prepare && npy_ma_str_array_wrap && npy_ma_str_array_finalize && npy_ma_str_buffer && npy_ma_str_ufunc && npy_ma_str_order && npy_ma_str_copy && npy_ma_str_dtype && - npy_ma_str_ndmin; + npy_ma_str_ndmin && npy_ma_str_axis1 && npy_ma_str_axis2; } diff --git a/numpy/core/src/multiarray/multiarraymodule.h b/numpy/core/src/multiarray/multiarraymodule.h index 82ae24845..3de68c549 100644 --- a/numpy/core/src/multiarray/multiarraymodule.h +++ b/numpy/core/src/multiarray/multiarraymodule.h @@ -11,5 +11,7 @@ NPY_VISIBILITY_HIDDEN extern PyObject * npy_ma_str_order; NPY_VISIBILITY_HIDDEN extern PyObject * npy_ma_str_copy; NPY_VISIBILITY_HIDDEN extern PyObject * npy_ma_str_dtype; NPY_VISIBILITY_HIDDEN extern PyObject * npy_ma_str_ndmin; +NPY_VISIBILITY_HIDDEN extern PyObject * npy_ma_str_axis1; +NPY_VISIBILITY_HIDDEN extern PyObject * npy_ma_str_axis2; #endif diff --git a/numpy/core/src/multiarray/shape.c b/numpy/core/src/multiarray/shape.c index 21f901755..29c122bd3 100644 --- a/numpy/core/src/multiarray/shape.c +++ b/numpy/core/src/multiarray/shape.c @@ -17,6 +17,7 @@ #include "shape.h" +#include "multiarraymodule.h" /* for interned strings */ #include "templ_common.h" /* for npy_mul_with_overflow_intp */ #include "common.h" /* for convert_shape_to_string */ #include "alloc.h" @@ -648,10 +649,10 @@ PyArray_SwapAxes(PyArrayObject *ap, int a1, int a2) int n = PyArray_NDIM(ap); int i; - if (check_and_adjust_axis_cmsg(&a1, n, "axis1") < 0) { + if (check_and_adjust_axis_msg(&a1, n, npy_ma_str_axis1) < 0) { return NULL; } - if (check_and_adjust_axis_cmsg(&a2, n, "axis2") < 0) { + if (check_and_adjust_axis_msg(&a2, n, npy_ma_str_axis2) < 0) { return NULL; } |
