[pacman-dev] [PATCH 5/5] filelist_sort: check if filelist is presorted
Andrew Gregory
andrew.gregory.8 at gmail.com
Fri Dec 9 16:14:07 UTC 2016
Signed-off-by: Andrew Gregory <andrew.gregory.8 at gmail.com>
---
This patch obviously won't do any good until packages start being built with
their file lists presorted, so we may want to defer it, but in the handful of
packages I tested, it did not cause a significant delay either.
lib/libalpm/filelist.c | 11 +++++++++--
1 file changed, 9 insertions(+), 2 deletions(-)
diff --git a/lib/libalpm/filelist.c b/lib/libalpm/filelist.c
index 318b2b7..f6fdf37 100644
--- a/lib/libalpm/filelist.c
+++ b/lib/libalpm/filelist.c
@@ -135,8 +135,15 @@ alpm_file_t SYMEXPORT *alpm_filelist_contains(alpm_filelist_t *filelist,
void _alpm_filelist_sort(alpm_filelist_t *filelist)
{
- qsort(filelist->files, filelist->count,
- sizeof(alpm_file_t), _alpm_files_cmp);
+ size_t i;
+ for(i = 1; i < filelist->count; i++) {
+ if(strcmp(filelist->files[i - 1].name, filelist->files[i].name) > 0) {
+ /* filelist is not pre-sorted */
+ qsort(filelist->files, filelist->count,
+ sizeof(alpm_file_t), _alpm_files_cmp);
+ return;
+ }
+ }
}
/* vim: set noet: */
--
2.10.2
More information about the pacman-dev
mailing list