Use std::unordered_map<> in wxArchiveFSHandler code
In addition to removing wx hash map macros, also change the private wxArchiveFSEntryHash to store std::unique_ptr<wxArchiveEntry> rather than the raw pointers to ensure they're destroyed automatically and we don't need to use WX_CLEAR_HASH_MAP() for them.
This commit is contained in:
parent
4697f3cdad
commit
2eb09eea29
2 changed files with 13 additions and 11 deletions
|
|
@ -14,9 +14,10 @@
|
|||
#if wxUSE_FS_ARCHIVE
|
||||
|
||||
#include "wx/filesys.h"
|
||||
#include "wx/hashmap.h"
|
||||
|
||||
WX_DECLARE_STRING_HASH_MAP(int, wxArchiveFilenameHashMap);
|
||||
#include <unordered_map>
|
||||
|
||||
using wxArchiveFilenameHashMap = std::unordered_map<wxString, int>;
|
||||
|
||||
//---------------------------------------------------------------------------
|
||||
// wxArchiveFSHandler
|
||||
|
|
|
|||
|
|
@ -32,7 +32,8 @@
|
|||
// version.
|
||||
//---------------------------------------------------------------------------
|
||||
|
||||
WX_DECLARE_STRING_HASH_MAP(wxArchiveEntry*, wxArchiveFSEntryHash);
|
||||
using wxArchiveFSEntryHash =
|
||||
std::unordered_map<wxString, std::unique_ptr<wxArchiveEntry>>;
|
||||
|
||||
struct wxArchiveFSEntry
|
||||
{
|
||||
|
|
@ -59,6 +60,7 @@ public:
|
|||
wxArchiveFSEntry *GetNext(wxArchiveFSEntry *fse);
|
||||
|
||||
private:
|
||||
// Takes ownership of "entry".
|
||||
wxArchiveFSEntry *AddToCache(wxArchiveEntry *entry);
|
||||
void CloseStreams();
|
||||
|
||||
|
|
@ -98,8 +100,6 @@ wxArchiveFSCacheDataImpl::wxArchiveFSCacheDataImpl(
|
|||
|
||||
wxArchiveFSCacheDataImpl::~wxArchiveFSCacheDataImpl()
|
||||
{
|
||||
WX_CLEAR_HASH_MAP(wxArchiveFSEntryHash, m_hash);
|
||||
|
||||
wxArchiveFSEntry *entry = m_begin;
|
||||
|
||||
while (entry)
|
||||
|
|
@ -114,7 +114,7 @@ wxArchiveFSCacheDataImpl::~wxArchiveFSCacheDataImpl()
|
|||
|
||||
wxArchiveFSEntry *wxArchiveFSCacheDataImpl::AddToCache(wxArchiveEntry *entry)
|
||||
{
|
||||
m_hash[entry->GetName(wxPATH_UNIX)] = entry;
|
||||
m_hash[entry->GetName(wxPATH_UNIX)] = std::unique_ptr<wxArchiveEntry>(entry);
|
||||
wxArchiveFSEntry *fse = new wxArchiveFSEntry;
|
||||
*m_endptr = fse;
|
||||
(*m_endptr)->entry = entry;
|
||||
|
|
@ -131,10 +131,10 @@ void wxArchiveFSCacheDataImpl::CloseStreams()
|
|||
|
||||
wxArchiveEntry *wxArchiveFSCacheDataImpl::Get(const wxString& name)
|
||||
{
|
||||
wxArchiveFSEntryHash::iterator it = m_hash.find(name);
|
||||
const auto it = m_hash.find(name);
|
||||
|
||||
if (it != m_hash.end())
|
||||
return it->second;
|
||||
return it->second.get();
|
||||
|
||||
if (!m_archive)
|
||||
return nullptr;
|
||||
|
|
@ -254,7 +254,8 @@ wxArchiveFSCacheData& wxArchiveFSCacheData::operator=(
|
|||
// of wxFileSystem.
|
||||
//---------------------------------------------------------------------------
|
||||
|
||||
WX_DECLARE_STRING_HASH_MAP(wxArchiveFSCacheData, wxArchiveFSCacheDataHash);
|
||||
using wxArchiveFSCacheDataHash =
|
||||
std::unordered_map<wxString, wxArchiveFSCacheData>;
|
||||
|
||||
class wxArchiveFSCache
|
||||
{
|
||||
|
|
@ -289,9 +290,9 @@ wxArchiveFSCacheData* wxArchiveFSCache::Add(
|
|||
|
||||
wxArchiveFSCacheData *wxArchiveFSCache::Get(const wxString& name)
|
||||
{
|
||||
wxArchiveFSCacheDataHash::iterator it;
|
||||
const auto it = m_hash.find(name);
|
||||
|
||||
if ((it = m_hash.find(name)) != m_hash.end())
|
||||
if (it != m_hash.end())
|
||||
return &it->second;
|
||||
|
||||
return nullptr;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue