Commit de82c426 authored by Yedidya Feldblum's avatar Yedidya Feldblum Committed by Facebook GitHub Bot

fix MSVC C5219 conversion warnings in EventBase

Summary:
Fixes warnings like the following:

```
folly\io\async\EventBase.cpp(725): warning C5219: implicit conversion from '_Rep' to 'double', possible loss of data
        with
        [
            _Rep=__int64
        ]
folly\io\async\EventBase.cpp(738): warning C5219: implicit conversion from '_Rep' to 'double', possible loss of data
        with
        [
            _Rep=__int64
        ]
folly\io\async\EventBase.cpp(740): warning C5219: implicit conversion from 'size_t' to 'double', possible loss of data
```

Reviewed By: luciang

Differential Revision: D31330566

fbshipit-source-id: 86a2cd10fdad53dce9c0ee0704b26bb1bce2bf18
parent a7426cc4
......@@ -722,7 +722,7 @@ void EventBase::initNotificationQueue() {
void EventBase::SmoothLoopTime::setTimeInterval(
std::chrono::microseconds timeInterval) {
expCoeff_ = -1.0 / timeInterval.count();
expCoeff_ = -1.0 / static_cast<double>(timeInterval.count());
VLOG(11) << "expCoeff_ " << expCoeff_ << " " << __PRETTY_FUNCTION__;
}
......@@ -735,9 +735,10 @@ void EventBase::SmoothLoopTime::addSample(
if ((buffer_time_ + total) > buffer_interval_ && buffer_cnt_ > 0) {
// See https://en.wikipedia.org/wiki/Exponential_smoothing for
// more info on this calculation.
double coeff = exp(buffer_time_.count() * expCoeff_);
value_ =
value_ * coeff + (1.0 - coeff) * (busy_buffer_.count() / buffer_cnt_);
double coeff = exp(static_cast<double>(buffer_time_.count()) * expCoeff_);
value_ = value_ * coeff +
(1.0 - coeff) *
(static_cast<double>(busy_buffer_.count()) / buffer_cnt_);
buffer_time_ = std::chrono::microseconds{0};
busy_buffer_ = std::chrono::microseconds{0};
buffer_cnt_ = 0;
......
......@@ -736,7 +736,8 @@ class EventBase : public TimeoutManager,
class SmoothLoopTime {
public:
explicit SmoothLoopTime(std::chrono::microseconds timeInterval)
: expCoeff_(-1.0 / timeInterval.count()), value_(0.0) {
: expCoeff_(-1.0 / static_cast<double>(timeInterval.count())),
value_(0.0) {
VLOG(11) << "expCoeff_ " << expCoeff_ << " " << __PRETTY_FUNCTION__;
}
......@@ -749,8 +750,9 @@ class EventBase : public TimeoutManager,
double get() const {
// Add the outstanding buffered times linearly, to avoid
// expensive exponentiation
auto lcoeff = buffer_time_.count() * -expCoeff_;
return value_ * (1.0 - lcoeff) + lcoeff * busy_buffer_.count();
auto lcoeff = static_cast<double>(buffer_time_.count()) * -expCoeff_;
return value_ * (1.0 - lcoeff) +
lcoeff * static_cast<double>(busy_buffer_.count());
}
void dampen(double factor) { value_ *= factor; }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment