diff --git a/include/wx/html/htmlpars.h b/include/wx/html/htmlpars.h index bc4be92280..17793e76ff 100644 --- a/include/wx/html/htmlpars.h +++ b/include/wx/html/htmlpars.h @@ -14,11 +14,14 @@ #include "wx/html/htmltag.h" #include "wx/filesys.h" -#include "wx/hashmap.h" -#include "wx/hashset.h" #include "wx/vector.h" #include "wx/fontenc.h" +#include +#include +#include +#include + class WXDLLIMPEXP_FWD_BASE wxMBConv; class WXDLLIMPEXP_FWD_HTML wxHtmlParser; class WXDLLIMPEXP_FWD_HTML wxHtmlTagHandler; @@ -27,13 +30,7 @@ class WXDLLIMPEXP_FWD_HTML wxHtmlEntitiesParser; class wxHtmlTextPieces; class wxHtmlParserState; -WX_DECLARE_HASH_SET_WITH_DECL_PTR(wxHtmlTagHandler*, - wxPointerHash, wxPointerEqual, - wxHtmlTagHandlersSet, - class WXDLLIMPEXP_HTML); -WX_DECLARE_STRING_HASH_MAP_WITH_DECL(wxHtmlTagHandler*, - wxHtmlTagHandlersHash, - class WXDLLIMPEXP_HTML); +using wxHtmlTagHandlersHash = std::unordered_map; enum wxHtmlURLType @@ -185,9 +182,8 @@ protected: // (see wxHtmlWinParser for details about filling it) // m_HandlersHash is for random access based on knowledge of tag name (BR, P, etc.) // it may (and often does) contain more references to one object - // m_HandlersList is list of all handlers and it is guaranteed to contain - // only one reference to each handler instance. - wxHtmlTagHandlersSet m_HandlersSet; + // m_HandlersSet is set of all handlers and owns its elements. + std::unordered_set> m_HandlersSet; wxHtmlTagHandlersHash m_HandlersHash; wxDECLARE_NO_COPY_CLASS(wxHtmlParser); @@ -195,7 +191,7 @@ protected: // class for opening files (file system) wxFileSystem *m_FS; // handlers stack used by PushTagHandler and PopTagHandler - wxVector m_HandlersStack; + std::stack> m_HandlersStack; // entity parse wxHtmlEntitiesParser *m_entitiesParser; diff --git a/src/html/htmlpars.cpp b/src/html/htmlpars.cpp index 9312591b13..2fe5381c49 100644 --- a/src/html/htmlpars.cpp +++ b/src/html/htmlpars.cpp @@ -86,8 +86,6 @@ wxHtmlParser::~wxHtmlParser() while (RestoreState()) {} DestroyDOMTree(); - WX_CLEAR_ARRAY(m_HandlersStack); - WX_CLEAR_HASH_SET(wxHtmlTagHandlersSet, m_HandlersSet); delete m_entitiesParser; delete m_Source; } @@ -331,7 +329,7 @@ void wxHtmlParser::AddTagHandler(wxHtmlTagHandler *handler) while (tokenizer.HasMoreTokens()) m_HandlersHash[tokenizer.GetNextToken()] = handler; - m_HandlersSet.insert(handler); + m_HandlersSet.insert(std::unique_ptr(handler)); handler->SetParser(this); } @@ -341,7 +339,9 @@ void wxHtmlParser::PushTagHandler(wxHtmlTagHandler *handler, const wxString& tag wxStringTokenizer tokenizer(tags, wxT(", ")); wxString key; - m_HandlersStack.push_back(new wxHtmlTagHandlersHash(m_HandlersHash)); + m_HandlersStack.push(std::unique_ptr( + new wxHtmlTagHandlersHash(m_HandlersHash)) + ); while (tokenizer.HasMoreTokens()) { @@ -355,10 +355,8 @@ void wxHtmlParser::PopTagHandler() wxCHECK_RET( !m_HandlersStack.empty(), "attempt to remove HTML tag handler from empty stack" ); - wxHtmlTagHandlersHash *prev = m_HandlersStack.back(); - m_HandlersStack.pop_back(); - m_HandlersHash = *prev; - delete prev; + m_HandlersHash = *m_HandlersStack.top(); + m_HandlersStack.pop(); } void wxHtmlParser::SetSourceAndSaveState(const wxString& src)