diff --git a/src/core/model/trickle-timer.cc b/src/core/model/trickle-timer.cc index e97c99025..b9f8ec38e 100644 --- a/src/core/model/trickle-timer.cc +++ b/src/core/model/trickle-timer.cc @@ -21,6 +21,7 @@ #include "log.h" +#include #include namespace ns3 @@ -116,20 +117,7 @@ TrickleTimer::GetDoublings() const return 0; } - // Here we assume that m_ticks is a power of 2. - // This could have been way more elegant by using - // std::countl_zero() defined in the header - // which is c++20 - so not yet widely available. - - uint64_t ticks = m_ticks; - uint8_t doublings = 0; - while (ticks != 1) - { - ticks >>= 1; - doublings++; - } - - return doublings; + return std::countr_zero(m_ticks); } uint16_t diff --git a/utils/codespell-ignored-lines b/utils/codespell-ignored-lines index 5b068867f..e5c0b7e8c 100644 --- a/utils/codespell-ignored-lines +++ b/utils/codespell-ignored-lines @@ -85,6 +85,9 @@ Network Animator nam. It is not possible to run a simulation ./src/core/examples/hash-example.cc 6ed21de2 brand-newness peripherial +./src/core/model/trickle-timer.cc:120 + return std::countr_zero(m_ticks); + ./src/dsr/model/dsr-routing.cc:243, 246, 3360, 3363 .AddAttribute("GratReplyHoldoff", MakeTimeAccessor(&DsrRouting::m_gratReplyHoldoff),