1
0
Fork 0
mirror of https://github.com/OpenMW/openmw.git synced 2025-03-31 04:06:40 +00:00

Avoids unecessary copies

Fixed issue with lowerCase

Oups fixed compialtion on openMW_test_suite
This commit is contained in:
florent.teppe 2022-11-13 12:04:57 +01:00
parent b61d5d8123
commit 30a020883e
10 changed files with 27 additions and 28 deletions

View file

@ -186,7 +186,7 @@ void CSMDoc::WriteDialogueCollectionStage::perform(int stage, Messages& messages
{
CSMWorld::InfoCollection::RecordConstIterator prev = iter;
--prev;
std::string prevIdString = (*prev)->get().mId.getRefIdString();
std::string_view prevIdString = (*prev)->get().mId.getRefIdString();
info.mPrev = ESM::RefId::stringRefId(prevIdString.substr(prevIdString.find_last_of('#') + 1));
}
@ -196,7 +196,7 @@ void CSMDoc::WriteDialogueCollectionStage::perform(int stage, Messages& messages
info.mNext = ESM::RefId::sEmpty;
if (next != range.second)
{
std::string nextIdString = (*next)->get().mId.getRefIdString();
std::string_view nextIdString = (*next)->get().mId.getRefIdString();
info.mNext = ESM::RefId::stringRefId(nextIdString.substr(nextIdString.find_last_of('#') + 1));
}

View file

@ -117,7 +117,7 @@ void CSMTools::MergeReferencesStage::perform(int stage, CSMDoc::Messages& messag
ref.mOriginalCell = ref.mCell;
ref.mRefNum.mIndex = mIndex[ref.mCell.getRefIdString()]++;
ref.mRefNum.mIndex = mIndex[Misc::StringUtils::lowerCase(ref.mCell.getRefIdString())]++;
ref.mRefNum.mContentFile = 0;
ref.mNew = false;

View file

@ -909,8 +909,8 @@ void CSMTools::ReferenceableCheckStage::inventoryListCheck(
{
for (size_t i = 0; i < itemList.size(); ++i)
{
ESM::RefId item = itemList[i].mItem;
auto itemName = item.getRefIdString();
const ESM::RefId& item = itemList[i].mItem;
const auto& itemName = item.getRefIdString();
CSMWorld::RefIdData::LocalIndex localIndex = mReferencables.searchId(item);
if (localIndex.first == -1)

View file

@ -331,7 +331,7 @@ namespace CSMWorld
{
auto id = IdAccessorT().getId(record);
auto iter = mIndex.find(id.getRefIdString());
auto iter = mIndex.find(Misc::StringUtils::lowerCase(id.getRefIdString()));
if (iter == mIndex.end())
{
@ -490,7 +490,8 @@ namespace CSMWorld
int Collection<ESXRecordT, IdAccessorT>::searchId(const ESM::RefId& id) const
{
std::map<std::string, int>::const_iterator iter = mIndex.find(id.getRefIdString());
std::map<std::string, int>::const_iterator iter
= mIndex.find(Misc::StringUtils::lowerCase(id.getRefIdString()));
if (iter == mIndex.end())
return -1;
@ -554,7 +555,7 @@ namespace CSMWorld
throw std::runtime_error("index out of range");
std::unique_ptr<Record<ESXRecordT>> record2(static_cast<Record<ESXRecordT>*>(record.release()));
std::string id = IdAccessorT().getId(record2->get()).getRefIdString();
std::string id = Misc::StringUtils::lowerCase(IdAccessorT().getId(record2->get()).getRefIdString());
if (index == size)
mRecords.push_back(std::move(record2));

View file

@ -380,7 +380,7 @@ void CSVRender::PagedWorldspaceWidget::landDataChanged(const QModelIndex& topLef
{
for (int r = topLeft.row(); r <= bottomRight.row(); ++r)
{
auto id = mDocument.getData().getLand().getId(r);
const auto& id = mDocument.getData().getLand().getId(r);
auto cellIt = mCells.find(CSMWorld::CellCoordinates::fromId(id.getRefIdString()).first);
if (cellIt != mCells.end())
@ -395,7 +395,7 @@ void CSVRender::PagedWorldspaceWidget::landAboutToBeRemoved(const QModelIndex& p
{
for (int r = start; r <= end; ++r)
{
auto id = mDocument.getData().getLand().getId(r);
const auto& id = mDocument.getData().getLand().getId(r);
auto cellIt = mCells.find(CSMWorld::CellCoordinates::fromId(id.getRefIdString()).first);
if (cellIt != mCells.end())
@ -410,7 +410,7 @@ void CSVRender::PagedWorldspaceWidget::landAdded(const QModelIndex& parent, int
{
for (int r = start; r <= end; ++r)
{
auto id = mDocument.getData().getLand().getId(r);
const auto& id = mDocument.getData().getLand().getId(r);
auto cellIt = mCells.find(CSMWorld::CellCoordinates::fromId(id.getRefIdString()).first);
if (cellIt != mCells.end())

View file

@ -259,7 +259,7 @@ namespace CSVRender
{
CSMWorld::IdTree* model
= &dynamic_cast<CSMWorld::IdTree&>(*mData.getTableModel(CSMWorld::UniversalId::Type_Pathgrids));
std::string idString = mId.getRefIdString();
const std::string& idString = mId.getRefIdString();
const CSMWorld::Pathgrid* source = getPathgridSource();
if (source)
{

View file

@ -757,7 +757,7 @@ namespace MWRender
bool NpcAnimation::isFirstPersonPart(const ESM::BodyPart* bodypart)
{
const auto partName = bodypart->mId.getRefIdString();
std::string_view partName = bodypart->mId.getRefIdString();
return partName.size() >= 3 && partName.substr(partName.size() - 3, 3) == "1st";
}

View file

@ -30,7 +30,7 @@ namespace
auto& scripts = MWBase::Environment::get().getWorld()->getLocalScripts();
for (const auto&& ptr : store)
{
auto script = ptr.getClass().getScript(ptr);
const auto& script = ptr.getClass().getScript(ptr);
if (!script.empty())
{
MWWorld::Ptr item = ptr;

View file

@ -801,7 +801,7 @@ namespace MWWorld
MWWorld::ContainerStore& container = reference.getClass().getContainerStore(reference);
for (MWWorld::ContainerStoreIterator it = container.begin(); it != container.end(); ++it)
{
auto script = it->getClass().getScript(*it);
const auto& script = it->getClass().getScript(*it);
if (!script.empty())
{
MWWorld::Ptr item = *it;
@ -844,7 +844,7 @@ namespace MWWorld
MWWorld::ContainerStore& container = reference.getClass().getContainerStore(reference);
for (MWWorld::ContainerStoreIterator it = container.begin(); it != container.end(); ++it)
{
auto script = it->getClass().getScript(*it);
const ESM::RefId& script = it->getClass().getScript(*it);
if (!script.empty())
{
MWWorld::Ptr item = *it;
@ -1128,7 +1128,7 @@ namespace MWWorld
&& ptr.getRefData().isEnabled())
{
mWorldScene->addObjectToScene(ptr);
auto script = ptr.getClass().getScript(ptr);
const auto& script = ptr.getClass().getScript(ptr);
if (!script.empty())
mLocalScripts.add(script, ptr);
addContainerScripts(ptr, ptr.getCell());
@ -1189,7 +1189,7 @@ namespace MWWorld
if (newPtr.getRefData().isEnabled())
mWorldScene->addObjectToScene(newPtr);
auto script = newPtr.getClass().getScript(newPtr);
const auto& script = newPtr.getClass().getScript(newPtr);
if (!script.empty())
{
mLocalScripts.add(script, newPtr);
@ -1219,7 +1219,7 @@ namespace MWWorld
MWBase::MechanicsManager* mechMgr = MWBase::Environment::get().getMechanicsManager();
mechMgr->updateCell(ptr, newPtr);
auto script = ptr.getClass().getScript(ptr);
const auto& script = ptr.getClass().getScript(ptr);
if (!script.empty())
{
mLocalScripts.remove(ptr);
@ -2135,7 +2135,7 @@ namespace MWWorld
void World::PCDropped(const Ptr& item)
{
auto script = item.getClass().getScript(item);
const auto& script = item.getClass().getScript(item);
// Set OnPCDrop Variable on item's script, if it has a script with that variable declared
if (!script.empty())
@ -2212,7 +2212,7 @@ namespace MWWorld
{
mWorldScene->addObjectToScene(dropped);
}
auto script = dropped.getClass().getScript(dropped);
const auto& script = dropped.getClass().getScript(dropped);
if (!script.empty())
{
mLocalScripts.add(script, dropped);
@ -2861,14 +2861,12 @@ namespace MWWorld
const ESM::Cell* ext = getExterior(name);
if (!ext)
{
std::string cellName = std::string(name);
size_t comma = cellName.find(',');
size_t comma = name.find(',');
if (comma != std::string::npos)
{
int x, y;
std::from_chars_result xResult = std::from_chars(cellName.data(), cellName.data() + comma, x);
std::from_chars_result yResult
= std::from_chars(cellName.data() + comma + 1, cellName.data() + cellName.size(), y);
std::from_chars_result xResult = std::from_chars(name.data(), name.data() + comma, x);
std::from_chars_result yResult = std::from_chars(name.data() + comma + 1, name.data() + name.size(), y);
if (xResult.ec == std::errc::result_out_of_range || yResult.ec == std::errc::result_out_of_range)
throw std::runtime_error("Cell coordinates out of range.");
else if (xResult.ec == std::errc{} && yResult.ec == std::errc{})
@ -3431,7 +3429,7 @@ namespace MWWorld
return;
}
std::string cellName;
std::string_view cellName;
if (!closestMarker.mCell->isExterior())
cellName = closestMarker.mCell->getCell()->mName;

View file

@ -144,7 +144,7 @@ namespace
class TestInterpreterContext : public Interpreter::Context
{
LocalVariables mLocals;
std::map<std::string, GlobalVariables, std::less<>> mMembers;
std::map<std::string, GlobalVariables, Misc::StringUtils::CiComp> mMembers;
public:
const ESM::RefId& getTarget() const override { return ESM::RefId::sEmpty; }