mirror of
https://github.com/XRPLF/rippled.git
synced 2026-09-27 23:38:08 +00:00
refactor(telemetry): use ranges algorithms in ValidationTracker, mark accessors nodiscard
Nine std::count_if calls over window1h_ and window7d_ took an iterator pair; std::ranges::count_if takes the container. One hand-rolled erase-while-iterating loop becomes a single std::erase_if: pending_ is a hash_map, which is a std::unordered_map alias, so the C++20 overload applies. The hard-trim loop below it is left as a loop on purpose. It re-tests pending_.size() every step to stop as soon as the cap is met, which erase_if cannot express. The accessors return values a caller must use: 13 in ValidationTracker.h, the two Unit.h mappers, the two HistogramBuckets.h helpers, getMeter() and networkTypeFromId(). No caller in the chain discards any of them.
This commit is contained in:
@@ -53,7 +53,7 @@ enum class Unit : std::uint8_t {
|
||||
* @param unit The unit to translate.
|
||||
* @return A static, null-terminated UCUM code.
|
||||
*/
|
||||
constexpr char const*
|
||||
[[nodiscard]] constexpr char const*
|
||||
otelUnitCode(Unit unit) noexcept
|
||||
{
|
||||
switch (unit)
|
||||
@@ -78,7 +78,7 @@ otelUnitCode(Unit unit) noexcept
|
||||
* @param unit The unit to describe.
|
||||
* @return A static, null-terminated description.
|
||||
*/
|
||||
constexpr char const*
|
||||
[[nodiscard]] constexpr char const*
|
||||
otelUnitDescription(Unit unit) noexcept
|
||||
{
|
||||
switch (unit)
|
||||
|
||||
@@ -144,7 +144,7 @@ inline constexpr std::array kByteBuckets{
|
||||
* @return true when the ladder is non-empty, starts at or above zero, and
|
||||
* every later edge is strictly greater than its predecessor.
|
||||
*/
|
||||
constexpr bool
|
||||
[[nodiscard]] constexpr bool
|
||||
isAscendingNonNegative(std::span<double const> ladder) noexcept
|
||||
{
|
||||
if (ladder.empty() || ladder.front() < 0.0)
|
||||
@@ -167,7 +167,7 @@ static_assert(isAscendingNonNegative(kByteBuckets));
|
||||
* @param ladder Bucket upper bounds.
|
||||
* @return A vector holding the same edges in the same order.
|
||||
*/
|
||||
inline std::vector<double>
|
||||
[[nodiscard]] inline std::vector<double>
|
||||
toVector(std::span<double const> ladder)
|
||||
{
|
||||
return std::vector<double>(ladder.begin(), ladder.end());
|
||||
|
||||
@@ -393,7 +393,7 @@ public:
|
||||
* @param name Meter name used to identify the instrumentation scope.
|
||||
* @return A shared pointer to the Meter.
|
||||
*/
|
||||
virtual opentelemetry::nostd::shared_ptr<opentelemetry::metrics::Meter>
|
||||
[[nodiscard]] virtual opentelemetry::nostd::shared_ptr<opentelemetry::metrics::Meter>
|
||||
getMeter(std::string_view name = kMeterName) = 0;
|
||||
|
||||
/**
|
||||
@@ -486,7 +486,7 @@ makeTelemetrySetup(
|
||||
* @param networkId The network identifier from [network_id] config.
|
||||
* @return "mainnet" (0), "testnet" (1), "devnet" (2), or "unknown".
|
||||
*/
|
||||
std::string
|
||||
[[nodiscard]] std::string
|
||||
networkTypeFromId(std::uint32_t networkId);
|
||||
|
||||
} // namespace xrpl::telemetry
|
||||
|
||||
Reference in New Issue
Block a user