From d03b57f459fb9ab9288991a70c4e7297a7c1d150 Mon Sep 17 00:00:00 2001 From: Dan McGee Date: Sun, 9 Jan 2011 20:36:42 -0600 Subject: 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 --- lib/libalpm/diskspace.c | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) (limited to 'lib/libalpm/diskspace.c') 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 #endif -#include - /* libarchive */ #include #include @@ -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; -- cgit v1.2.3-24-g4f1b