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> Signed-off-by: Dan McGee <dan@archlinux.org>
This commit is contained in:
parent
c5e7eeece7
commit
35ac4e7ef3
@ -315,19 +315,16 @@ void _alpm_fileconflict_free(alpm_fileconflict_t *conflict)
|
|||||||
const alpm_file_t *_alpm_filelist_contains(alpm_filelist_t *filelist,
|
const alpm_file_t *_alpm_filelist_contains(alpm_filelist_t *filelist,
|
||||||
const char *name)
|
const char *name)
|
||||||
{
|
{
|
||||||
size_t i;
|
alpm_file_t key;
|
||||||
const alpm_file_t *file;
|
|
||||||
|
|
||||||
if(!filelist) {
|
if(!filelist) {
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
for(file = filelist->files, i = 0; i < filelist->count; file++, i++) {
|
key.name = (char *)name;
|
||||||
if(strcmp(file->name, name) == 0) {
|
|
||||||
return file;
|
return bsearch(&key, filelist->files, filelist->count,
|
||||||
}
|
sizeof(alpm_file_t), _alpm_files_cmp);
|
||||||
}
|
|
||||||
return NULL;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static int dir_belongsto_pkg(alpm_handle_t *handle, const char *dirpath,
|
static int dir_belongsto_pkg(alpm_handle_t *handle, const char *dirpath,
|
||||||
|
Loading…
Reference in New Issue
Block a user