Conflict checking code cleanup
* Make conflict_isin() static; it is used nowhere else. * Remove does_conflict(): it turns out to be replaceable by a single call to _alpm_depcmp(). By pushing it up, we can reduce calls to _alpm_splitdep() from 60,368 to 16,940 during one test -Su operation I ran. Signed-off-by: Dan McGee <dan@archlinux.org>
This commit is contained in:
parent
d1cc1ef6c3
commit
00c393d49f
2 changed files with 13 additions and 31 deletions
|
@ -40,7 +40,8 @@
|
||||||
#include "log.h"
|
#include "log.h"
|
||||||
#include "deps.h"
|
#include "deps.h"
|
||||||
|
|
||||||
pmconflict_t *_alpm_conflict_new(const char *package1, const char *package2, const char *reason)
|
pmconflict_t *_alpm_conflict_new(const char *package1, const char *package2,
|
||||||
|
const char *reason)
|
||||||
{
|
{
|
||||||
pmconflict_t *conflict;
|
pmconflict_t *conflict;
|
||||||
|
|
||||||
|
@ -75,18 +76,18 @@ pmconflict_t *_alpm_conflict_dup(const pmconflict_t *conflict)
|
||||||
return(newconflict);
|
return(newconflict);
|
||||||
}
|
}
|
||||||
|
|
||||||
int _alpm_conflict_isin(pmconflict_t *needle, alpm_list_t *haystack)
|
static int conflict_isin(pmconflict_t *needle, alpm_list_t *haystack)
|
||||||
{
|
{
|
||||||
alpm_list_t *i;
|
alpm_list_t *i;
|
||||||
|
const char *npkg1 = needle->package1;
|
||||||
|
const char *npkg2 = needle->package2;
|
||||||
|
|
||||||
ALPM_LOG_FUNC;
|
ALPM_LOG_FUNC;
|
||||||
|
|
||||||
for(i = haystack; i; i = i->next) {
|
for(i = haystack; i; i = i->next) {
|
||||||
pmconflict_t *conflict = i->data;
|
pmconflict_t *conflict = i->data;
|
||||||
char *cpkg1 = conflict->package1;
|
const char *cpkg1 = conflict->package1;
|
||||||
char *cpkg2 = conflict->package2;
|
const char *cpkg2 = conflict->package2;
|
||||||
char *npkg1 = needle->package1;
|
|
||||||
char *npkg2 = needle->package2;
|
|
||||||
if((strcmp(cpkg1, npkg1) == 0 && strcmp(cpkg2, npkg2) == 0)
|
if((strcmp(cpkg1, npkg1) == 0 && strcmp(cpkg2, npkg2) == 0)
|
||||||
|| (strcmp(cpkg1, npkg2) == 0 && strcmp(cpkg2, npkg1) == 0)) {
|
|| (strcmp(cpkg1, npkg2) == 0 && strcmp(cpkg2, npkg1) == 0)) {
|
||||||
return(1);
|
return(1);
|
||||||
|
@ -96,28 +97,6 @@ int _alpm_conflict_isin(pmconflict_t *needle, alpm_list_t *haystack)
|
||||||
return(0);
|
return(0);
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Check if pkg1 conflicts with pkg2
|
|
||||||
* @param pkg1 package we are looking at
|
|
||||||
* @param conflict name of the possible conflict
|
|
||||||
* @param pkg2 package to check
|
|
||||||
* @return 0 for no conflict, non-zero otherwise
|
|
||||||
*/
|
|
||||||
static int does_conflict(pmpkg_t *pkg1, const char *conflict, pmpkg_t *pkg2)
|
|
||||||
{
|
|
||||||
const char *pkg1name = alpm_pkg_get_name(pkg1);
|
|
||||||
const char *pkg2name = alpm_pkg_get_name(pkg2);
|
|
||||||
pmdepend_t *conf = _alpm_splitdep(conflict);
|
|
||||||
int match = 0;
|
|
||||||
|
|
||||||
match = _alpm_depcmp(pkg2, conf);
|
|
||||||
if(match) {
|
|
||||||
_alpm_log(PM_LOG_DEBUG, "package %s conflicts with %s (by %s)\n",
|
|
||||||
pkg1name, pkg2name, conflict);
|
|
||||||
}
|
|
||||||
_alpm_dep_free(conf);
|
|
||||||
return(match);
|
|
||||||
}
|
|
||||||
|
|
||||||
/** Adds the pkg1/pkg2 conflict to the baddeps list
|
/** Adds the pkg1/pkg2 conflict to the baddeps list
|
||||||
* @param *baddeps list to add conflict to
|
* @param *baddeps list to add conflict to
|
||||||
* @param pkg1 first package
|
* @param pkg1 first package
|
||||||
|
@ -127,7 +106,9 @@ static void add_conflict(alpm_list_t **baddeps, const char *pkg1,
|
||||||
const char *pkg2, const char *reason)
|
const char *pkg2, const char *reason)
|
||||||
{
|
{
|
||||||
pmconflict_t *conflict = _alpm_conflict_new(pkg1, pkg2, reason);
|
pmconflict_t *conflict = _alpm_conflict_new(pkg1, pkg2, reason);
|
||||||
if(conflict && !_alpm_conflict_isin(conflict, *baddeps)) {
|
_alpm_log(PM_LOG_DEBUG, "package %s conflicts with %s (by %s)\n",
|
||||||
|
pkg1, pkg2, reason);
|
||||||
|
if(conflict && !conflict_isin(conflict, *baddeps)) {
|
||||||
*baddeps = alpm_list_add(*baddeps, conflict);
|
*baddeps = alpm_list_add(*baddeps, conflict);
|
||||||
} else {
|
} else {
|
||||||
_alpm_conflict_free(conflict);
|
_alpm_conflict_free(conflict);
|
||||||
|
@ -158,6 +139,7 @@ static void check_conflict(alpm_list_t *list1, alpm_list_t *list2,
|
||||||
|
|
||||||
for(j = alpm_pkg_get_conflicts(pkg1); j; j = j->next) {
|
for(j = alpm_pkg_get_conflicts(pkg1); j; j = j->next) {
|
||||||
const char *conflict = j->data;
|
const char *conflict = j->data;
|
||||||
|
pmdepend_t *parsed_conflict = _alpm_splitdep(conflict);
|
||||||
|
|
||||||
for(k = list2; k; k = k->next) {
|
for(k = list2; k; k = k->next) {
|
||||||
pmpkg_t *pkg2 = k->data;
|
pmpkg_t *pkg2 = k->data;
|
||||||
|
@ -168,7 +150,7 @@ static void check_conflict(alpm_list_t *list1, alpm_list_t *list2,
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
if(does_conflict(pkg1, conflict, pkg2)) {
|
if(_alpm_depcmp(pkg2, parsed_conflict)) {
|
||||||
if(order >= 0) {
|
if(order >= 0) {
|
||||||
add_conflict(baddeps, pkg1name, pkg2name, conflict);
|
add_conflict(baddeps, pkg1name, pkg2name, conflict);
|
||||||
} else {
|
} else {
|
||||||
|
@ -176,6 +158,7 @@ static void check_conflict(alpm_list_t *list1, alpm_list_t *list2,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
_alpm_dep_free(parsed_conflict);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -40,7 +40,6 @@ struct __pmfileconflict_t {
|
||||||
pmconflict_t *_alpm_conflict_new(const char *package1, const char *package2, const char *reason);
|
pmconflict_t *_alpm_conflict_new(const char *package1, const char *package2, const char *reason);
|
||||||
pmconflict_t *_alpm_conflict_dup(const pmconflict_t *conflict);
|
pmconflict_t *_alpm_conflict_dup(const pmconflict_t *conflict);
|
||||||
void _alpm_conflict_free(pmconflict_t *conflict);
|
void _alpm_conflict_free(pmconflict_t *conflict);
|
||||||
int _alpm_conflict_isin(pmconflict_t *needle, alpm_list_t *haystack);
|
|
||||||
alpm_list_t *_alpm_innerconflicts(alpm_list_t *packages);
|
alpm_list_t *_alpm_innerconflicts(alpm_list_t *packages);
|
||||||
alpm_list_t *_alpm_outerconflicts(pmdb_t *db, alpm_list_t *packages);
|
alpm_list_t *_alpm_outerconflicts(pmdb_t *db, alpm_list_t *packages);
|
||||||
alpm_list_t *_alpm_db_find_fileconflicts(pmdb_t *db, pmtrans_t *trans,
|
alpm_list_t *_alpm_db_find_fileconflicts(pmdb_t *db, pmtrans_t *trans,
|
||||||
|
|
Loading…
Add table
Reference in a new issue