| 3442 | D. A. Bell, Comp J. 1 (1958), 75. */ |
| 3443 | |
| 3444 | static void |
| 3445 | sequential_sort (struct line *restrict lines, size_t nlines, |
| 3446 | struct line *restrict temp, bool to_temp) |
| 3447 | { |
| 3448 | if (nlines == 2) |
| 3449 | { |
| 3450 | /* Declare 'swap' as int, not bool, to work around a bug |
| 3451 | <https://lists.gnu.org/r/bug-coreutils/2005-10/msg00086.html> |
| 3452 | in the IBM xlc 6.0.0.0 compiler in 64-bit mode. */ |
| 3453 | int swap = (0 < compare (&lines[-1], &lines[-2])); |
| 3454 | if (to_temp) |
| 3455 | { |
| 3456 | temp[-1] = lines[-1 - swap]; |
| 3457 | temp[-2] = lines[-2 + swap]; |
| 3458 | } |
| 3459 | else if (swap) |
| 3460 | { |
| 3461 | temp[-1] = lines[-1]; |
| 3462 | lines[-1] = lines[-2]; |
| 3463 | lines[-2] = temp[-1]; |
| 3464 | } |
| 3465 | } |
| 3466 | else |
| 3467 | { |
| 3468 | size_t nlo = nlines / 2; |
| 3469 | size_t nhi = nlines - nlo; |
| 3470 | struct line *lo = lines; |
| 3471 | struct line *hi = lines - nlo; |
| 3472 | |
| 3473 | sequential_sort (hi, nhi, temp - (to_temp ? nlo : 0), to_temp); |
| 3474 | if (1 < nlo) |
| 3475 | sequential_sort (lo, nlo, temp, !to_temp); |
| 3476 | else if (!to_temp) |
| 3477 | temp[-1] = lo[-1]; |
| 3478 | |
| 3479 | struct line *dest; |
| 3480 | struct line const *sorted_lo; |
| 3481 | if (to_temp) |
| 3482 | { |
| 3483 | dest = temp; |
| 3484 | sorted_lo = lines; |
| 3485 | } |
| 3486 | else |
| 3487 | { |
| 3488 | dest = lines; |
| 3489 | sorted_lo = temp; |
| 3490 | } |
| 3491 | mergelines (dest, nlines, sorted_lo); |
| 3492 | } |
| 3493 | } |
| 3494 | |
| 3495 | static struct merge_node *init_node (struct merge_node *restrict, |
| 3496 | struct merge_node *restrict, |
no test coverage detected