summaryrefslogtreecommitdiffstats
path: root/Source/cmStringAlgorithms.cxx
diff options
context:
space:
mode:
authorKyle Edwards <kyle.edwards@kitware.com>2022-11-29 21:59:24 (GMT)
committerKyle Edwards <kyle.edwards@kitware.com>2022-11-30 05:05:09 (GMT)
commitbeba50bd61d32ea68acffca67a48bd7e81e6e097 (patch)
tree7df1a3f4f832cdafb37cc38850a6699edec6f5d4 /Source/cmStringAlgorithms.cxx
parentd6f2a7ab4b6cbb6648928c5da6cd0bf845025126 (diff)
downloadCMake-beba50bd61d32ea68acffca67a48bd7e81e6e097.zip
CMake-beba50bd61d32ea68acffca67a48bd7e81e6e097.tar.gz
CMake-beba50bd61d32ea68acffca67a48bd7e81e6e097.tar.bz2
cmStrCat(): optimize when first argument is an rvalue string
Diffstat (limited to 'Source/cmStringAlgorithms.cxx')
-rw-r--r--Source/cmStringAlgorithms.cxx18
1 files changed, 13 insertions, 5 deletions
diff --git a/Source/cmStringAlgorithms.cxx b/Source/cmStringAlgorithms.cxx
index f73c854..e559cfa 100644
--- a/Source/cmStringAlgorithms.cxx
+++ b/Source/cmStringAlgorithms.cxx
@@ -203,15 +203,23 @@ cmAlphaNum::cmAlphaNum(double val)
MakeDigits(this->View_, this->Digits_, "%g", val);
}
-std::string cmCatViews(std::initializer_list<cm::string_view> views)
+std::string cmCatViews(cm::optional<std::string>&& first,
+ std::initializer_list<cm::string_view> views)
{
- std::size_t total_size = 0;
+ std::size_t totalSize = 0;
for (cm::string_view const& view : views) {
- total_size += view.size();
+ totalSize += view.size();
}
- std::string result(total_size, '\0');
- std::string::iterator sit = result.begin();
+ std::string result;
+ std::string::size_type initialLen = 0;
+ if (first) {
+ totalSize += first->length();
+ initialLen = first->length();
+ result = std::move(*first);
+ }
+ result.resize(totalSize);
+ std::string::iterator sit = result.begin() + initialLen;
for (cm::string_view const& view : views) {
sit = std::copy_n(view.data(), view.size(), sit);
}