Linux Archive

Linux Archive (http://www.linux-archive.org/)
-   ArchLinux Pacman Development (http://www.linux-archive.org/archlinux-pacman-development/)
-   -   lib/conflict: use a binary search within filelists (http://www.linux-archive.org/archlinux-pacman-development/683000-lib-conflict-use-binary-search-within-filelists.html)

Dave Reisner 07-12-2012 05:18 PM

lib/conflict: use a binary search within filelists
 
Take advantage of the fact that our filelists are arrays sorted by
filename with a known length and use a binary search. This should speed
up file conflict checking, particularly when larger packages are
involved.

Signed-off-by: Dave Reisner <dreisner@archlinux.org>
---
lib/libalpm/conflict.c | 13 +++++--------
1 file changed, 5 insertions(+), 8 deletions(-)

diff --git a/lib/libalpm/conflict.c b/lib/libalpm/conflict.c
index 7494fd7..fd4eff1 100644
--- a/lib/libalpm/conflict.c
+++ b/lib/libalpm/conflict.c
@@ -315,19 +315,16 @@ void _alpm_fileconflict_free(alpm_fileconflict_t *conflict)
const alpm_file_t *_alpm_filelist_contains(alpm_filelist_t *filelist,
const char *name)
{
- size_t i;
- const alpm_file_t *file;
+ alpm_file_t key;

if(!filelist) {
return NULL;
}

- for(file = filelist->files, i = 0; i < filelist->count; file++, i++) {
- if(strcmp(file->name, name) == 0) {
- return file;
- }
- }
- return NULL;
+ key.name = (char *)name;
+
+ return bsearch(&key, filelist->files, filelist->count,
+ sizeof(alpm_file_t), _alpm_files_cmp);
}

static int dir_belongsto_pkg(alpm_handle_t *handle, const char *dirpath,
--
1.7.11.1


All times are GMT. The time now is 05:36 AM.

VBulletin, Copyright ©2000 - 2014, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO ©2007, Crawlability, Inc.