From e29f989dd7f153b28d7c2bd8ef7d59e0dc249a0c Mon Sep 17 00:00:00 2001 From: Rosen Penev Date: Fri, 13 Dec 2024 12:32:37 -0800 Subject: [PATCH] use min_element Signed-off-by: Rosen Penev --- pdns/dnspacket.cc | 9 ++++----- pdns/dnsparser.hh | 4 ++++ 2 files changed, 8 insertions(+), 5 deletions(-) diff --git a/pdns/dnspacket.cc b/pdns/dnspacket.cc index 2afde53a35..832f89b269 100644 --- a/pdns/dnspacket.cc +++ b/pdns/dnspacket.cc @@ -244,12 +244,11 @@ bool DNSPacket::couldBeCached() const unsigned int DNSPacket::getMinTTL() { - unsigned int minttl = UINT_MAX; - for(const DNSZoneRecord& rr : d_rrs) { - minttl = std::min(minttl, rr.dr.d_ttl); + auto it = std::min_element(d_rrs.begin(), d_rrs.end()); + if (it != d_rrs.end()) { + return it->dr.d_ttl; } - - return minttl; + return UINT_MAX; } bool DNSPacket::isEmpty() diff --git a/pdns/dnsparser.hh b/pdns/dnsparser.hh index fd2f5b7112..cefeb79220 100644 --- a/pdns/dnsparser.hh +++ b/pdns/dnsparser.hh @@ -438,6 +438,10 @@ struct DNSZoneRecord bool auth{true}; bool disabled{false}; DNSRecord dr; + + bool operator<(const DNSZoneRecord& other) const { + return dr.d_ttl < other.dr.d_ttl; + } }; class UnknownRecordContent : public DNSRecordContent -- 2.47.2