Commit fd7d3c57 authored by Tatsuhiro Tsujikawa's avatar Tatsuhiro Tsujikawa

nghttpx: Use faster version of power

In our use case, x and y is quite small, and there is no chance for
overflow, and y is always integer.
parent 179561e4
......@@ -80,8 +80,8 @@ void ConnectBlocker::on_failure() {
++fail_count_;
auto base_backoff = pow(
MULTIPLIER, static_cast<double>(std::min(MAX_BACKOFF_EXP, fail_count_)));
auto base_backoff =
util::int_pow(MULTIPLIER, std::min(MAX_BACKOFF_EXP, fail_count_));
auto dist = std::uniform_real_distribution<>(-JITTER * base_backoff,
JITTER * base_backoff);
......
......@@ -157,8 +157,8 @@ constexpr auto JITTER = 0.2;
} // namespace
void LiveCheck::schedule() {
auto base_backoff = pow(
MULTIPLIER, static_cast<double>(std::min(fail_count_, MAX_BACKOFF_EXP)));
auto base_backoff =
util::int_pow(MULTIPLIER, std::min(fail_count_, MAX_BACKOFF_EXP));
auto dist = std::uniform_real_distribution<>(-JITTER * base_backoff,
JITTER * base_backoff);
......
......@@ -1316,6 +1316,15 @@ StringRef percent_decode(BlockAllocator &balloc, const StringRef &src) {
return StringRef{iov.base, p};
}
// Returns x**y
double int_pow(double x, size_t y) {
auto res = 1.;
for (; y; --y) {
res *= x;
}
return res;
}
} // namespace util
} // namespace nghttp2
......@@ -677,6 +677,9 @@ OutputIterator copy_lit(OutputIterator it, CharT(&s)[N]) {
return std::copy_n(s, N - 1, it);
}
// Returns x**y
double int_pow(double x, size_t y);
} // namespace util
} // namespace nghttp2
......
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