summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--src/mergesort.c13
1 files changed, 7 insertions, 6 deletions
diff --git a/src/mergesort.c b/src/mergesort.c
index 7391544..883d8ba 100644
--- a/src/mergesort.c
+++ b/src/mergesort.c
@@ -1,6 +1,6 @@
/* SPDX-License-Identifier: LGPL-2.1-only */
-/* Copyright (C) 2020 Gediminas Jakutis */
+/* Copyright (C) 2020-2021 Gediminas Jakutis */
#include <errno.h>
#include <stdlib.h>
@@ -16,7 +16,6 @@ int merge_sort(struct stream * const src, struct stream * const dest)
{
int ret = 0;
struct stream tmp[4] = {0}; /* I can't into stream reuse, hence four. A yeet, followed by a dab. */
- size_t i;
try(!src || !dest, err, EINVAL, "cannot sort what's not there");
@@ -29,10 +28,12 @@ int merge_sort(struct stream * const src, struct stream * const dest)
merge(dest, tmp + 1, tmp + 3); /* merge the two halves back */
dest->rewind(dest);
- for (i = 0; i < (sizeof(tmp) / sizeof(*tmp)); ++i) {
- stream_close(tmp + i);
- }
- } else { /* stream of size one is inherently sorted, simply src with dest */
+ /* you can't spell -funroll-loops without fun, wee~! */
+ stream_close(tmp);
+ stream_close(tmp + 1);
+ stream_close(tmp + 2);
+ stream_close(tmp + 3);
+ } else { /* stream of size one is inherently sorted, simply swap src with dest */
*tmp = *dest;
*dest = *src;
*src = *tmp;