LookupServer: Avoid unnecessary copies

This commit is contained in:
Ben Wiederhake 2021-12-05 12:10:17 +01:00 committed by Andreas Kling
parent 182a85c895
commit 95c21977b4

View file

@ -149,8 +149,8 @@ Vector<DNSAnswer> LookupServer::lookup(const DNSName& name, DNSRecordType record
};
// First, try /etc/hosts.
if (auto local_answers = m_etc_hosts.get(name); local_answers.has_value()) {
for (auto& answer : local_answers.value()) {
if (auto local_answers = m_etc_hosts.find(name); local_answers != m_etc_hosts.end()) {
for (auto& answer : local_answers->value) {
if (answer.type() == record_type)
add_answer(answer);
}
@ -169,8 +169,8 @@ Vector<DNSAnswer> LookupServer::lookup(const DNSName& name, DNSRecordType record
}
// Third, try our cache.
if (auto cached_answers = m_lookup_cache.get(name); cached_answers.has_value()) {
for (auto& answer : cached_answers.value()) {
if (auto cached_answers = m_lookup_cache.find(name); cached_answers != m_lookup_cache.end()) {
for (auto& answer : cached_answers->value) {
// TODO: Actually remove expired answers from the cache.
if (answer.type() == record_type && !answer.has_expired()) {
dbgln_if(LOOKUPSERVER_DEBUG, "Cache hit: {} -> {}", name.as_string(), answer.record_data());