[pacman-dev] [PATCH] Kill compute_requiredby usage in deps.c/can_remove_package()
From 5b83eec6d87dc43a1f9dface9540220d8188edcf Mon Sep 17 00:00:00 2001 From: Nagy Gabor <ngaba@bibl.u-szeged.hu> Date: Sun, 20 Apr 2008 00:39:32 +0200 Subject: [PATCH] Kill compute_requiredby usage in deps.c/can_remove_package() After this patch compute_requiredby is used nowhere in back-end, so it can be optimized for front-end. * Before this patch the db param wasn't used, db == localdb was supposed * This is a minor speed-up, since we needn't calculate the whole requiredby list, if we find an ,,external'' member Signed-off-by: Nagy Gabor <ngaba@bibl.u-szeged.hu> --- lib/libalpm/deps.c | 20 +++++++++++--------- 1 files changed, 11 insertions(+), 9 deletions(-) diff --git a/lib/libalpm/deps.c b/lib/libalpm/deps.c index 1eebca3..4216e2c 100644 --- a/lib/libalpm/deps.c +++ b/lib/libalpm/deps.c @@ -439,7 +439,7 @@ pmdepend_t *_alpm_dep_dup(const pmdepend_t *dep) static int can_remove_package(pmdb_t *db, pmpkg_t *pkg, alpm_list_t *targets, int include_explicit) { - alpm_list_t *i, *requiredby; + alpm_list_t *i, *j; if(_alpm_pkg_find(alpm_pkg_get_name(pkg), targets)) { return(0); @@ -461,15 +461,17 @@ static int can_remove_package(pmdb_t *db, pmpkg_t *pkg, alpm_list_t *targets, * if checkdeps detected it would break something */ /* see if other packages need it */ - requiredby = alpm_pkg_compute_requiredby(pkg); - for(i = requiredby; i; i = i->next) { - pmpkg_t *reqpkg = _alpm_db_get_pkgfromcache(db, i->data); - if(reqpkg && !_alpm_pkg_find(alpm_pkg_get_name(reqpkg), targets)) { - FREELIST(requiredby); - return(0); - } + for(i = _alpm_db_get_pkgcache(db); i; i = i->next) { + pmpkg_t *lpkg = i->data; + for(j = alpm_pkg_get_depends(lpkg); j; j = j->next) { + if(alpm_depcmp(pkg, j->data)) { + if(!_alpm_pkg_find(lpkg->name, targets)) { + return(0); + } + break; + } + } } - FREELIST(requiredby); /* it's ok to remove */ return(1); -- 1.5.3.8
Comments inline. On Sat, Apr 19, 2008 at 5:49 PM, Nagy Gabor <ngaba@bibl.u-szeged.hu> wrote:
From 5b83eec6d87dc43a1f9dface9540220d8188edcf Mon Sep 17 00:00:00 2001 From: Nagy Gabor <ngaba@bibl.u-szeged.hu> Date: Sun, 20 Apr 2008 00:39:32 +0200 Subject: [PATCH] Kill compute_requiredby usage in deps.c/can_remove_package()
After this patch compute_requiredby is used nowhere in back-end, so it can be optimized for front-end. * Before this patch the db param wasn't used, db == localdb was supposed In reality, we would never do this on anything but the localdb, correct? Can we remove the param entirely?
* This is a minor speed-up, since we needn't calculate the whole requiredby list, if we find an ,,external'' member I have no idea what you mean by ,,external" member. Especially with
We really should go through the whole backend and stop passing pointers to the localdb around- I believe we have it always accessible on the handle. Of course, whether that is the best method is up for discussion too. the commas and unmatched quotes. Can you explain?
Signed-off-by: Nagy Gabor <ngaba@bibl.u-szeged.hu> --- lib/libalpm/deps.c | 20 +++++++++++--------- 1 files changed, 11 insertions(+), 9 deletions(-)
diff --git a/lib/libalpm/deps.c b/lib/libalpm/deps.c index 1eebca3..4216e2c 100644 --- a/lib/libalpm/deps.c +++ b/lib/libalpm/deps.c @@ -439,7 +439,7 @@ pmdepend_t *_alpm_dep_dup(const pmdepend_t *dep) static int can_remove_package(pmdb_t *db, pmpkg_t *pkg, alpm_list_t *targets, int include_explicit) { - alpm_list_t *i, *requiredby; + alpm_list_t *i, *j;
if(_alpm_pkg_find(alpm_pkg_get_name(pkg), targets)) { return(0); @@ -461,15 +461,17 @@ static int can_remove_package(pmdb_t *db, pmpkg_t *pkg, alpm_list_t *targets, * if checkdeps detected it would break something */
/* see if other packages need it */ - requiredby = alpm_pkg_compute_requiredby(pkg); - for(i = requiredby; i; i = i->next) { - pmpkg_t *reqpkg = _alpm_db_get_pkgfromcache(db, i->data); - if(reqpkg && !_alpm_pkg_find(alpm_pkg_get_name(reqpkg), targets)) { - FREELIST(requiredby); - return(0); - } + for(i = _alpm_db_get_pkgcache(db); i; i = i->next) { + pmpkg_t *lpkg = i->data; + for(j = alpm_pkg_get_depends(lpkg); j; j = j->next) { + if(alpm_depcmp(pkg, j->data)) { + if(!_alpm_pkg_find(lpkg->name, targets)) { + return(0); + } + break; + } + } } - FREELIST(requiredby);
/* it's ok to remove */ return(1); -- 1.5.3.8
I like the patch though- the code changes are great and straightforward, so I'll pull this on a resubmit. -Dan
Comments inline.
From 5b83eec6d87dc43a1f9dface9540220d8188edcf Mon Sep 17 00:00:00 2001 From: Nagy Gabor <ngaba@bibl.u-szeged.hu> Date: Sun, 20 Apr 2008 00:39:32 +0200 Subject: [PATCH] Kill compute_requiredby usage in deps.c/can_remove_package()
After this patch compute_requiredby is used nowhere in back-end, so it can be optimized for front-end. * Before this patch the db param wasn't used, db == localdb was supposed In reality, we would never do this on anything but the localdb, correct? Can we remove the param entirely? We really should go through the whole backend and stop passing
On Sat, Apr 19, 2008 at 5:49 PM, Nagy Gabor <ngaba@bibl.u-szeged.hu> wrote: pointers to the localdb around- I believe we have it always accessible on the handle. Of course, whether that is the best method is up for discussion too.
Correct. But in deps.c almost all functions have these pointers.
* This is a minor speed-up, since we needn't calculate the whole requiredby list, if we find an ,,external'' member I have no idea what you mean by ,,external" member. Especially with the commas and unmatched quotes. Can you explain?
Oops, ,,quote'' is the Hungarian "quote", sorry (in TeX style). External refers to external member of requiredby list, which means package not in 'targets' list. So we needn't calculate the whole requiredby list (sometimes), we can stop if we find a package with that property.
Signed-off-by: Nagy Gabor <ngaba@bibl.u-szeged.hu> --- lib/libalpm/deps.c | 20 +++++++++++--------- 1 files changed, 11 insertions(+), 9 deletions(-)
diff --git a/lib/libalpm/deps.c b/lib/libalpm/deps.c index 1eebca3..4216e2c 100644 --- a/lib/libalpm/deps.c +++ b/lib/libalpm/deps.c @@ -439,7 +439,7 @@ pmdepend_t *_alpm_dep_dup(const pmdepend_t *dep) static int can_remove_package(pmdb_t *db, pmpkg_t *pkg, alpm_list_t *targets, int include_explicit) { - alpm_list_t *i, *requiredby; + alpm_list_t *i, *j;
if(_alpm_pkg_find(alpm_pkg_get_name(pkg), targets)) { return(0); @@ -461,15 +461,17 @@ static int can_remove_package(pmdb_t *db, pmpkg_t *pkg, alpm_list_t *targets, * if checkdeps detected it would break something */
/* see if other packages need it */ - requiredby = alpm_pkg_compute_requiredby(pkg); - for(i = requiredby; i; i = i->next) { - pmpkg_t *reqpkg = _alpm_db_get_pkgfromcache(db, i->data); - if(reqpkg && !_alpm_pkg_find(alpm_pkg_get_name(reqpkg), targets)) { - FREELIST(requiredby); - return(0); - } + for(i = _alpm_db_get_pkgcache(db); i; i = i->next) { + pmpkg_t *lpkg = i->data; + for(j = alpm_pkg_get_depends(lpkg); j; j = j->next) { + if(alpm_depcmp(pkg, j->data)) { + if(!_alpm_pkg_find(lpkg->name, targets)) { + return(0); + } + break; + } + } } - FREELIST(requiredby);
/* it's ok to remove */ return(1); -- 1.5.3.8
I like the patch though- the code changes are great and straightforward, so I'll pull this on a resubmit.
What shall I change? The commit message? Bye
On Mon, Apr 21, 2008 at 10:45 AM, Nagy Gabor <ngaba@bibl.u-szeged.hu> wrote:
Correct. But in deps.c almost all functions have these pointers.
Oops, ,,quote'' is the Hungarian "quote", sorry (in TeX style). External refers to external member of requiredby list, which means package not in 'targets' list. So we needn't calculate the whole requiredby list (sometimes), we can stop if we find a package with that property.
What shall I change? The commit message?
I am not sure what Dan wanted, but my suggestion would be to keep the patch as is, and change the commit message to something like this : "In the can_remove_package function, we don't need to compute the whole requiredby list, we just need to find one member of it that doesn't belong to the targets list. That way we get a small speedup and remove the only usage of alpm_pkg_compute_requiredby in the backend, so that it can be tweaked for frontend usage." Then someone could do a separate patch that removes all the useless db param from deps.c for example, if that is a good idea.
From 7a390333be1b3ab5644c4e39d98538e32ee3e3ec Mon Sep 17 00:00:00 2001 From: Nagy Gabor <ngaba@bibl.u-szeged.hu> Date: Mon, 21 Apr 2008 12:16:15 +0200 Subject: [PATCH] Kill compute_requiredby usage in deps.c/can_remove_package() In the can_remove_package function, we don't need to compute the whole requiredby list, we just need to find one member of it that doesn't belong to the targets list. That way we get a small speedup and remove the only usage of alpm_pkg_compute_requiredby in the backend, so that it can be tweaked for frontend usage. Signed-off-by: Nagy Gabor <ngaba@bibl.u-szeged.hu> --- lib/libalpm/deps.c | 20 +++++++++++--------- 1 files changed, 11 insertions(+), 9 deletions(-) diff --git a/lib/libalpm/deps.c b/lib/libalpm/deps.c index 1eebca3..4216e2c 100644 --- a/lib/libalpm/deps.c +++ b/lib/libalpm/deps.c @@ -439,7 +439,7 @@ pmdepend_t *_alpm_dep_dup(const pmdepend_t *dep) static int can_remove_package(pmdb_t *db, pmpkg_t *pkg, alpm_list_t *targets, int include_explicit) { - alpm_list_t *i, *requiredby; + alpm_list_t *i, *j; if(_alpm_pkg_find(alpm_pkg_get_name(pkg), targets)) { return(0); @@ -461,15 +461,17 @@ static int can_remove_package(pmdb_t *db, pmpkg_t *pkg, alpm_list_t *targets, * if checkdeps detected it would break something */ /* see if other packages need it */ - requiredby = alpm_pkg_compute_requiredby(pkg); - for(i = requiredby; i; i = i->next) { - pmpkg_t *reqpkg = _alpm_db_get_pkgfromcache(db, i->data); - if(reqpkg && !_alpm_pkg_find(alpm_pkg_get_name(reqpkg), targets)) { - FREELIST(requiredby); - return(0); - } + for(i = _alpm_db_get_pkgcache(db); i; i = i->next) { + pmpkg_t *lpkg = i->data; + for(j = alpm_pkg_get_depends(lpkg); j; j = j->next) { + if(alpm_depcmp(pkg, j->data)) { + if(!_alpm_pkg_find(lpkg->name, targets)) { + return(0); + } + break; + } + } } - FREELIST(requiredby); /* it's ok to remove */ return(1); -- 1.5.3.8
participants (3)
-
Dan McGee
-
Nagy Gabor
-
Xavier