From: Remi Gacogne Date: Fri, 11 Jul 2025 08:03:18 +0000 (+0200) Subject: dns: Rewrite `RCode::from_short` with `std::find` and `std::distance` X-Git-Tag: rec-5.4.0-alpha0~36^2~6 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=978fca63b078da822c15d1a9bdee9bd0bb4a7349;p=thirdparty%2Fpdns.git dns: Rewrite `RCode::from_short` with `std::find` and `std::distance` Signed-off-by: Remi Gacogne --- diff --git a/pdns/dns.cc b/pdns/dns.cc index d78027d80e..38c761cfbf 100644 --- a/pdns/dns.cc +++ b/pdns/dns.cc @@ -87,14 +87,11 @@ std::string RCode::to_short_s(uint8_t rcode) { std::optional RCode::from_short(const std::string_view& rcode_string) { - uint8_t position = 0; - for (const auto& short_rcode : rcodes_short_s) { - if (short_rcode == rcode_string) { - return position; - } - ++position; + auto position = std::find(rcodes_short_s.begin(), rcodes_short_s.end(), rcode_string); + if (position == rcodes_short_s.end()) { + return std::nullopt; } - return std::nullopt; + return std::distance(rcodes_short_s.begin(), position); } std::string ERCode::to_s(uint16_t rcode) {