mirror of
https://gitee.com/openharmony/third_party_nghttp2
synced 2024-11-30 11:30:44 +00:00
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_;
|
||||
|
||||
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
|
||||
|
Loading…
Reference in New Issue
Block a user