| 2518 | } |
| 2519 | |
| 2520 | static void |
| 2521 | npy_amerge_right(char *arr, npy_intp *p1, npy_intp l1, npy_intp *p2, |
| 2522 | npy_intp l2, npy_intp *p3, size_t len, |
| 2523 | PyArray_CompareFunc *cmp, PyArrayObject *py_arr) |
| 2524 | { |
| 2525 | npy_intp ofs; |
| 2526 | npy_intp *start = p1 - 1; |
| 2527 | memcpy(p3, p2, sizeof(npy_intp) * l2); |
| 2528 | p1 += l1 - 1; |
| 2529 | p2 += l2 - 1; |
| 2530 | p3 += l2 - 1; |
| 2531 | /* first element must be in p1 otherwise skipped in the caller */ |
| 2532 | *p2-- = *p1--; |
| 2533 | |
| 2534 | while (p1 < p2 && start < p1) { |
| 2535 | if (cmp(arr + (*p3) * len, arr + (*p1) * len, py_arr) < 0) { |
| 2536 | *p2-- = *p1--; |
| 2537 | } |
| 2538 | else { |
| 2539 | *p2-- = *p3--; |
| 2540 | } |
| 2541 | } |
| 2542 | |
| 2543 | if (p1 != p2) { |
| 2544 | ofs = p2 - start; |
| 2545 | memcpy(start + 1, p3 - ofs + 1, sizeof(npy_intp) * ofs); |
| 2546 | } |
| 2547 | } |
| 2548 | |
| 2549 | static int |
| 2550 | npy_amerge_at(char *arr, npy_intp *tosort, const run *stack, const npy_intp at, |