1
0
mirror of https://gitlab.com/OpenMW/openmw.git synced 2025-01-29 09:32:45 +00:00

Call push_back() if inserting to the end of the vector. It seems MSVC may be generating different code compared to insert().

(copied the changes from commit SHA-1: 257126ed69a5f6f964ba771766de061e81f87433)
This commit is contained in:
cc9cii 2021-07-23 23:17:16 +10:00
parent 44a333b6db
commit 725d689e8a

View File

@ -543,20 +543,25 @@ namespace CSMWorld
void Collection<ESXRecordT, IdAccessorT>::insertRecord (std::unique_ptr<RecordBase> record, int index,
UniversalId::Type type)
{
if (index<0 || index>static_cast<int> (mRecords.size()))
int size = static_cast<int>(mRecords.size());
if (index < 0 || index > size)
throw std::runtime_error ("index out of range");
std::unique_ptr<Record<ESXRecordT> > record2(static_cast<Record<ESXRecordT>*>(record.release()));
std::string lowerId = Misc::StringUtils::lowerCase(IdAccessorT().getId(record2->get()));
mRecords.insert (mRecords.begin()+index, std::move(record2));
if (index == size)
mRecords.push_back (std::move(record2));
else
mRecords.insert (mRecords.begin()+index, std::move(record2));
if (index<static_cast<int> (mRecords.size())-1)
if (index < size-1)
{
for (std::map<std::string, int>::iterator iter (mIndex.begin()); iter!=mIndex.end();
++iter)
if (iter->second>=index)
++(iter->second);
for (std::map<std::string, int>::iterator iter (mIndex.begin()); iter!=mIndex.end(); ++iter)
{
if (iter->second >= index)
++(iter->second);
}
}
mIndex.insert (std::make_pair (lowerId, index));