summaryrefslogtreecommitdiff
path: root/lib/progress.c
diff options
context:
space:
mode:
authorDaniel Stenberg <daniel@haxx.se>2004-05-05 07:45:21 +0000
committerDaniel Stenberg <daniel@haxx.se>2004-05-05 07:45:21 +0000
commitcaf7854a3ce16933557ad6ff33e6b210a2109b48 (patch)
tree8248c26bdebd6907ddb1ac66c59376be43fe49fc /lib/progress.c
parent6def0892eaea1a4fd174b74a95d637a30a6a6d18 (diff)
downloadcurl-caf7854a3ce16933557ad6ff33e6b210a2109b48.tar.gz
if the values allow it, avoid floting point math for the current speed
Diffstat (limited to 'lib/progress.c')
-rw-r--r--lib/progress.c19
1 files changed, 15 insertions, 4 deletions
diff --git a/lib/progress.c b/lib/progress.c
index e7e5728ef..51333aff1 100644
--- a/lib/progress.c
+++ b/lib/progress.c
@@ -301,10 +301,21 @@ int Curl_pgrsUpdate(struct connectdata *conn)
if(0 == span_ms)
span_ms=1; /* at least one millisecond MUST have passed */
- /* Calculate the average speed the last 'countindex' seconds */
- data->progress.current_speed = (curl_off_t)
- (data->progress.speeder[nowindex]-
- data->progress.speeder[checkindex])/((double)span_ms/1000);
+ /* Calculate the average speed the last 'span_ms' milliseconds */
+ {
+ curl_off_t amount = data->progress.speeder[nowindex]-
+ data->progress.speeder[checkindex];
+
+ if(amount > 0xffffffff/1000)
+ /* the 'amount' value is bigger than would fit in 32 bits if
+ multiplied with 1000, so we use the double math for this */
+ data->progress.current_speed = (curl_off_t)
+ (amount/(span_ms/1000.0));
+ else
+ /* the 'amount' value is small enough to fit within 32 bits even
+ when multiplied with 1000 */
+ data->progress.current_speed = amount*1000/span_ms;
+ }
}
else
/* the first second we use the main average */