From 7a43c6fee0c76e66bcc4b67e545fb18331321ba9 Mon Sep 17 00:00:00 2001 From: morganamilo Date: Sat, 3 Feb 2024 13:16:24 +0000 Subject: [PATCH] Speedup comparing lists if they happen to be in the same order --- lib/libalpm/alpm_list.c | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/lib/libalpm/alpm_list.c b/lib/libalpm/alpm_list.c index ed736c71..bd012acc 100644 --- a/lib/libalpm/alpm_list.c +++ b/lib/libalpm/alpm_list.c @@ -525,6 +525,15 @@ int SYMEXPORT alpm_list_cmp_unsorted(const alpm_list_t *left, return 0; } + /* faster comparison for if the lists happen to be in the same order */ + while(left && fn(left->data, right->data) == 0) { + left = left->next; + right = right->next; + } + if(!left) { + return 1; + } + matched = calloc(alpm_list_count(right), sizeof(int)); for(l = left; l; l = l->next) {