1
0
mirror of https://github.com/moparisthebest/pacman synced 2024-08-13 17:03:46 -04:00

Remove need for floating point division in backend

All of these can be done with integer division; the only slightly
interesting part is ensuring we round up like before with calling the
ceil() function.

We can also remove the math library from requirements; now that the only
ceil() calls are gone, we don't need this anymore.

Signed-off-by: Dan McGee <dan@archlinux.org>
This commit is contained in:
Dan McGee 2011-01-09 20:36:42 -06:00
parent 281a4c0a4f
commit d03b57f459
5 changed files with 26 additions and 30 deletions

View File

@ -133,9 +133,6 @@ AC_PATH_PROGS([BASH_SHELL], [bash bash4 bash3], [false])
AM_GNU_GETTEXT([external]) AM_GNU_GETTEXT([external])
AM_GNU_GETTEXT_VERSION(0.13.1) AM_GNU_GETTEXT_VERSION(0.13.1)
# Check for lm
AC_CHECK_LIB([m], [ceil])
# Check for libarchive # Check for libarchive
AC_CHECK_LIB([archive], [archive_read_data], , AC_CHECK_LIB([archive], [archive_read_data], ,
AC_MSG_ERROR([libarchive is needed to compile pacman!])) AC_MSG_ERROR([libarchive is needed to compile pacman!]))

View File

@ -477,8 +477,8 @@ static int extract_single_file(struct archive *archive,
return(errors); return(errors);
} }
static int commit_single_pkg(pmpkg_t *newpkg, size_t pkg_current, size_t pkg_count, static int commit_single_pkg(pmpkg_t *newpkg, size_t pkg_current,
pmtrans_t *trans, pmdb_t *db) size_t pkg_count, pmtrans_t *trans, pmdb_t *db)
{ {
int i, ret = 0, errors = 0; int i, ret = 0, errors = 0;
char scriptlet[PATH_MAX+1]; char scriptlet[PATH_MAX+1];
@ -605,31 +605,31 @@ static int commit_single_pkg(pmpkg_t *newpkg, size_t pkg_current, size_t pkg_cou
} }
for(i = 0; archive_read_next_header(archive, &entry) == ARCHIVE_OK; i++) { for(i = 0; archive_read_next_header(archive, &entry) == ARCHIVE_OK; i++) {
double percent; int percent;
if(newpkg->size != 0) { if(newpkg->size != 0) {
/* Using compressed size for calculations here, as newpkg->isize is not /* Using compressed size for calculations here, as newpkg->isize is not
* exact when it comes to comparing to the ACTUAL uncompressed size * exact when it comes to comparing to the ACTUAL uncompressed size
* (missing metadata sizes) */ * (missing metadata sizes) */
int64_t pos = archive_position_compressed(archive); int64_t pos = archive_position_compressed(archive);
percent = (double)pos / (double)newpkg->size; percent = (pos * 100) / newpkg->size;
_alpm_log(PM_LOG_DEBUG, "decompression progress: " _alpm_log(PM_LOG_DEBUG, "decompression progress: "
"%f%% (%"PRId64" / %jd)\n", "%d%% (%"PRId64" / %jd)\n",
percent*100.0, pos, (intmax_t)newpkg->size); percent, pos, (intmax_t)newpkg->size);
if(percent >= 1.0) { if(percent >= 100) {
percent = 1.0; percent = 100;
} }
} else { } else {
percent = 0.0; percent = 0;
} }
if(is_upgrade) { if(is_upgrade) {
PROGRESS(trans, PM_TRANS_PROGRESS_UPGRADE_START, PROGRESS(trans, PM_TRANS_PROGRESS_UPGRADE_START,
alpm_pkg_get_name(newpkg), (int)(percent * 100), pkg_count, alpm_pkg_get_name(newpkg), percent, pkg_count,
pkg_current); pkg_current);
} else { } else {
PROGRESS(trans, PM_TRANS_PROGRESS_ADD_START, PROGRESS(trans, PM_TRANS_PROGRESS_ADD_START,
alpm_pkg_get_name(newpkg), (int)(percent * 100), pkg_count, alpm_pkg_get_name(newpkg), percent, pkg_count,
pkg_current); pkg_current);
} }

View File

@ -425,8 +425,8 @@ alpm_list_t *_alpm_db_find_fileconflicts(pmdb_t *db, pmtrans_t *trans,
continue; continue;
} }
double percent = (double)current / (double)numtargs; int percent = (current * 100) / numtargs;
PROGRESS(trans, PM_TRANS_PROGRESS_CONFLICTS_START, "", (int)(percent * 100), PROGRESS(trans, PM_TRANS_PROGRESS_CONFLICTS_START, "", percent,
numtargs, current); numtargs, current);
/* CHECK 1: check every target against every target */ /* CHECK 1: check every target against every target */
_alpm_log(PM_LOG_DEBUG, "searching for file conflicts: %s\n", _alpm_log(PM_LOG_DEBUG, "searching for file conflicts: %s\n",

View File

@ -38,8 +38,6 @@
#include <sys/types.h> #include <sys/types.h>
#endif #endif
#include <math.h>
/* libarchive */ /* libarchive */
#include <archive.h> #include <archive.h>
#include <archive_entry.h> #include <archive_entry.h>
@ -178,8 +176,9 @@ static int calculate_removed_size(const alpm_list_t *mount_points,
} }
data = mp->data; data = mp->data;
data->blocks_needed -= (long)ceil((double)(st.st_size) / /* the addition of (divisor - 1) performs ceil() with integer division */
(double)(data->fsp.f_bsize)); data->blocks_needed -=
(st.st_size + data->fsp.f_bsize - 1) / data->fsp.f_bsize;
data->used = 1; data->used = 1;
} }
@ -229,8 +228,9 @@ static int calculate_installed_size(const alpm_list_t *mount_points,
} }
data = mp->data; data = mp->data;
data->blocks_needed += (long)ceil((double)(archive_entry_size(entry)) / /* the addition of (divisor - 1) performs ceil() with integer division */
(double)(data->fsp.f_bsize)); data->blocks_needed +=
(archive_entry_size(entry) + data->fsp.f_bsize - 1) / data->fsp.f_bsize;
data->used = 1; data->used = 1;
} }
@ -259,8 +259,8 @@ int _alpm_check_diskspace(pmtrans_t *trans, pmdb_t *db_local)
if(replaces) { if(replaces) {
numtargs += replaces; numtargs += replaces;
for(targ = trans->remove; targ; targ = targ->next, current++) { for(targ = trans->remove; targ; targ = targ->next, current++) {
double percent = (double)current / (double)numtargs; int percent = (current * 100) / numtargs;
PROGRESS(trans, PM_TRANS_PROGRESS_DISKSPACE_START, "", (int)(percent * 100), PROGRESS(trans, PM_TRANS_PROGRESS_DISKSPACE_START, "", percent,
numtargs, current); numtargs, current);
pkg = targ->data; pkg = targ->data;
@ -269,8 +269,8 @@ int _alpm_check_diskspace(pmtrans_t *trans, pmdb_t *db_local)
} }
for(targ = trans->add; targ; targ = targ->next, current++) { for(targ = trans->add; targ; targ = targ->next, current++) {
double percent = (double)current / (double)numtargs; int percent = (current * 100) / numtargs;
PROGRESS(trans, PM_TRANS_PROGRESS_DISKSPACE_START, "", (int)(percent * 100), PROGRESS(trans, PM_TRANS_PROGRESS_DISKSPACE_START, "", percent,
numtargs, current); numtargs, current);
pkg = targ->data; pkg = targ->data;

View File

@ -425,14 +425,13 @@ int _alpm_remove_packages(pmtrans_t *trans, pmdb_t *db)
/* 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; int 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 = (position * 100) / filenum;
PROGRESS(trans, PM_TRANS_PROGRESS_REMOVE_START, info->name, PROGRESS(trans, PM_TRANS_PROGRESS_REMOVE_START, info->name,
(int)(percent * 100), pkg_count, percent, pkg_count, (pkg_count - targcount + 1));
(pkg_count - targcount + 1));
position++; position++;
} }
alpm_list_free(newfiles); alpm_list_free(newfiles);