From a3be5fd165172530436f1293f66fd51904d00dff Mon Sep 17 00:00:00 2001 From: Vadim Zeitlin Date: Mon, 17 Apr 2023 20:09:33 +0100 Subject: [PATCH] Use std::unordered_map<> in wxHTTP directly Replace wxStringToStringHashMap with std::unordered_map<>, although still use (private) typedefs for the two different maps storing the cookies and the headers respectively for clarity. Also use a range for loop for iterating over the headers. Include wx/wxcrt.h from http.cpp explicitly because wxAtoi(), declared there, is used in this file, but it was previously only included indirectly via wx/hashmap.h. --- include/wx/protocol/http.h | 18 +++++++++++------- src/common/http.cpp | 6 +++--- 2 files changed, 14 insertions(+), 10 deletions(-) diff --git a/include/wx/protocol/http.h b/include/wx/protocol/http.h index 5053fed714..03d5f012d4 100644 --- a/include/wx/protocol/http.h +++ b/include/wx/protocol/http.h @@ -14,10 +14,11 @@ #if wxUSE_PROTOCOL_HTTP -#include "wx/hashmap.h" #include "wx/protocol/protocol.h" #include "wx/buffer.h" +#include + class WXDLLIMPEXP_NET wxHTTP : public wxProtocol { public: @@ -51,10 +52,13 @@ public: wxDEPRECATED(void SetPostBuffer(const wxString& post_buf)); protected: - typedef wxStringToStringHashMap::iterator wxHeaderIterator; - typedef wxStringToStringHashMap::const_iterator wxHeaderConstIterator; - typedef wxStringToStringHashMap::iterator wxCookieIterator; - typedef wxStringToStringHashMap::const_iterator wxCookieConstIterator; + using wxHeadersMap = std::unordered_map; + typedef wxHeadersMap::iterator wxHeaderIterator; + typedef wxHeadersMap::const_iterator wxHeaderConstIterator; + + using wxCookiesMap = std::unordered_map; + typedef wxCookiesMap::iterator wxCookieIterator; + typedef wxCookiesMap::const_iterator wxCookieConstIterator; bool BuildRequest(const wxString& path, const wxString& method); void SendHeaders(); @@ -75,9 +79,9 @@ protected: // internal variables: wxString m_method; - wxStringToStringHashMap m_cookies; + wxCookiesMap m_cookies; - wxStringToStringHashMap m_headers; + wxHeadersMap m_headers; bool m_read, m_proxy_mode; wxSockAddress *m_addr; diff --git a/src/common/http.cpp b/src/common/http.cpp index 79c4e4b7bb..60dd9dbe4f 100644 --- a/src/common/http.cpp +++ b/src/common/http.cpp @@ -28,6 +28,7 @@ #include "wx/protocol/http.h" #include "wx/sckstrm.h" #include "wx/thread.h" +#include "wx/wxcrt.h" // ---------------------------------------------------------------------------- @@ -227,12 +228,11 @@ wxHTTP::SetPostText(const wxString& contentType, void wxHTTP::SendHeaders() { - typedef wxStringToStringHashMap::iterator iterator; wxString buf; - for (iterator it = m_headers.begin(), en = m_headers.end(); it != en; ++it ) + for ( const auto& kv : m_headers ) { - buf.Printf(wxT("%s: %s\r\n"), it->first.c_str(), it->second.c_str()); + buf.Printf("%s: %s\r\n", kv.first, kv.second); const wxWX2MBbuf cbuf = buf.mb_str(); Write(cbuf, strlen(cbuf));