From 9caccbfec112c53133aff09119eda623ae0644fe Mon Sep 17 00:00:00 2001
From: David Oberhollenzer <david.oberhollenzer@sigma-star.at>
Date: Sat, 29 Apr 2023 00:23:27 +0200
Subject: gensquashfs: simplify sort_file_list

Signed-off-by: David Oberhollenzer <david.oberhollenzer@sigma-star.at>
---
 bin/gensquashfs/src/sort_by_file.c | 48 ++++++++++++++++----------------------
 1 file changed, 20 insertions(+), 28 deletions(-)

(limited to 'bin/gensquashfs')

diff --git a/bin/gensquashfs/src/sort_by_file.c b/bin/gensquashfs/src/sort_by_file.c
index a1aacc0..023dfb5 100644
--- a/bin/gensquashfs/src/sort_by_file.c
+++ b/bin/gensquashfs/src/sort_by_file.c
@@ -211,40 +211,32 @@ static void sort_file_list(fstree_t *fs)
 	tree_node_t *out = NULL, *out_last = NULL;
 
 	while (fs->files != NULL) {
-		sqfs_s64 lowest = fs->files->data.file.priority;
-		tree_node_t *it, *prev;
-
-		for (it = fs->files; it != NULL; it = it->next_by_type) {
-			if (it->data.file.priority < lowest)
-				lowest = it->data.file.priority;
-		}
-
-		it = fs->files;
-		prev = NULL;
+		tree_node_t *low = fs->files, *low_prev = NULL;
+		tree_node_t *it = low->next_by_type, *prev = low;
 
 		while (it != NULL) {
-			if (it->data.file.priority != lowest) {
-				prev = it;
-				it = it->next_by_type;
-				continue;
-			}
-
-			if (prev == NULL) {
-				fs->files = it->next_by_type;
-			} else {
-				prev->next_by_type = it->next_by_type;
+			if (it->data.file.priority < low->data.file.priority) {
+				low = it;
+				low_prev = prev;
 			}
+			prev = it;
+			it = it->next_by_type;
+		}
 
-			if (out == NULL) {
-				out = it;
-			} else {
-				out_last->next_by_type = it;
-			}
+		if (low_prev == NULL) {
+			fs->files = low->next_by_type;
+		} else {
+			low_prev->next_by_type = low->next_by_type;
+		}
 
-			out_last = it;
-			it = it->next_by_type;
-			out_last->next_by_type = NULL;
+		if (out == NULL) {
+			out = low;
+		} else {
+			out_last->next_by_type = low;
 		}
+
+		out_last = low;
+		low->next_by_type = NULL;
 	}
 
 	fs->files = out;
-- 
cgit v1.2.3