From 4c96644f8db251ed4431b58b26008681dc78878a Mon Sep 17 00:00:00 2001 From: jvoisin Date: Sun, 25 Apr 2021 19:57:09 +0200 Subject: [PATCH] Use a char instead of a string in find() where possible This was done via PVS Studio ( https://pvs-studio.com ), and should provide a super-duper-marginal performance boost \o/ --- apps/openmw/mwgui/tooltips.cpp | 2 +- apps/openmw/mwgui/windowmanagerimp.cpp | 5 +++-- apps/openmw/mwmechanics/character.cpp | 2 +- 3 files changed, 5 insertions(+), 4 deletions(-) diff --git a/apps/openmw/mwgui/tooltips.cpp b/apps/openmw/mwgui/tooltips.cpp index e0a8e4d3e..c0694e403 100644 --- a/apps/openmw/mwgui/tooltips.cpp +++ b/apps/openmw/mwgui/tooltips.cpp @@ -273,7 +273,7 @@ namespace MWGui std::string widgetName = userStringPair.first.substr(underscorePos+1, userStringPair.first.size()-(underscorePos+1)); type = "Property"; - size_t caretPos = key.find("^"); + size_t caretPos = key.find('^'); if (caretPos != std::string::npos) { type = key.substr(0, caretPos); diff --git a/apps/openmw/mwgui/windowmanagerimp.cpp b/apps/openmw/mwgui/windowmanagerimp.cpp index 2f9d357bd..68dd9faa3 100644 --- a/apps/openmw/mwgui/windowmanagerimp.cpp +++ b/apps/openmw/mwgui/windowmanagerimp.cpp @@ -1017,8 +1017,9 @@ namespace MWGui if(tag.compare(0, MyGuiPrefixLength, MyGuiPrefix) == 0) { tag = tag.substr(MyGuiPrefixLength, tag.length()); - std::string settingSection = tag.substr(0, tag.find(",")); - std::string settingTag = tag.substr(tag.find(",")+1, tag.length()); + size_t comma_pos = tag.find(','); + std::string settingSection = tag.substr(0, comma_pos); + std::string settingTag = tag.substr(comma_pos+1, tag.length()); _result = Settings::Manager::getString(settingTag, settingSection); } diff --git a/apps/openmw/mwmechanics/character.cpp b/apps/openmw/mwmechanics/character.cpp index b83d313ce..6758df9c4 100644 --- a/apps/openmw/mwmechanics/character.cpp +++ b/apps/openmw/mwmechanics/character.cpp @@ -966,7 +966,7 @@ void CharacterController::handleTextKey(const std::string &groupname, SceneUtil: // The event can optionally contain volume and pitch modifiers float volume=1.f, pitch=1.f; - if (soundgen.find(" ") != std::string::npos) + if (soundgen.find(' ') != std::string::npos) { std::vector tokens; split(soundgen, ' ', tokens);