Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit c176234

Browse files
committed
ENH: Use memcpy and swap order
Not sure this makes a difference, but we check for memory overlap so `memmov` isn't necessary and if the compiler keeps the order intact, we want the `memcpy` path to be the hot one.
1 parent 74979f3 commit c176234

File tree

1 file changed

+5
-4
lines changed

1 file changed

+5
-4
lines changed

numpy/core/src/multiarray/item_selection.c

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1088,16 +1088,17 @@ PyArray_Choose(PyArrayObject *ip, PyObject *op, PyArrayObject *out,
10881088
break;
10891089
}
10901090
}
1091-
if (cast_info.func != NULL) {
1091+
if (cast_info.func == NULL) {
1092+
/* We ensure memory doesn't overlap, so can use memcpy */
1093+
memcpy(ret_data, PyArray_MultiIter_DATA(multi, mi), elsize);
1094+
}
1095+
else {
10921096
char *args[2] = {PyArray_MultiIter_DATA(multi, mi), ret_data};
10931097
if (cast_info.func(&cast_info.context, args, &one,
10941098
transfer_strides, cast_info.auxdata) < 0) {
10951099
goto fail;
10961100
}
10971101
}
1098-
else {
1099-
memmove(ret_data, PyArray_MultiIter_DATA(multi, mi), elsize);
1100-
}
11011102
ret_data += elsize;
11021103
PyArray_MultiIter_NEXT(multi);
11031104
}

0 commit comments

Comments
 (0)