From 2ed5eafa69939491d782617d83025dff732ef99a Mon Sep 17 00:00:00 2001 From: smf- Date: Wed, 22 Aug 2018 16:20:40 +0100 Subject: [PATCH] Optimise start up by delaying the state save sort and check for duplicates until all the devices have been started. This has the most visible effect on vgmplay because it registers over thirty thousand state save entries. [smf] --- src/emu/save.cpp | 24 +++++++++--------------- 1 file changed, 9 insertions(+), 15 deletions(-) diff --git a/src/emu/save.cpp b/src/emu/save.cpp index 767aadb5ad9..38ad52a9a88 100644 --- a/src/emu/save.cpp +++ b/src/emu/save.cpp @@ -80,6 +80,14 @@ void save_manager::allow_registration(bool allowed) m_reg_allowed = allowed; if (!allowed) { + // look for duplicates + std::sort(m_entry_list.begin(), m_entry_list.end(), + [](std::unique_ptr const& a, std::unique_ptr const& b) { return a->m_name < b->m_name; }); + + for (int i = 0; i < m_entry_list.size() - 1; i++) + if (m_entry_list[i]->m_name == m_entry_list[i + 1]->m_name) + fatalerror("Duplicate save state registration entry (%s)\n", m_entry_list[i]->m_name.c_str()); + dump_registry(); // everything is registered by now, evaluate the savestate size @@ -175,22 +183,8 @@ void save_manager::save_memory(device_t *device, const char *module, const char else totalname = string_format("%s/%X/%s", module, index, name); - // look for duplicates and an entry to insert in front of - std::vector>::iterator insert_after = m_entry_list.begin(); - for (auto it = m_entry_list.begin(); it != m_entry_list.end(); ++it) - { - // stop when we find an entry whose name is after ours - if (it->get()->m_name.compare(totalname)>0) - break; - insert_after = it; - - // error if we are equal - if (it->get()->m_name.compare(totalname)==0) - fatalerror("Duplicate save state registration entry (%s)\n", totalname.c_str()); - } - // insert us into the list - m_entry_list.insert(insert_after, std::make_unique(val, totalname.c_str(), device, module, tag ? tag : "", index, valsize, valcount)); + m_entry_list.emplace_back(std::make_unique(val, totalname.c_str(), device, module, tag ? tag : "", index, valsize, valcount)); }