| 220 | */ |
| 221 | template <typename Tag, typename type> |
| 222 | static void |
| 223 | merge_right_(type *p1, npy_intp l1, type *p2, npy_intp l2, type *p3) |
| 224 | { |
| 225 | npy_intp ofs; |
| 226 | type *start = p1 - 1; |
| 227 | memcpy(p3, p2, sizeof(type) * l2); |
| 228 | p1 += l1 - 1; |
| 229 | p2 += l2 - 1; |
| 230 | p3 += l2 - 1; |
| 231 | /* first element must be in p1 otherwise skipped in the caller */ |
| 232 | *p2-- = *p1--; |
| 233 | |
| 234 | while (p1 < p2 && start < p1) { |
| 235 | if (Tag::less(*p3, *p1)) { |
| 236 | *p2-- = *p1--; |
| 237 | } |
| 238 | else { |
| 239 | *p2-- = *p3--; |
| 240 | } |
| 241 | } |
| 242 | |
| 243 | if (p1 != p2) { |
| 244 | ofs = p2 - start; |
| 245 | memcpy(start + 1, p3 - ofs + 1, sizeof(type) * ofs); |
| 246 | } |
| 247 | } |
| 248 | |
| 249 | /* Note: the naming convention of gallop functions are different from that of |
| 250 | * CPython. For example, here gallop_right means gallop from left toward right, |