diff options
author | 2021-02-25 17:18:33 +0200 | |
---|---|---|
committer | 2021-02-25 17:18:33 +0200 | |
commit | 361c1a693c50e42df849f5d68642552d4a99aa4a (patch) | |
tree | 387ed390946104afa3b26b6ed83541c9d2aad1e4 /src | |
parent | 4f203f855ed6e950197f9b241d4d40fcfda5f52d (diff) | |
download | algos-ld1-361c1a693c50e42df849f5d68642552d4a99aa4a.tar.gz algos-ld1-361c1a693c50e42df849f5d68642552d4a99aa4a.tar.bz2 algos-ld1-361c1a693c50e42df849f5d68642552d4a99aa4a.zip |
apply -funroll-loops on the mergesort algo.
Signed-off-by: Gediminas Jakutis <gediminas@varciai.lt>
Diffstat (limited to 'src')
-rw-r--r-- | src/mergesort.c | 13 |
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; |