Remove various string copies

crashfix_debugdraw
Evil Eye 2 years ago
parent a50b9b9876
commit 0cded25033

@ -115,7 +115,7 @@ namespace MWClass
{
const MWWorld::LiveCellRef<ESM::Armor> *ref = ptr.get<ESM::Armor>();
std::string typeGmst;
std::string_view typeGmst;
switch (ref->mBase->mData.mType)
{
@ -298,7 +298,7 @@ namespace MWClass
if (npc.getClass().isNpc())
{
std::string npcRace = npc.get<ESM::NPC>()->mBase->mRace;
const std::string& npcRace = npc.get<ESM::NPC>()->mBase->mRace;
// Beast races cannot equip shoes / boots, or full helms (head part vs hair part)
const ESM::Race* race = MWBase::Environment::get().getWorld()->getStore().get<ESM::Race>().find(npcRace);

@ -205,7 +205,7 @@ namespace MWClass
if (npc.getClass().isNpc())
{
std::string npcRace = npc.get<ESM::NPC>()->mBase->mRace;
const std::string& npcRace = npc.get<ESM::NPC>()->mBase->mRace;
// Beast races cannot equip shoes / boots, or full helms (head part vs hair part)
const ESM::Race* race = MWBase::Environment::get().getWorld()->getStore().get<ESM::Race>().find(npcRace);

@ -147,8 +147,8 @@ namespace MWClass
return action;
}
const std::string lockedSound = "LockedChest";
const std::string trapActivationSound = "Disarm Trap Fail";
const std::string_view lockedSound = "LockedChest";
const std::string_view trapActivationSound = "Disarm Trap Fail";
MWWorld::Ptr player = MWBase::Environment::get().getWorld ()->getPlayerPtr();
MWWorld::InventoryStore& invStore = player.getClass().getInventoryStore(player);
@ -156,9 +156,9 @@ namespace MWClass
bool isLocked = ptr.getCellRef().getLockLevel() > 0;
bool isTrapped = !ptr.getCellRef().getTrap().empty();
bool hasKey = false;
std::string keyName;
std::string_view keyName;
const std::string keyId = ptr.getCellRef().getKey();
const std::string& keyId = ptr.getCellRef().getKey();
if (!keyId.empty())
{
MWWorld::Ptr keyPtr = invStore.search(keyId);
@ -171,7 +171,7 @@ namespace MWClass
if (isLocked && hasKey)
{
MWBase::Environment::get().getWindowManager ()->messageBox (keyName + " #{sKeyUsed}");
MWBase::Environment::get().getWindowManager ()->messageBox(std::string{keyName} + " #{sKeyUsed}");
ptr.getCellRef().unlock();
// using a key disarms the trap
if(isTrapped)
@ -204,7 +204,7 @@ namespace MWClass
}
else
{
std::unique_ptr<MWWorld::Action> action = std::make_unique<MWWorld::FailedAction>(std::string(), ptr);
std::unique_ptr<MWWorld::Action> action = std::make_unique<MWWorld::FailedAction>(std::string_view{}, ptr);
action->setSound(lockedSound);
return action;
}

@ -132,7 +132,7 @@ namespace MWClass
ptr.get<ESM::CreatureLevList>();
auto& prng = MWBase::Environment::get().getWorld()->getPrng();
std::string id = MWMechanics::getLevelledItem(ref->mBase, true, prng);
std::string_view id = MWMechanics::getLevelledItem(ref->mBase, true, prng);
if (!id.empty())
{

@ -118,18 +118,11 @@ namespace MWClass
const std::string_view lockedSound = "LockedDoor";
const std::string_view trapActivationSound = "Disarm Trap Fail";
MWWorld::ContainerStore &invStore = actor.getClass().getContainerStore(actor);
bool isLocked = ptr.getCellRef().getLockLevel() > 0;
bool isTrapped = !ptr.getCellRef().getTrap().empty();
bool hasKey = false;
std::string keyName;
// FIXME: If NPC activate teleporting door, it can lead to crash due to iterator invalidation in the Actors update.
// Make such activation a no-op for now, like how it is in the vanilla game.
if (actor != MWMechanics::getPlayer() && ptr.getCellRef().getTeleport())
{
std::unique_ptr<MWWorld::Action> action = std::make_unique<MWWorld::FailedAction>(std::string(), ptr);
std::unique_ptr<MWWorld::Action> action = std::make_unique<MWWorld::FailedAction>(std::string_view{}, ptr);
action->setSound(lockedSound);
return action;
}
@ -150,7 +143,13 @@ namespace MWClass
}
}
const std::string keyId = ptr.getCellRef().getKey();
MWWorld::ContainerStore &invStore = actor.getClass().getContainerStore(actor);
bool isLocked = ptr.getCellRef().getLockLevel() > 0;
bool isTrapped = !ptr.getCellRef().getTrap().empty();
bool hasKey = false;
std::string_view keyName;
const std::string& keyId = ptr.getCellRef().getKey();
if (!keyId.empty())
{
MWWorld::Ptr keyPtr = invStore.search(keyId);
@ -164,7 +163,7 @@ namespace MWClass
if (isLocked && hasKey)
{
if(actor == MWMechanics::getPlayer())
MWBase::Environment::get().getWindowManager()->messageBox(keyName + " #{sKeyUsed}");
MWBase::Environment::get().getWindowManager()->messageBox(std::string{keyName} + " #{sKeyUsed}");
ptr.getCellRef().unlock(); //Call the function here. because that makes sense.
// using a key disarms the trap
if(isTrapped)
@ -236,7 +235,7 @@ namespace MWClass
else
{
// locked, and we can't open.
std::unique_ptr<MWWorld::Action> action = std::make_unique<MWWorld::FailedAction>(std::string(), ptr);
std::unique_ptr<MWWorld::Action> action = std::make_unique<MWWorld::FailedAction>(std::string_view{}, ptr);
action->setSound(lockedSound);
return action;
}

@ -1150,7 +1150,7 @@ namespace MWClass
{
MWBase::Environment::get().getWorld()->breakInvisibility(actor);
MWMechanics::CastSpell cast(actor, actor);
std::string recordId = consumable.getCellRef().getRefId();
const std::string& recordId = consumable.getCellRef().getRefId();
MWBase::Environment::get().getLuaManager()->itemConsumed(consumable, actor);
actor.getClass().getContainerStore(actor).remove(consumable, 1, actor);
return cast.cast(recordId);

@ -45,7 +45,7 @@ namespace MWDialogue
Entry::Entry (const ESM::JournalEntry& record) : mInfoId (record.mInfo), mText (record.mText), mActorName(record.mActorName) {}
std::string Entry::getText() const
const std::string& Entry::getText() const
{
return mText;
}

@ -30,7 +30,7 @@ namespace MWDialogue
Entry (const ESM::JournalEntry& record);
std::string getText() const;
const std::string& getText() const;
void write (ESM::JournalEntry& entry) const;
};

@ -96,7 +96,7 @@ namespace MWDialogue
if(quest.addEntry(entry)) // we are doing slicing on purpose here
{
// Restart all "other" quests with the same name as well
std::string name = quest.getName();
std::string_view name = quest.getName();
for(auto& it : mQuests)
{
if(it.second.isFinished() && Misc::StringUtils::ciEqual(it.second.getName(), name))

@ -23,7 +23,7 @@ namespace MWDialogue
: Topic (state.mTopic), mIndex (state.mState), mFinished (state.mFinished!=0)
{}
std::string Quest::getName() const
std::string_view Quest::getName() const
{
const ESM::Dialogue *dialogue =
MWBase::Environment::get().getWorld()->getStore().get<ESM::Dialogue>().find (mTopic);
@ -33,7 +33,7 @@ namespace MWDialogue
if (iter->mQuestStatus==ESM::DialInfo::QS_Name)
return iter->mResponse;
return "";
return {};
}
int Quest::getIndex() const

@ -24,7 +24,7 @@ namespace MWDialogue
Quest (const ESM::QuestState& state);
std::string getName() const override;
std::string_view getName() const override;
///< May be an empty string
int getIndex() const;

@ -44,7 +44,7 @@ namespace MWDialogue
return mTopic;
}
std::string Topic::getName() const
std::string_view Topic::getName() const
{
return mName;
}

@ -47,7 +47,7 @@ namespace MWDialogue
std::string getTopic() const;
virtual std::string getName() const;
virtual std::string_view getName() const;
void removeLastAddedResponse(std::string_view actorName);

@ -55,11 +55,6 @@ namespace MWGui
center();
}
std::string GenerateClassResultDialog::getClassId() const
{
return mClassName->getCaption();
}
void GenerateClassResultDialog::setClassId(const std::string &classId)
{
mCurrentClassId = classId;

@ -71,7 +71,6 @@ namespace MWGui
public:
GenerateClassResultDialog();
std::string getClassId() const;
void setClassId(const std::string &classId);
bool exit() override { return false; }

@ -35,12 +35,12 @@ struct JournalViewModelImpl : JournalViewModel
}
/// \todo replace this nasty BS
static Utf8Span toUtf8Span (std::string const & str)
static Utf8Span toUtf8Span(std::string_view str)
{
if (str.size () == 0)
return Utf8Span (Utf8Point (nullptr), Utf8Point (nullptr));
Utf8Point point = reinterpret_cast <Utf8Point> (str.c_str ());
Utf8Point point = reinterpret_cast<Utf8Point>(str.data());
return Utf8Span (point, point + str.size ());
}
@ -191,11 +191,11 @@ struct JournalViewModelImpl : JournalViewModel
};
void visitQuestNames (bool active_only, std::function <void (const std::string&, bool)> visitor) const override
void visitQuestNames(bool active_only, std::function <void (std::string_view, bool)> visitor) const override
{
MWBase::Journal * journal = MWBase::Environment::get ().getJournal ();
std::set<std::string> visitedQuests;
std::set<std::string, std::less<>> visitedQuests;
// Note that for purposes of the journal GUI, quests are identified by the name, not the ID, so several
// different quest IDs can end up in the same quest log. A quest log should be considered finished
@ -225,7 +225,7 @@ struct JournalViewModelImpl : JournalViewModel
visitor (quest.getName(), isFinished);
visitedQuests.insert(quest.getName());
visitedQuests.emplace(quest.getName());
}
}
}
@ -305,7 +305,7 @@ struct JournalViewModelImpl : JournalViewModel
visitor (toUtf8Span (topic.getName()));
}
void visitTopicNamesStartingWith (Utf8Stream::UnicodeChar character, std::function < void (const std::string&) > visitor) const override
void visitTopicNamesStartingWith(Utf8Stream::UnicodeChar character, std::function < void (std::string_view) > visitor) const override
{
MWBase::Journal * journal = MWBase::Environment::get().getJournal();

@ -73,7 +73,7 @@ namespace MWGui
virtual bool isEmpty () const = 0;
/// walks the active and optionally completed, quests providing the name and completed status
virtual void visitQuestNames (bool active_only, std::function <void (const std::string&, bool)> visitor) const = 0;
virtual void visitQuestNames(bool active_only, std::function <void (std::string_view, bool)> visitor) const = 0;
/// walks over the journal entries related to all quests with the given name
/// If \a questName is empty, simply visits all journal entries
@ -83,7 +83,7 @@ namespace MWGui
virtual void visitTopicName (TopicId topicId, std::function <void (Utf8Span)> visitor) const = 0;
/// walks over the topics whose names start with the character
virtual void visitTopicNamesStartingWith (Utf8Stream::UnicodeChar character, std::function < void (const std::string&) > visitor) const = 0;
virtual void visitTopicNamesStartingWith(Utf8Stream::UnicodeChar character, std::function < void (std::string_view) > visitor) const = 0;
/// walks over the topic entries for the topic specified by its identifier
virtual void visitTopicEntries (TopicId topicId, std::function <void (TopicEntry const &)> visitor) const = 0;

@ -518,7 +518,7 @@ namespace
AddNamesToList(Gui::MWList* list) : mList(list) {}
Gui::MWList* mList;
void operator () (const std::string& name, bool finished=false)
void operator() (std::string_view name, bool finished = false)
{
mList->addItem(name);
}
@ -528,7 +528,7 @@ namespace
SetNamesInactive(Gui::MWList* list) : mList(list) {}
Gui::MWList* mList;
void operator () (const std::string& name, bool finished)
void operator() (std::string_view name, bool finished)
{
if (finished)
{

@ -19,7 +19,7 @@ namespace MWMechanics
{
/// @return ID of resulting item, or empty if none
inline std::string getLevelledItem (const ESM::LevelledListBase* levItem, bool creature, Misc::Rng::Generator& prng)
inline std::string_view getLevelledItem(const ESM::LevelledListBase* levItem, bool creature, Misc::Rng::Generator& prng)
{
const std::vector<ESM::LevelledListBase::LevelItem>& items = levItem->mList;
@ -27,9 +27,9 @@ namespace MWMechanics
int playerLevel = player.getClass().getCreatureStats(player).getLevel();
if (Misc::Rng::roll0to99(prng) < levItem->mChanceNone)
return std::string();
return {};
std::vector<std::string> candidates;
std::vector<std::string_view> candidates;
int highestLevel = 0;
for (const auto& levelledItem : items)
{
@ -42,7 +42,7 @@ namespace MWMechanics
if (creature)
allLevels = levItem->mFlags & ESM::CreatureLevList::AllLevels;
std::pair<int, std::string> highest = std::make_pair(-1, "");
std::pair<int, std::string_view> highest = {-1, {}};
for (const auto& levelledItem : items)
{
if (playerLevel >= levelledItem.mLevel
@ -54,14 +54,14 @@ namespace MWMechanics
}
}
if (candidates.empty())
return std::string();
std::string item = candidates[Misc::Rng::rollDice(candidates.size(), prng)];
return {};
std::string_view item = candidates[Misc::Rng::rollDice(candidates.size(), prng)];
// Vanilla doesn't fail on nonexistent items in levelled lists
if (!MWBase::Environment::get().getWorld()->getStore().find(Misc::StringUtils::lowerCase(item)))
if (!MWBase::Environment::get().getWorld()->getStore().find(item))
{
Log(Debug::Warning) << "Warning: ignoring nonexistent item '" << item << "' in levelled list '" << levItem->mId << "'";
return std::string();
return {};
}
// Is this another levelled item or a real item?

@ -64,7 +64,7 @@ namespace
else
{
auto& prng = MWBase::Environment::get().getWorld()->getPrng();
std::string itemId = MWMechanics::getLevelledItem(itemPtr.get<ESM::ItemLevList>()->mBase, false, prng);
std::string_view itemId = MWMechanics::getLevelledItem(itemPtr.get<ESM::ItemLevList>()->mBase, false, prng);
if (itemId.empty())
return;
MWWorld::ManualRef manualRef(MWBase::Environment::get().getWorld()->getStore(), itemId, 1);

@ -543,7 +543,7 @@ void MWWorld::ContainerStore::fillNonRandom (const ESM::InventoryList& items, co
mResolved = false;
}
void MWWorld::ContainerStore::addInitialItem (const std::string& id, const std::string& owner, int count,
void MWWorld::ContainerStore::addInitialItem(std::string_view id, const std::string& owner, int count,
Misc::Rng::Generator* prng, bool topLevel)
{
if (count == 0) return; //Don't restock with nothing.
@ -584,7 +584,7 @@ void MWWorld::ContainerStore::addInitialItemImp(const MWWorld::Ptr& ptr, const s
}
else
{
std::string itemId = MWMechanics::getLevelledItem(ptr.get<ESM::ItemLevList>()->mBase, false, *prng);
std::string_view itemId = MWMechanics::getLevelledItem(ptr.get<ESM::ItemLevList>()->mBase, false, *prng);
if (itemId.empty())
return;
addInitialItem(itemId, owner, count, prng, false);

@ -126,7 +126,7 @@ namespace MWWorld
std::weak_ptr<ResolutionListener> mResolutionListener;
ContainerStoreIterator addImp (const Ptr& ptr, int count, bool markModified = true);
void addInitialItem (const std::string& id, const std::string& owner, int count, Misc::Rng::Generator* prng, bool topLevel=true);
void addInitialItem(std::string_view id, const std::string& owner, int count, Misc::Rng::Generator* prng, bool topLevel=true);
void addInitialItemImp (const MWWorld::Ptr& ptr, const std::string& owner, int count, Misc::Rng::Generator* prng, bool topLevel=true);
template<typename T>

@ -3692,7 +3692,7 @@ namespace MWWorld
for (int i=0; i<numCreatures; ++i)
{
std::string selectedCreature = MWMechanics::getLevelledItem(list, true, mPrng);
std::string_view selectedCreature = MWMechanics::getLevelledItem(list, true, mPrng);
if (selectedCreature.empty())
continue;

@ -27,9 +27,9 @@ namespace Gui
MyGUI::Align::Top | MyGUI::Align::Left | MyGUI::Align::Stretch, getName() + "_ScrollView");
}
void MWList::addItem(const std::string& name)
void MWList::addItem(std::string_view name)
{
mItems.push_back(name);
mItems.emplace_back(name);
}
void MWList::addSeparator()
@ -152,9 +152,11 @@ namespace Gui
eventWidgetSelected(_sender);
}
MyGUI::Button *MWList::getItemWidget(const std::string& name)
MyGUI::Button* MWList::getItemWidget(std::string_view name)
{
return mScrollView->findWidget (getName() + "_item_" + name)->castType<MyGUI::Button>();
std::string search = getName() + "_item_";
search += name;
return mScrollView->findWidget(search)->castType<MyGUI::Button>();
}
void MWList::scrollToTop()

@ -36,14 +36,14 @@ namespace Gui
*/
void adjustSize();
void addItem(const std::string& name);
void addItem(std::string_view name);
void addSeparator(); ///< add a seperator between the current and the next item.
void removeItem(const std::string& name);
unsigned int getItemCount();
std::string getItemNameAt(unsigned int at); ///< \attention if there are separators, this method will return "" at the place where the separator is
void clear();
MyGUI::Button* getItemWidget(const std::string& name);
MyGUI::Button* getItemWidget(std::string_view name);
///< get widget for an item name, useful to set up tooltip
void scrollToTop();

Loading…
Cancel
Save