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.
This commit is contained in:
parent
179561e4be
commit
fd7d3c57d7
|
@ -80,8 +80,8 @@ void ConnectBlocker::on_failure() {
|
||||||
|
|
||||||
++fail_count_;
|
++fail_count_;
|
||||||
|
|
||||||
auto base_backoff = pow(
|
auto base_backoff =
|
||||||
MULTIPLIER, static_cast<double>(std::min(MAX_BACKOFF_EXP, fail_count_)));
|
util::int_pow(MULTIPLIER, std::min(MAX_BACKOFF_EXP, fail_count_));
|
||||||
auto dist = std::uniform_real_distribution<>(-JITTER * base_backoff,
|
auto dist = std::uniform_real_distribution<>(-JITTER * base_backoff,
|
||||||
JITTER * base_backoff);
|
JITTER * base_backoff);
|
||||||
|
|
||||||
|
|
|
@ -157,8 +157,8 @@ constexpr auto JITTER = 0.2;
|
||||||
} // namespace
|
} // namespace
|
||||||
|
|
||||||
void LiveCheck::schedule() {
|
void LiveCheck::schedule() {
|
||||||
auto base_backoff = pow(
|
auto base_backoff =
|
||||||
MULTIPLIER, static_cast<double>(std::min(fail_count_, MAX_BACKOFF_EXP)));
|
util::int_pow(MULTIPLIER, std::min(fail_count_, MAX_BACKOFF_EXP));
|
||||||
auto dist = std::uniform_real_distribution<>(-JITTER * base_backoff,
|
auto dist = std::uniform_real_distribution<>(-JITTER * base_backoff,
|
||||||
JITTER * base_backoff);
|
JITTER * base_backoff);
|
||||||
|
|
||||||
|
|
|
@ -1316,6 +1316,15 @@ StringRef percent_decode(BlockAllocator &balloc, const StringRef &src) {
|
||||||
return StringRef{iov.base, p};
|
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 util
|
||||||
|
|
||||||
} // namespace nghttp2
|
} // namespace nghttp2
|
||||||
|
|
|
@ -677,6 +677,9 @@ OutputIterator copy_lit(OutputIterator it, CharT(&s)[N]) {
|
||||||
return std::copy_n(s, N - 1, it);
|
return std::copy_n(s, N - 1, it);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Returns x**y
|
||||||
|
double int_pow(double x, size_t y);
|
||||||
|
|
||||||
} // namespace util
|
} // namespace util
|
||||||
|
|
||||||
} // namespace nghttp2
|
} // namespace nghttp2
|
||||||
|
|
Loading…
Reference in New Issue