8000 PERF: Statically allocate unicode strings of memhandler by eendebakpt · Pull Request #21450 · numpy/numpy · GitHub
[go: up one dir, main page]

Skip to content

PERF: Statically allocate unicode strings of memhandler #21450

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
May 5, 2022
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

8000
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8000
Next Next commit
PERF Statically allocate unicode strings
  • Loading branch information
eendebakpt committed May 5, 2022
commit d08f24e677d96245d10ceb634ef17f124c0d3a31
2 changes: 1 addition & 1 deletion numpy/core/src/multiarray/alloc.c
Original file line number Diff line number Diff line change
Expand Up @@ -576,7 +576,7 @@ PyDataMem_GetHandler()
if (p == NULL) {
return NULL;
}
handler = PyDict_GetItemString(p, "current_allocator");
handler = PyDict_GetItem(p, npy_ma_str_current_allocator);
if (handler == NULL) {
handler = PyCapsule_New(&default_handler, "mem_handler", NULL);
if (handler == NULL) {
Expand Down
5 changes: 5 additions & 0 deletions numpy/core/src/multiarray/multiarraymodule.c
Original file line number Diff line number Diff line change
Expand Up @@ -4665,6 +4665,7 @@ set_flaginfo(PyObject *d)
return;
}

NPY_VISIBILITY_HIDDEN PyObject * npy_ma_str_current_allocator = NULL;
NPY_VISIBILITY_HIDDEN PyObject * npy_ma_str_array = NULL;
NPY_VISIBILITY_HIDDEN PyObject * npy_ma_str_array_function = NULL;
NPY_VISIBILITY_HIDDEN PyObject * npy_ma_str_array_struct = NULL;
Expand All @@ -4681,6 +4682,10 @@ NPY_VISIBILITY_HIDDEN PyObject * npy_ma_str_numpy = NULL;
static int
intern_strings(void)
{
npy_ma_str_current_allocator = PyUnicode_InternFromString("npy_ma_str_current_allocator");
if (npy_ma_str_current_allocator == NULL) {
return -1;
}
npy_ma_str_array = PyUnicode_InternFromString("__array__");
if (npy_ma_str_array == NULL) {
return -1;
Expand Down
1 change: 1 addition & 0 deletions numpy/core/src/multiarray/multiarraymodule.h
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#ifndef NUMPY_CORE_SRC_MULTIARRAY_MULTIARRAYMODULE_H_
#define NUMPY_CORE_SRC_MULTIARRAY_MULTIARRAYMODULE_H_

NPY_VISIBILITY_HIDDEN extern PyObject * npy_ma_str_current_allocator;
NPY_VISIBILITY_HIDDEN extern PyObject * npy_ma_str_array;
NPY_VISIBILITY_HIDDEN extern PyObject * npy_ma_str_array_function;
NPY_VISIBILITY_HIDDEN extern PyObject * npy_ma_str_array_struct;
Expand Down
0