summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDan McGee <dan@archlinux.org>2011-01-10 03:36:42 +0100
committerDan McGee <dan@archlinux.org>2011-01-10 17:49:55 +0100
commitd03b57f459fb9ab9288991a70c4e7297a7c1d150 (patch)
tree6bebc7f9ca3c5414a48dc1b5cfa323fd5c00e372
parent281a4c0a4f2de217b5d23939fb78b3bbfccc34ca (diff)
downloadpacman-d03b57f459fb9ab9288991a70c4e7297a7c1d150.tar.gz
pacman-d03b57f459fb9ab9288991a70c4e7297a7c1d150.tar.xz
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>
-rw-r--r--configure.ac3
-rw-r--r--lib/libalpm/add.c22
-rw-r--r--lib/libalpm/conflict.c4
-rw-r--r--lib/libalpm/diskspace.c20
-rw-r--r--lib/libalpm/remove.c7
5 files changed, 26 insertions, 30 deletions
diff --git a/configure.ac b/configure.ac
index 5627fb76..73a5d3d0 100644
--- a/configure.ac
+++ b/configure.ac
@@ -133,9 +133,6 @@ AC_PATH_PROGS([BASH_SHELL], [bash bash4 bash3], [false])
AM_GNU_GETTEXT([external])
AM_GNU_GETTEXT_VERSION(0.13.1)
-# Check for lm
-AC_CHECK_LIB([m], [ceil])
-
# Check for libarchive
AC_CHECK_LIB([archive], [archive_read_data], ,
AC_MSG_ERROR([libarchive is needed to compile pacman!]))
diff --git a/lib/libalpm/add.c b/lib/libalpm/add.c
index 2f341eb0..d4c56def 100644
--- a/lib/libalpm/add.c
+++ b/lib/libalpm/add.c
@@ -477,8 +477,8 @@ static int extract_single_file(struct archive *archive,
return(errors);
}
-static int commit_single_pkg(pmpkg_t *newpkg, size_t pkg_current, size_t pkg_count,
- pmtrans_t *trans, pmdb_t *db)
+static int commit_single_pkg(pmpkg_t *newpkg, size_t pkg_current,
+ size_t pkg_count, pmtrans_t *trans, pmdb_t *db)
{
int i, ret = 0, errors = 0;
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++) {
- double percent;
+ int percent;
if(newpkg->size != 0) {
/* Using compressed size for calculations here, as newpkg->isize is not
* exact when it comes to comparing to the ACTUAL uncompressed size
* (missing metadata sizes) */
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: "
- "%f%% (%"PRId64" / %jd)\n",
- percent*100.0, pos, (intmax_t)newpkg->size);
- if(percent >= 1.0) {
- percent = 1.0;
+ "%d%% (%"PRId64" / %jd)\n",
+ percent, pos, (intmax_t)newpkg->size);
+ if(percent >= 100) {
+ percent = 100;
}
} else {
- percent = 0.0;
+ percent = 0;
}
if(is_upgrade) {
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);
} else {
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);
}
diff --git a/lib/libalpm/conflict.c b/lib/libalpm/conflict.c
index 0eaf4373..fc25e7d3 100644
--- a/lib/libalpm/conflict.c
+++ b/lib/libalpm/conflict.c
@@ -425,8 +425,8 @@ alpm_list_t *_alpm_db_find_fileconflicts(pmdb_t *db, pmtrans_t *trans,
continue;
}
- double percent = (double)current / (double)numtargs;
- PROGRESS(trans, PM_TRANS_PROGRESS_CONFLICTS_START, "", (int)(percent * 100),
+ int percent = (current * 100) / numtargs;
+ PROGRESS(trans, PM_TRANS_PROGRESS_CONFLICTS_START, "", percent,
numtargs, current);
/* CHECK 1: check every target against every target */
_alpm_log(PM_LOG_DEBUG, "searching for file conflicts: %s\n",
diff --git a/lib/libalpm/diskspace.c b/lib/libalpm/diskspace.c
index 87dca84f..b53d272f 100644
--- a/lib/libalpm/diskspace.c
+++ b/lib/libalpm/diskspace.c
@@ -38,8 +38,6 @@
#include <sys/types.h>
#endif
-#include <math.h>
-
/* libarchive */
#include <archive.h>
#include <archive_entry.h>
@@ -178,8 +176,9 @@ static int calculate_removed_size(const alpm_list_t *mount_points,
}
data = mp->data;
- data->blocks_needed -= (long)ceil((double)(st.st_size) /
- (double)(data->fsp.f_bsize));
+ /* the addition of (divisor - 1) performs ceil() with integer division */
+ data->blocks_needed -=
+ (st.st_size + data->fsp.f_bsize - 1) / data->fsp.f_bsize;
data->used = 1;
}
@@ -229,8 +228,9 @@ static int calculate_installed_size(const alpm_list_t *mount_points,
}
data = mp->data;
- data->blocks_needed += (long)ceil((double)(archive_entry_size(entry)) /
- (double)(data->fsp.f_bsize));
+ /* the addition of (divisor - 1) performs ceil() with integer division */
+ data->blocks_needed +=
+ (archive_entry_size(entry) + data->fsp.f_bsize - 1) / data->fsp.f_bsize;
data->used = 1;
}
@@ -259,8 +259,8 @@ int _alpm_check_diskspace(pmtrans_t *trans, pmdb_t *db_local)
if(replaces) {
numtargs += replaces;
for(targ = trans->remove; targ; targ = targ->next, current++) {
- double percent = (double)current / (double)numtargs;
- PROGRESS(trans, PM_TRANS_PROGRESS_DISKSPACE_START, "", (int)(percent * 100),
+ int percent = (current * 100) / numtargs;
+ PROGRESS(trans, PM_TRANS_PROGRESS_DISKSPACE_START, "", percent,
numtargs, current);
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++) {
- double percent = (double)current / (double)numtargs;
- PROGRESS(trans, PM_TRANS_PROGRESS_DISKSPACE_START, "", (int)(percent * 100),
+ int percent = (current * 100) / numtargs;
+ PROGRESS(trans, PM_TRANS_PROGRESS_DISKSPACE_START, "", percent,
numtargs, current);
pkg = targ->data;
diff --git a/lib/libalpm/remove.c b/lib/libalpm/remove.c
index e1249fd6..d4e3b94a 100644
--- a/lib/libalpm/remove.c
+++ b/lib/libalpm/remove.c
@@ -425,14 +425,13 @@ int _alpm_remove_packages(pmtrans_t *trans, pmdb_t *db)
/* iterate through the list backwards, unlinking files */
newfiles = alpm_list_reverse(files);
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);
/* update progress bar after each file */
- percent = (double)position / (double)filenum;
+ percent = (position * 100) / filenum;
PROGRESS(trans, PM_TRANS_PROGRESS_REMOVE_START, info->name,
- (int)(percent * 100), pkg_count,
- (pkg_count - targcount + 1));
+ percent, pkg_count, (pkg_count - targcount + 1));
position++;
}
alpm_list_free(newfiles);