diff options
author | Rolf Eike Beer <eike@sf-mail.de> | 2020-03-21 11:57:29 (GMT) |
---|---|---|
committer | Rolf Eike Beer <eike@sf-mail.de> | 2020-03-24 16:50:37 (GMT) |
commit | 8ca2504a4d65f433f88ffb79331cea950789152d (patch) | |
tree | 82cdd893b2457ab1886bccd3ca9c30361e0bc854 /Source/CPack | |
parent | 761f1adcae026c6fd9e10dafdde679adbfaf5869 (diff) | |
download | CMake-8ca2504a4d65f433f88ffb79331cea950789152d.zip CMake-8ca2504a4d65f433f88ffb79331cea950789152d.tar.gz CMake-8ca2504a4d65f433f88ffb79331cea950789152d.tar.bz2 |
use string_views to avoid memory allocations
Diffstat (limited to 'Source/CPack')
-rw-r--r-- | Source/CPack/WiX/cmWIXAccessControlList.cxx | 15 | ||||
-rw-r--r-- | Source/CPack/cmCPackNSISGenerator.cxx | 13 | ||||
-rw-r--r-- | Source/CPack/cmCPackNSISGenerator.h | 5 |
3 files changed, 18 insertions, 15 deletions
diff --git a/Source/CPack/WiX/cmWIXAccessControlList.cxx b/Source/CPack/WiX/cmWIXAccessControlList.cxx index 3668b46..9685a7f 100644 --- a/Source/CPack/WiX/cmWIXAccessControlList.cxx +++ b/Source/CPack/WiX/cmWIXAccessControlList.cxx @@ -2,6 +2,8 @@ file Copyright.txt or https://cmake.org/licensing for details. */ #include "cmWIXAccessControlList.h" +#include <cm/string_view> + #include "cmCPackGenerator.h" #include "cmStringAlgorithms.h" #include "cmSystemTools.h" @@ -35,12 +37,13 @@ void cmWIXAccessControlList::CreatePermissionElement(std::string const& entry) return; } - std::string user_and_domain = entry.substr(0, pos); - std::string permission_string = entry.substr(pos + 1); + cm::string_view enview(entry); + cm::string_view user_and_domain = enview.substr(0, pos); + cm::string_view permission_string = enview.substr(pos + 1); pos = user_and_domain.find('@'); - std::string user; - std::string domain; + cm::string_view user; + cm::string_view domain; if (pos != std::string::npos) { user = user_and_domain.substr(0, pos); domain = user_and_domain.substr(pos + 1); @@ -51,9 +54,9 @@ void cmWIXAccessControlList::CreatePermissionElement(std::string const& entry) std::vector<std::string> permissions = cmTokenize(permission_string, ","); this->SourceWriter.BeginElement("Permission"); - this->SourceWriter.AddAttribute("User", user); + this->SourceWriter.AddAttribute("User", std::string(user)); if (!domain.empty()) { - this->SourceWriter.AddAttribute("Domain", domain); + this->SourceWriter.AddAttribute("Domain", std::string(domain)); } for (std::string const& permission : permissions) { this->EmitBooleanAttribute(entry, cmTrimWhitespace(permission)); diff --git a/Source/CPack/cmCPackNSISGenerator.cxx b/Source/CPack/cmCPackNSISGenerator.cxx index f7edc91..6b30407 100644 --- a/Source/CPack/cmCPackNSISGenerator.cxx +++ b/Source/CPack/cmCPackNSISGenerator.cxx @@ -68,7 +68,7 @@ int cmCPackNSISGenerator::PackageFiles() // Use the custom component install directory if we have one if (pos != std::string::npos) { - const std::string componentName = fileN.substr(0, pos); + auto componentName = cm::string_view(fileN).substr(0, pos); outputDir = CustomComponentInstallDirectory(componentName); } else { outputDir = CustomComponentInstallDirectory(fileN); @@ -672,7 +672,7 @@ std::string cmCPackNSISGenerator::CreateComponentDescription( const std::string componentOutputDir = CustomComponentInstallDirectory(component->Name); - componentCode += " SetOutPath \"" + componentOutputDir + "\"\n"; + componentCode += cmStrCat(" SetOutPath \"", componentOutputDir, "\"\n"); // Create the actual installation commands if (component->IsDownloaded) { @@ -921,12 +921,11 @@ std::string cmCPackNSISGenerator::CreateComponentGroupDescription( } std::string cmCPackNSISGenerator::CustomComponentInstallDirectory( - const std::string& componentName) + cm::string_view componentName) { - const char* outputDir = - this->GetOption("CPACK_NSIS_" + componentName + "_INSTALL_DIRECTORY"); - const std::string componentOutputDir = (outputDir ? outputDir : "$INSTDIR"); - return componentOutputDir; + const char* outputDir = this->GetOption( + cmStrCat("CPACK_NSIS_", componentName, "_INSTALL_DIRECTORY")); + return outputDir ? outputDir : "$INSTDIR"; } std::string cmCPackNSISGenerator::TranslateNewlines(std::string str) diff --git a/Source/CPack/cmCPackNSISGenerator.h b/Source/CPack/cmCPackNSISGenerator.h index 0af37af..88cba45 100644 --- a/Source/CPack/cmCPackNSISGenerator.h +++ b/Source/CPack/cmCPackNSISGenerator.h @@ -10,6 +10,8 @@ #include <string> #include <vector> +#include <cm/string_view> + #include "cmCPackGenerator.h" class cmCPackComponent; @@ -75,8 +77,7 @@ protected: /// Returns the custom install directory if available for the specified /// component, otherwise $INSTDIR is returned. - std::string CustomComponentInstallDirectory( - const std::string& componentName); + std::string CustomComponentInstallDirectory(cm::string_view componentName); /// Translations any newlines found in the string into \\r\\n, so that the /// resulting string can be used within NSIS. |