From 339d347aea7fe71642d75582214cbbe5eb51614f Mon Sep 17 00:00:00 2001 From: Thunderforge Date: Mon, 10 May 2021 22:44:07 -0500 Subject: [PATCH] Fixing performance-faster-string-find issues This addresses the Clang Tidy check [performance-faster-string-find](https://clang.llvm.org/extra/clang-tidy/checks/performance-faster-string-find.html). --- apps/mwiniimporter/importer.cpp | 8 ++++---- apps/niftest/niftest.cpp | 2 +- apps/opencs/model/prefs/shortcutmanager.cpp | 6 +++--- apps/opencs/view/render/terraintexturemode.cpp | 2 +- apps/openmw/mwgui/tooltips.cpp | 2 +- components/debug/gldebug.cpp | 2 +- components/fallback/validate.cpp | 2 +- components/resource/scenemanager.cpp | 2 +- components/widgets/imagebutton.cpp | 2 +- 9 files changed, 14 insertions(+), 14 deletions(-) diff --git a/apps/mwiniimporter/importer.cpp b/apps/mwiniimporter/importer.cpp index 23aea2deb..94b5cf7d0 100644 --- a/apps/mwiniimporter/importer.cpp +++ b/apps/mwiniimporter/importer.cpp @@ -686,12 +686,12 @@ MwIniImporter::multistrmap MwIniImporter::loadIniFile(const boost::filesystem::p continue; } - int comment_pos = line.find(";"); + int comment_pos = line.find(';'); if(comment_pos > 0) { line = line.substr(0,comment_pos); } - int pos = line.find("="); + int pos = line.find('='); if(pos < 1) { continue; } @@ -722,7 +722,7 @@ MwIniImporter::multistrmap MwIniImporter::loadCfgFile(const boost::filesystem::p while (std::getline(file, line)) { // we cant say comment by only looking at first char anymore - int comment_pos = line.find("#"); + int comment_pos = line.find('#'); if(comment_pos > 0) { line = line.substr(0,comment_pos); } @@ -731,7 +731,7 @@ MwIniImporter::multistrmap MwIniImporter::loadCfgFile(const boost::filesystem::p continue; } - int pos = line.find("="); + int pos = line.find('='); if(pos < 1) { continue; } diff --git a/apps/niftest/niftest.cpp b/apps/niftest/niftest.cpp index e9484d5f5..e403562d3 100644 --- a/apps/niftest/niftest.cpp +++ b/apps/niftest/niftest.cpp @@ -20,7 +20,7 @@ namespace bfs = boost::filesystem; ///See if the file has the named extension bool hasExtension(std::string filename, std::string extensionToFind) { - std::string extension = filename.substr(filename.find_last_of(".")+1); + std::string extension = filename.substr(filename.find_last_of('.')+1); //Convert strings to lower case for comparison std::transform(extension.begin(), extension.end(), extension.begin(), ::tolower); diff --git a/apps/opencs/model/prefs/shortcutmanager.cpp b/apps/opencs/model/prefs/shortcutmanager.cpp index 781ad4de3..4c5f77900 100644 --- a/apps/opencs/model/prefs/shortcutmanager.cpp +++ b/apps/opencs/model/prefs/shortcutmanager.cpp @@ -178,7 +178,7 @@ namespace CSMPrefs { const int MaxKeys = 4; // A limitation of QKeySequence - size_t end = data.find(";"); + size_t end = data.find(';'); size_t size = std::min(end, data.size()); std::string value = data.substr(0, size); @@ -191,7 +191,7 @@ namespace CSMPrefs while (start < value.size()) { - end = data.find("+", start); + end = data.find('+', start); end = std::min(end, value.size()); std::string name = value.substr(start, end - start); @@ -243,7 +243,7 @@ namespace CSMPrefs void ShortcutManager::convertFromString(const std::string& data, int& modifier) const { - size_t start = data.find(";") + 1; + size_t start = data.find(';') + 1; start = std::min(start, data.size()); std::string name = data.substr(start); diff --git a/apps/opencs/view/render/terraintexturemode.cpp b/apps/opencs/view/render/terraintexturemode.cpp index fa46cf673..1519d3efd 100644 --- a/apps/opencs/view/render/terraintexturemode.cpp +++ b/apps/opencs/view/render/terraintexturemode.cpp @@ -332,7 +332,7 @@ void CSVRender::TerrainTextureMode::editTerrainTextureGrid(const WorldspaceHitRe int textureColumn = landTable.findColumnIndex(CSMWorld::Columns::ColumnId_LandTexturesIndex); - std::size_t hashlocation = mBrushTexture.find("#"); + std::size_t hashlocation = mBrushTexture.find('#'); std::string mBrushTextureInt = mBrushTexture.substr (hashlocation+1); int brushInt = stoi(mBrushTexture.substr (hashlocation+1))+1; // All indices are offset by +1 diff --git a/apps/openmw/mwgui/tooltips.cpp b/apps/openmw/mwgui/tooltips.cpp index c0694e403..a821d0106 100644 --- a/apps/openmw/mwgui/tooltips.cpp +++ b/apps/openmw/mwgui/tooltips.cpp @@ -266,7 +266,7 @@ namespace MWGui std::map userStrings = focus->getUserStrings(); for (auto& userStringPair : userStrings) { - size_t underscorePos = userStringPair.first.find("_"); + size_t underscorePos = userStringPair.first.find('_'); if (underscorePos == std::string::npos) continue; std::string key = userStringPair.first.substr(0, underscorePos); diff --git a/components/debug/gldebug.cpp b/components/debug/gldebug.cpp index 37829a8c1..ccf49edd4 100644 --- a/components/debug/gldebug.cpp +++ b/components/debug/gldebug.cpp @@ -179,7 +179,7 @@ namespace Debug if (str.length() == 0) return true; - return str.find("OFF") == std::string::npos && str.find("0") == std::string::npos && str.find("NO") == std::string::npos; + return str.find("OFF") == std::string::npos && str.find('0') == std::string::npos && str.find("NO") == std::string::npos; } DebugGroup::DebugGroup(const std::string & message, GLuint id) diff --git a/components/fallback/validate.cpp b/components/fallback/validate.cpp index 982c709af..a482d40fa 100644 --- a/components/fallback/validate.cpp +++ b/components/fallback/validate.cpp @@ -12,7 +12,7 @@ void Fallback::validate(boost::any& v, std::vector const& tokens, F for (const auto& token : tokens) { std::string temp = Files::EscapeHashString::processString(token); - size_t sep = temp.find(","); + size_t sep = temp.find(','); if (sep < 1 || sep == temp.length() - 1 || sep == std::string::npos) throw boost::program_options::validation_error(boost::program_options::validation_error::invalid_option_value); diff --git a/components/resource/scenemanager.cpp b/components/resource/scenemanager.cpp index a3c751f7a..2e2fb9aa1 100644 --- a/components/resource/scenemanager.cpp +++ b/components/resource/scenemanager.cpp @@ -500,7 +500,7 @@ namespace Resource { std::string str(env); - if(str.find("OFF")!=std::string::npos || str.find("0")!= std::string::npos) options = 0; + if(str.find("OFF")!=std::string::npos || str.find('0')!= std::string::npos) options = 0; if(str.find("~FLATTEN_STATIC_TRANSFORMS")!=std::string::npos) options ^= Optimizer::FLATTEN_STATIC_TRANSFORMS; else if(str.find("FLATTEN_STATIC_TRANSFORMS")!=std::string::npos) options |= Optimizer::FLATTEN_STATIC_TRANSFORMS; diff --git a/components/widgets/imagebutton.cpp b/components/widgets/imagebutton.cpp index 0d1f798da..bf2b1b24c 100644 --- a/components/widgets/imagebutton.cpp +++ b/components/widgets/imagebutton.cpp @@ -118,7 +118,7 @@ namespace Gui void ImageButton::setImage(const std::string &image) { - size_t extpos = image.find_last_of("."); + size_t extpos = image.find_last_of('.'); std::string imageNoExt = image.substr(0, extpos); std::string ext = image.substr(extpos);