Convert get_update_timediff to integer return value
We don't need absolute floating point precision at all here; we can
stick to integer land and use milliseconds which are precise enough for
our purposes. This also removes most floating point math out of the
non-update code path.
-/* Silly little helper function, determines if the caller needs a visual update
+/* update speed for the fill_progress based functions */
+#define UPDATE_SPEED_MS 200
+
+/**
+ * Silly little helper function, determines if the caller needs a visual update
* since the last time this function was called.
- * This is made for the two progress bar functions, to prevent flicker
- *
- * first_call indicates if this is the first time it is called, for
- * initialization purposes */
-static double get_update_timediff(int first_call)
+ * This is made for the two progress bar functions, to prevent flicker.
+ * @param first_call 1 on first call for initialization purposes, 0 otherwise
+ * @return number of milliseconds since last call
+ */
+static long get_update_timediff(int first_call)
{
- double retval = 0.0;
+ long retval = 0;
static struct timeval last_time = {0, 0};
/* on first call, simply set the last time and return */
@@ -59,18 +63,17 @@ static double get_update_timediff(int first_call)
gettimeofday(&last_time, NULL);
} else {
struct timeval this_time;
- double diff_sec, diff_usec;
+ time_t diff_sec;
+ suseconds_t diff_usec;
- /* return 0 and do not update last_time if interval was too short */
- if(retval < UPDATE_SPEED_SEC) {
- retval = 0.0;
- } else {
+ /* do not update last_time if interval was too short */
+ if(retval >= UPDATE_SPEED_MS) {
last_time = this_time;
}
}
@@ -399,7 +402,7 @@ void cb_progress(alpm_progress_t event, const char *pkgname, int percent,
if(current != prevcurrent) {
/* update always */
} else if(!pkgname || percent == prevpercent ||
- get_update_timediff(0) < UPDATE_SPEED_SEC) {
+ get_update_timediff(0) < UPDATE_SPEED_MS) {
/* only update the progress bar when we have a package name, the
* percentage has changed, and it has been long enough. */
return;
@@ -534,7 +537,8 @@ void cb_dl_progress(const char *filename, off_t file_xfered, off_t file_total)