diff options
author | David Robillard <d@drobilla.net> | 2024-10-06 16:32:41 -0400 |
---|---|---|
committer | David Robillard <d@drobilla.net> | 2024-10-06 18:40:03 -0400 |
commit | 5fe9b2cd3e7ff8f7f23075c980e36d7d456788a8 (patch) | |
tree | c62f1bfc0046ae9a952df2e32f5d23c6aed24a6c | |
parent | 45bd400f71e574bfa2670f13f7c1611ab2089903 (diff) | |
download | ingen-5fe9b2cd3e7ff8f7f23075c980e36d7d456788a8.tar.gz ingen-5fe9b2cd3e7ff8f7f23075c980e36d7d456788a8.tar.bz2 ingen-5fe9b2cd3e7ff8f7f23075c980e36d7d456788a8.zip |
Avoid inefficient use of substr() to set strings to a prefix
-rw-r--r-- | .suppress.cppcheck | 1 | ||||
-rw-r--r-- | src/ClashAvoider.cpp | 2 | ||||
-rw-r--r-- | src/Configuration.cpp | 2 | ||||
-rw-r--r-- | src/client/PluginModel.cpp | 2 | ||||
-rw-r--r-- | src/gui/GraphCanvas.cpp | 2 | ||||
-rw-r--r-- | src/gui/LoadGraphWindow.cpp | 2 | ||||
-rw-r--r-- | src/server/LV2Plugin.cpp | 4 |
7 files changed, 7 insertions, 8 deletions
diff --git a/.suppress.cppcheck b/.suppress.cppcheck index 75896f7e..bad404e6 100644 --- a/.suppress.cppcheck +++ b/.suppress.cppcheck @@ -17,7 +17,6 @@ rethrowNoCurrentException shadowFunction unsafeClassCanLeak useStlAlgorithm -uselessCallsSubstr uselessOverride va_list_usedBeforeStarted variableScope diff --git a/src/ClashAvoider.cpp b/src/ClashAvoider.cpp index 251b8a33..a4f9fbee 100644 --- a/src/ClashAvoider.cpp +++ b/src/ClashAvoider.cpp @@ -62,7 +62,7 @@ ClashAvoider::map_path(const raul::Path& in) // Path without _n suffix std::string base_path_str = in; if (has_offset) { - base_path_str = base_path_str.substr(0, base_path_str.find_last_of('_')); + base_path_str.resize(base_path_str.find_last_of('_')); } raul::Path base_path(base_path_str); diff --git a/src/Configuration.cpp b/src/Configuration.cpp index 918bd9d3..e6461afc 100644 --- a/src/Configuration.cpp +++ b/src/Configuration.cpp @@ -185,7 +185,7 @@ Configuration::parse(int argc, char** argv) std::string name = std::string(argv[i]).substr(2); const char* equals = strchr(argv[i], '='); if (equals) { - name = name.substr(0, name.find('=')); + name.resize(name.find('=')); } const auto o = _options.find(name); diff --git a/src/client/PluginModel.cpp b/src/client/PluginModel.cpp index 333bf568..3036f2e8 100644 --- a/src/client/PluginModel.cpp +++ b/src/client/PluginModel.cpp @@ -103,7 +103,7 @@ PluginModel::get_property(const URI& key) const size_t last_delim = last_uri_delim(str); while (last_delim != string::npos && !contains_alpha_after(str, last_delim)) { - str = str.substr(0, last_delim); + str.resize(last_delim); last_delim = last_uri_delim(str); } str = str.substr(last_delim + 1); diff --git a/src/gui/GraphCanvas.cpp b/src/gui/GraphCanvas.cpp index 6d5c3b5a..2c08fb47 100644 --- a/src/gui/GraphCanvas.cpp +++ b/src/gui/GraphCanvas.cpp @@ -735,7 +735,7 @@ GraphCanvas::paste() if (base_uri) { std::string base = *base_uri; if (base[base.size() - 1] == '/') { - base = base.substr(0, base.size() - 1); + base.resize(base.size() - 1); } copy_root = uri_to_path(URI(base)); } diff --git a/src/gui/LoadGraphWindow.cpp b/src/gui/LoadGraphWindow.cpp index 794cfe71..b118effb 100644 --- a/src/gui/LoadGraphWindow.cpp +++ b/src/gui/LoadGraphWindow.cpp @@ -237,7 +237,7 @@ raul::Symbol LoadGraphWindow::symbol_from_filename(const Glib::ustring& filename) { std::string symbol_str = Glib::path_get_basename(get_filename()); - symbol_str = symbol_str.substr(0, symbol_str.find('.')); + symbol_str.resize(symbol_str.find('.')); return raul::Symbol::symbolify(symbol_str); } diff --git a/src/server/LV2Plugin.cpp b/src/server/LV2Plugin.cpp index ff571d0b..e304e9c0 100644 --- a/src/server/LV2Plugin.cpp +++ b/src/server/LV2Plugin.cpp @@ -71,7 +71,7 @@ LV2Plugin::symbol() const { std::string working = uri(); if (working.back() == '/') { - working = working.substr(0, working.length() - 1); + working.resize(working.length() - 1); } while (!working.empty()) { @@ -82,7 +82,7 @@ LV2Plugin::symbol() const return raul::Symbol::symbolify(symbol); } - working = working.substr(0, last_slash); + working.resize(last_slash); } return raul::Symbol("lv2_symbol"); |