From b15f595130c22c595464707a372132fc8e7ea72b Mon Sep 17 00:00:00 2001 From: Lioncash Date: Mon, 27 May 2019 09:31:13 -0400 Subject: [PATCH] Common/HttpRequest: Avoid unnecessary copies in loop in Fetch() Previously, every entry pair within the map would be copied. The reason for this is subtle. A std::map's internal entry type is defined as: std::pair but the loop was declaring it as: std::pair These two types aren't synonymous with one another and so the compiler is required to always perform a copy. Using structured bindings avoids this (as would plain auto or correcting the explicit type), while also allowing the use of more appropriate names compared to first and second. --- Source/Core/Common/HttpRequest.cpp | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/Source/Core/Common/HttpRequest.cpp b/Source/Core/Common/HttpRequest.cpp index f0da40cdea..18ea402dc5 100644 --- a/Source/Core/Common/HttpRequest.cpp +++ b/Source/Core/Common/HttpRequest.cpp @@ -197,14 +197,14 @@ HttpRequest::Response HttpRequest::Impl::Fetch(const std::string& url, Method me curl_slist* list = nullptr; Common::ScopeGuard list_guard{[&list] { curl_slist_free_all(list); }}; - for (const std::pair>& header : headers) + for (const auto& [name, value] : headers) { - if (!header.second) - list = curl_slist_append(list, (header.first + ":").c_str()); - else if (header.second->empty()) - list = curl_slist_append(list, (header.first + ";").c_str()); + if (!value) + list = curl_slist_append(list, (name + ':').c_str()); + else if (value->empty()) + list = curl_slist_append(list, (name + ';').c_str()); else - list = curl_slist_append(list, (header.first + ": " + *header.second).c_str()); + list = curl_slist_append(list, (name + ": " + *value).c_str()); } curl_easy_setopt(m_curl.get(), CURLOPT_HTTPHEADER, list);