diff options
author | Christian Göttsche <cgzones@googlemail.com> | 2023-02-21 19:40:56 +0100 |
---|---|---|
committer | Christian Göttsche <cgzones@googlemail.com> | 2023-02-21 19:40:56 +0100 |
commit | a3934549633550ea625604c03e25724664048f40 (patch) | |
tree | b192139bc2d427c0e3d67bc50a7c294ef3178d5f | |
parent | 404761cf4df321580b40baacd50cd3d3e5cb643f (diff) | |
download | patchelf-a3934549633550ea625604c03e25724664048f40.tar.gz |
Avoid unnecessary copies in splitColonDelimitedString()
Avoid creating a stringstream by using find().
-rw-r--r-- | src/patchelf.cc | 17 |
1 files changed, 11 insertions, 6 deletions
diff --git a/src/patchelf.cc b/src/patchelf.cc index 1a67158..946e81c 100644 --- a/src/patchelf.cc +++ b/src/patchelf.cc @@ -24,6 +24,7 @@ #include <sstream> #include <stdexcept> #include <string> +#include <string_view> #include <unordered_map> #include <vector> #include <optional> @@ -69,14 +70,18 @@ static int forcedPageSize = -1; #define EM_LOONGARCH 258 #endif - -static std::vector<std::string> splitColonDelimitedString(const char * s) +[[nodiscard]] static std::vector<std::string> splitColonDelimitedString(std::string_view s) { - std::string item; std::vector<std::string> parts; - std::stringstream ss(s); - while (std::getline(ss, item, ':')) - parts.push_back(item); + + size_t pos; + while ((pos = s.find(':')) != std::string_view::npos) { + parts.emplace_back(s.substr(0, pos)); + s = s.substr(pos + 1); + } + + if (!s.empty()) + parts.emplace_back(s); return parts; } |