vector instead of simple_list (nw)

This commit is contained in:
Miodrag Milanovic 2016-01-11 18:11:55 +01:00
parent f21c96ce8a
commit 864486b7e6
2 changed files with 11 additions and 18 deletions

View File

@ -241,7 +241,7 @@ static void CLIB_DECL ATTR_PRINTF(1,2) debugload(const char *string, ...)
chd_file *rom_load_manager::get_disk_handle(const char *region)
{
for (open_chd *curdisk = m_chd_list.first(); curdisk != nullptr; curdisk = curdisk->next())
for (auto &curdisk : m_chd_list)
if (strcmp(curdisk->region(), region) == 0)
return &curdisk->chd();
return nullptr;
@ -255,12 +255,10 @@ chd_file *rom_load_manager::get_disk_handle(const char *region)
int rom_load_manager::set_disk_handle(const char *region, const char *fullpath)
{
auto chd = global_alloc(open_chd(region));
chd_error err = chd->orig_chd().open(fullpath);
auto chd = std::make_unique<open_chd>(region);
auto err = chd->orig_chd().open(fullpath);
if (err == CHDERR_NONE)
m_chd_list.append(*chd);
else
global_free(chd);
m_chd_list.push_back(std::move(chd));
return err;
}
@ -1161,7 +1159,7 @@ void rom_load_manager::process_disk_entries(const char *regiontag, const rom_ent
/* handle files */
if (ROMENTRY_ISFILE(romp))
{
auto chd = global_alloc(open_chd(regiontag));
auto chd = std::make_unique<open_chd>(regiontag);
hash_collection hashes(ROM_GETHASHDATA(romp));
chd_error err;
@ -1175,7 +1173,7 @@ void rom_load_manager::process_disk_entries(const char *regiontag, const rom_ent
if (err != CHDERR_NONE)
{
handle_missing_file(romp, std::string(), err);
global_free(chd);
chd = nullptr;
continue;
}
@ -1205,14 +1203,14 @@ void rom_load_manager::process_disk_entries(const char *regiontag, const rom_ent
{
strcatprintf(m_errorstring, "%s DIFF CHD ERROR: %s\n", filename.c_str(), chd_file::error_string(err));
m_errors++;
global_free(chd);
chd = nullptr;
continue;
}
}
/* we're okay, add to the list of disks */
LOG(("Assigning to handle %d\n", DISK_GETINDEX(romp)));
m_chd_list.append(*chd);
m_chd_list.push_back(std::move(chd));
}
}
}
@ -1478,7 +1476,7 @@ rom_load_manager::rom_load_manager(running_machine &machine)
count_roms();
/* reset the disk list */
m_chd_list.reset();
m_chd_list.clear();
/* process the ROM entries we were passed */
process_region_list();

View File

@ -264,21 +264,16 @@ class rom_load_manager
{
class open_chd
{
friend class simple_list<open_chd>;
public:
open_chd(const char *region)
: m_next(nullptr),
m_region(region) { }
: m_region(region) { }
open_chd *next() const { return m_next; }
const char *region() const { return m_region.c_str(); }
chd_file &chd() { return m_diffchd.opened() ? m_diffchd : m_origchd; }
chd_file &orig_chd() { return m_origchd; }
chd_file &diff_chd() { return m_diffchd; }
private:
open_chd * m_next; /* pointer to next in the list */
std::string m_region; /* disk region we came from */
chd_file m_origchd; /* handle to the original CHD */
chd_file m_diffchd; /* handle to the diff CHD */
@ -344,7 +339,7 @@ private:
UINT32 m_romstotalsize; /* total size of ROMs to read */
emu_file * m_file; /* current file */
simple_list<open_chd> m_chd_list; /* disks */
std::vector<std::unique_ptr<open_chd>> m_chd_list; /* disks */
memory_region * m_region; /* info about current region */