From 361c1a693c50e42df849f5d68642552d4a99aa4a Mon Sep 17 00:00:00 2001 From: Gediminas Jakutis Date: Thu, 25 Feb 2021 17:18:33 +0200 Subject: apply -funroll-loops on the mergesort algo. Signed-off-by: Gediminas Jakutis --- src/mergesort.c | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) (limited to 'src/mergesort.c') 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 #include @@ -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; -- cgit v1.2.3