From 00c393d49ff77bb85397278b8f4bd89450402806 Mon Sep 17 00:00:00 2001 From: Dan McGee Date: Wed, 16 Feb 2011 19:10:53 -0600 Subject: 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 --- lib/libalpm/conflict.c | 43 +++++++++++++------------------------------ lib/libalpm/conflict.h | 1 - 2 files changed, 13 insertions(+), 31 deletions(-) (limited to 'lib') diff --git a/lib/libalpm/conflict.c b/lib/libalpm/conflict.c index ca15dbe3..8fda7a7b 100644 --- a/lib/libalpm/conflict.c +++ b/lib/libalpm/conflict.c @@ -40,7 +40,8 @@ #include "log.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; @@ -75,18 +76,18 @@ pmconflict_t *_alpm_conflict_dup(const pmconflict_t *conflict) 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; + const char *npkg1 = needle->package1; + const char *npkg2 = needle->package2; ALPM_LOG_FUNC; for(i = haystack; i; i = i->next) { pmconflict_t *conflict = i->data; - char *cpkg1 = conflict->package1; - char *cpkg2 = conflict->package2; - char *npkg1 = needle->package1; - char *npkg2 = needle->package2; + const char *cpkg1 = conflict->package1; + const char *cpkg2 = conflict->package2; if((strcmp(cpkg1, npkg1) == 0 && strcmp(cpkg2, npkg2) == 0) || (strcmp(cpkg1, npkg2) == 0 && strcmp(cpkg2, npkg1) == 0)) { return(1); @@ -96,28 +97,6 @@ int _alpm_conflict_isin(pmconflict_t *needle, alpm_list_t *haystack) 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 * @param *baddeps list to add conflict to * @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) { 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); } else { _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) { const char *conflict = j->data; + pmdepend_t *parsed_conflict = _alpm_splitdep(conflict); for(k = list2; k; k = k->next) { pmpkg_t *pkg2 = k->data; @@ -168,7 +150,7 @@ static void check_conflict(alpm_list_t *list1, alpm_list_t *list2, continue; } - if(does_conflict(pkg1, conflict, pkg2)) { + if(_alpm_depcmp(pkg2, parsed_conflict)) { if(order >= 0) { add_conflict(baddeps, pkg1name, pkg2name, conflict); } else { @@ -176,6 +158,7 @@ static void check_conflict(alpm_list_t *list1, alpm_list_t *list2, } } } + _alpm_dep_free(parsed_conflict); } } } diff --git a/lib/libalpm/conflict.h b/lib/libalpm/conflict.h index 09b4f99b..418d3f61 100644 --- a/lib/libalpm/conflict.h +++ b/lib/libalpm/conflict.h @@ -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_dup(const 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_outerconflicts(pmdb_t *db, alpm_list_t *packages); alpm_list_t *_alpm_db_find_fileconflicts(pmdb_t *db, pmtrans_t *trans, -- cgit v1.2.3-24-g4f1b