1
0
mirror of https://github.com/moparisthebest/curl synced 2024-12-21 23:58:49 -05:00

if the values allow it, avoid floting point math for the current speed

This commit is contained in:
Daniel Stenberg 2004-05-05 07:45:21 +00:00
parent 6def0892ea
commit caf7854a3c

View File

@ -301,10 +301,21 @@ int Curl_pgrsUpdate(struct connectdata *conn)
if(0 == span_ms) if(0 == span_ms)
span_ms=1; /* at least one millisecond MUST have passed */ span_ms=1; /* at least one millisecond MUST have passed */
/* Calculate the average speed the last 'countindex' seconds */ /* Calculate the average speed the last 'span_ms' milliseconds */
data->progress.current_speed = (curl_off_t) {
(data->progress.speeder[nowindex]- curl_off_t amount = data->progress.speeder[nowindex]-
data->progress.speeder[checkindex])/((double)span_ms/1000); 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 else
/* the first second we use the main average */ /* the first second we use the main average */