mirror of
https://github.com/moparisthebest/pacman
synced 2024-08-13 17:03:46 -04:00
Reduce calls to list_count() in removing package
We don't need to count the number of packages left once per file when removing; we only need to do it once per package. Also move a variable into the correct scope. Signed-off-by: Dan McGee <dan@archlinux.org>
This commit is contained in:
parent
3bc8c28ce3
commit
6e312220ec
@ -379,6 +379,7 @@ int _alpm_remove_packages(pmtrans_t *trans, pmdb_t *db)
|
|||||||
char scriptlet[PATH_MAX];
|
char scriptlet[PATH_MAX];
|
||||||
info = (pmpkg_t*)targ->data;
|
info = (pmpkg_t*)targ->data;
|
||||||
const char *pkgname = NULL;
|
const char *pkgname = NULL;
|
||||||
|
int targcount = alpm_list_count(targ);
|
||||||
|
|
||||||
if(handle->trans->state == STATE_INTERRUPTED) {
|
if(handle->trans->state == STATE_INTERRUPTED) {
|
||||||
return(0);
|
return(0);
|
||||||
@ -399,7 +400,6 @@ int _alpm_remove_packages(pmtrans_t *trans, pmdb_t *db)
|
|||||||
alpm_pkg_get_version(info), NULL, trans);
|
alpm_pkg_get_version(info), NULL, trans);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
if(!(trans->flags & PM_TRANS_FLAG_DBONLY)) {
|
if(!(trans->flags & PM_TRANS_FLAG_DBONLY)) {
|
||||||
alpm_list_t *files = alpm_pkg_get_files(info);
|
alpm_list_t *files = alpm_pkg_get_files(info);
|
||||||
for(lp = files; lp; lp = lp->next) {
|
for(lp = files; lp; lp = lp->next) {
|
||||||
@ -411,20 +411,20 @@ int _alpm_remove_packages(pmtrans_t *trans, pmdb_t *db)
|
|||||||
}
|
}
|
||||||
|
|
||||||
int filenum = alpm_list_count(files);
|
int filenum = alpm_list_count(files);
|
||||||
double percent = 0.0;
|
|
||||||
alpm_list_t *newfiles;
|
alpm_list_t *newfiles;
|
||||||
_alpm_log(PM_LOG_DEBUG, "removing %d files\n", filenum);
|
_alpm_log(PM_LOG_DEBUG, "removing %d files\n", filenum);
|
||||||
|
|
||||||
/* iterate through the list backwards, unlinking files */
|
/* iterate through the list backwards, unlinking files */
|
||||||
newfiles = alpm_list_reverse(files);
|
newfiles = alpm_list_reverse(files);
|
||||||
for(lp = newfiles; lp; lp = alpm_list_next(lp)) {
|
for(lp = newfiles; lp; lp = alpm_list_next(lp)) {
|
||||||
|
double percent;
|
||||||
unlink_file(info, lp->data, NULL, trans->flags & PM_TRANS_FLAG_NOSAVE);
|
unlink_file(info, lp->data, NULL, trans->flags & PM_TRANS_FLAG_NOSAVE);
|
||||||
|
|
||||||
/* update progress bar after each file */
|
/* update progress bar after each file */
|
||||||
percent = (double)position / (double)filenum;
|
percent = (double)position / (double)filenum;
|
||||||
PROGRESS(trans, PM_TRANS_PROGRESS_REMOVE_START, info->name,
|
PROGRESS(trans, PM_TRANS_PROGRESS_REMOVE_START, info->name,
|
||||||
(double)(percent * 100), pkg_count,
|
(double)(percent * 100), pkg_count,
|
||||||
(pkg_count - alpm_list_count(targ) + 1));
|
(pkg_count - targcount + 1));
|
||||||
position++;
|
position++;
|
||||||
}
|
}
|
||||||
alpm_list_free(newfiles);
|
alpm_list_free(newfiles);
|
||||||
@ -432,7 +432,7 @@ int _alpm_remove_packages(pmtrans_t *trans, pmdb_t *db)
|
|||||||
|
|
||||||
/* set progress to 100% after we finish unlinking files */
|
/* set progress to 100% after we finish unlinking files */
|
||||||
PROGRESS(trans, PM_TRANS_PROGRESS_REMOVE_START, pkgname, 100,
|
PROGRESS(trans, PM_TRANS_PROGRESS_REMOVE_START, pkgname, 100,
|
||||||
pkg_count, (pkg_count - alpm_list_count(targ) + 1));
|
pkg_count, (pkg_count - targcount + 1));
|
||||||
|
|
||||||
/* run the post-remove script if it exists */
|
/* run the post-remove script if it exists */
|
||||||
if(alpm_pkg_has_scriptlet(info) && !(trans->flags & PM_TRANS_FLAG_NOSCRIPTLET)) {
|
if(alpm_pkg_has_scriptlet(info) && !(trans->flags & PM_TRANS_FLAG_NOSCRIPTLET)) {
|
||||||
|
Loading…
Reference in New Issue
Block a user