mirror of
https://github.com/Kitware/CMake.git
synced 2025-10-16 22:37:30 +08:00
use string_views to avoid memory allocations
This commit is contained in:
@@ -2,6 +2,8 @@
|
|||||||
file Copyright.txt or https://cmake.org/licensing for details. */
|
file Copyright.txt or https://cmake.org/licensing for details. */
|
||||||
#include "cmWIXAccessControlList.h"
|
#include "cmWIXAccessControlList.h"
|
||||||
|
|
||||||
|
#include <cm/string_view>
|
||||||
|
|
||||||
#include "cmCPackGenerator.h"
|
#include "cmCPackGenerator.h"
|
||||||
#include "cmStringAlgorithms.h"
|
#include "cmStringAlgorithms.h"
|
||||||
#include "cmSystemTools.h"
|
#include "cmSystemTools.h"
|
||||||
@@ -35,12 +37,13 @@ void cmWIXAccessControlList::CreatePermissionElement(std::string const& entry)
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
std::string user_and_domain = entry.substr(0, pos);
|
cm::string_view enview(entry);
|
||||||
std::string permission_string = entry.substr(pos + 1);
|
cm::string_view user_and_domain = enview.substr(0, pos);
|
||||||
|
cm::string_view permission_string = enview.substr(pos + 1);
|
||||||
|
|
||||||
pos = user_and_domain.find('@');
|
pos = user_and_domain.find('@');
|
||||||
std::string user;
|
cm::string_view user;
|
||||||
std::string domain;
|
cm::string_view domain;
|
||||||
if (pos != std::string::npos) {
|
if (pos != std::string::npos) {
|
||||||
user = user_and_domain.substr(0, pos);
|
user = user_and_domain.substr(0, pos);
|
||||||
domain = user_and_domain.substr(pos + 1);
|
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, ",");
|
std::vector<std::string> permissions = cmTokenize(permission_string, ",");
|
||||||
|
|
||||||
this->SourceWriter.BeginElement("Permission");
|
this->SourceWriter.BeginElement("Permission");
|
||||||
this->SourceWriter.AddAttribute("User", user);
|
this->SourceWriter.AddAttribute("User", std::string(user));
|
||||||
if (!domain.empty()) {
|
if (!domain.empty()) {
|
||||||
this->SourceWriter.AddAttribute("Domain", domain);
|
this->SourceWriter.AddAttribute("Domain", std::string(domain));
|
||||||
}
|
}
|
||||||
for (std::string const& permission : permissions) {
|
for (std::string const& permission : permissions) {
|
||||||
this->EmitBooleanAttribute(entry, cmTrimWhitespace(permission));
|
this->EmitBooleanAttribute(entry, cmTrimWhitespace(permission));
|
||||||
|
@@ -68,7 +68,7 @@ int cmCPackNSISGenerator::PackageFiles()
|
|||||||
|
|
||||||
// Use the custom component install directory if we have one
|
// Use the custom component install directory if we have one
|
||||||
if (pos != std::string::npos) {
|
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);
|
outputDir = CustomComponentInstallDirectory(componentName);
|
||||||
} else {
|
} else {
|
||||||
outputDir = CustomComponentInstallDirectory(fileN);
|
outputDir = CustomComponentInstallDirectory(fileN);
|
||||||
@@ -672,7 +672,7 @@ std::string cmCPackNSISGenerator::CreateComponentDescription(
|
|||||||
|
|
||||||
const std::string componentOutputDir =
|
const std::string componentOutputDir =
|
||||||
CustomComponentInstallDirectory(component->Name);
|
CustomComponentInstallDirectory(component->Name);
|
||||||
componentCode += " SetOutPath \"" + componentOutputDir + "\"\n";
|
componentCode += cmStrCat(" SetOutPath \"", componentOutputDir, "\"\n");
|
||||||
|
|
||||||
// Create the actual installation commands
|
// Create the actual installation commands
|
||||||
if (component->IsDownloaded) {
|
if (component->IsDownloaded) {
|
||||||
@@ -921,12 +921,11 @@ std::string cmCPackNSISGenerator::CreateComponentGroupDescription(
|
|||||||
}
|
}
|
||||||
|
|
||||||
std::string cmCPackNSISGenerator::CustomComponentInstallDirectory(
|
std::string cmCPackNSISGenerator::CustomComponentInstallDirectory(
|
||||||
const std::string& componentName)
|
cm::string_view componentName)
|
||||||
{
|
{
|
||||||
const char* outputDir =
|
const char* outputDir = this->GetOption(
|
||||||
this->GetOption("CPACK_NSIS_" + componentName + "_INSTALL_DIRECTORY");
|
cmStrCat("CPACK_NSIS_", componentName, "_INSTALL_DIRECTORY"));
|
||||||
const std::string componentOutputDir = (outputDir ? outputDir : "$INSTDIR");
|
return outputDir ? outputDir : "$INSTDIR";
|
||||||
return componentOutputDir;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
std::string cmCPackNSISGenerator::TranslateNewlines(std::string str)
|
std::string cmCPackNSISGenerator::TranslateNewlines(std::string str)
|
||||||
|
@@ -10,6 +10,8 @@
|
|||||||
#include <string>
|
#include <string>
|
||||||
#include <vector>
|
#include <vector>
|
||||||
|
|
||||||
|
#include <cm/string_view>
|
||||||
|
|
||||||
#include "cmCPackGenerator.h"
|
#include "cmCPackGenerator.h"
|
||||||
|
|
||||||
class cmCPackComponent;
|
class cmCPackComponent;
|
||||||
@@ -75,8 +77,7 @@ protected:
|
|||||||
|
|
||||||
/// Returns the custom install directory if available for the specified
|
/// Returns the custom install directory if available for the specified
|
||||||
/// component, otherwise $INSTDIR is returned.
|
/// component, otherwise $INSTDIR is returned.
|
||||||
std::string CustomComponentInstallDirectory(
|
std::string CustomComponentInstallDirectory(cm::string_view componentName);
|
||||||
const std::string& componentName);
|
|
||||||
|
|
||||||
/// Translations any newlines found in the string into \\r\\n, so that the
|
/// Translations any newlines found in the string into \\r\\n, so that the
|
||||||
/// resulting string can be used within NSIS.
|
/// resulting string can be used within NSIS.
|
||||||
|
@@ -4,6 +4,8 @@
|
|||||||
|
|
||||||
#include <cstring>
|
#include <cstring>
|
||||||
|
|
||||||
|
#include <cm/string_view>
|
||||||
|
|
||||||
#include "cmExecutionStatus.h"
|
#include "cmExecutionStatus.h"
|
||||||
#include "cmMakefile.h"
|
#include "cmMakefile.h"
|
||||||
#include "cmRange.h"
|
#include "cmRange.h"
|
||||||
@@ -86,7 +88,8 @@ bool cmAddSubDirectoryCommand(std::vector<std::string> const& args,
|
|||||||
if (binLen > 0 && bin.back() == '/') {
|
if (binLen > 0 && bin.back() == '/') {
|
||||||
--binLen;
|
--binLen;
|
||||||
}
|
}
|
||||||
binPath = bin.substr(0, binLen) + srcPath.substr(srcLen);
|
binPath = cmStrCat(cm::string_view(bin).substr(0, binLen),
|
||||||
|
cm::string_view(srcPath).substr(srcLen));
|
||||||
} else {
|
} else {
|
||||||
// Use the binary directory specified.
|
// Use the binary directory specified.
|
||||||
// Interpret a relative path with respect to the current binary directory.
|
// Interpret a relative path with respect to the current binary directory.
|
||||||
|
@@ -6,6 +6,7 @@
|
|||||||
#include <sstream>
|
#include <sstream>
|
||||||
|
|
||||||
#include <cm/memory>
|
#include <cm/memory>
|
||||||
|
#include <cm/string_view>
|
||||||
|
|
||||||
#include <cmsys/RegularExpression.hxx>
|
#include <cmsys/RegularExpression.hxx>
|
||||||
|
|
||||||
@@ -26,14 +27,16 @@ static std::string ReplaceOrigin(const std::string& rpath,
|
|||||||
|
|
||||||
cmsys::RegularExpressionMatch match;
|
cmsys::RegularExpressionMatch match;
|
||||||
if (originRegex.find(rpath.c_str(), match)) {
|
if (originRegex.find(rpath.c_str(), match)) {
|
||||||
std::string begin = rpath.substr(0, match.start(1));
|
cm::string_view pathv(rpath);
|
||||||
std::string end = rpath.substr(match.end(1));
|
auto begin = pathv.substr(0, match.start(1));
|
||||||
return begin + origin + end;
|
auto end = pathv.substr(match.end(1));
|
||||||
|
return cmStrCat(begin, origin, end);
|
||||||
}
|
}
|
||||||
if (originCurlyRegex.find(rpath.c_str(), match)) {
|
if (originCurlyRegex.find(rpath.c_str(), match)) {
|
||||||
std::string begin = rpath.substr(0, match.start());
|
cm::string_view pathv(rpath);
|
||||||
std::string end = rpath.substr(match.end());
|
auto begin = pathv.substr(0, match.start());
|
||||||
return begin + origin + end;
|
auto end = pathv.substr(match.end());
|
||||||
|
return cmStrCat(begin, origin, end);
|
||||||
}
|
}
|
||||||
return rpath;
|
return rpath;
|
||||||
}
|
}
|
||||||
|
@@ -17,6 +17,7 @@
|
|||||||
#include <vector>
|
#include <vector>
|
||||||
|
|
||||||
#include <cm/memory>
|
#include <cm/memory>
|
||||||
|
#include <cm/string_view>
|
||||||
#include <cmext/algorithm>
|
#include <cmext/algorithm>
|
||||||
|
|
||||||
#include "cmsys/Base64.h"
|
#include "cmsys/Base64.h"
|
||||||
@@ -2046,13 +2047,15 @@ bool cmCTest::HandleCommandLineArguments(size_t& i,
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
const std::string noTestsPrefix = "--no-tests=";
|
cm::string_view noTestsPrefix = "--no-tests=";
|
||||||
if (cmHasPrefix(arg, noTestsPrefix)) {
|
if (cmHasPrefix(arg, noTestsPrefix)) {
|
||||||
const std::string noTestsMode = arg.substr(noTestsPrefix.length());
|
cm::string_view noTestsMode =
|
||||||
|
cm::string_view(arg).substr(noTestsPrefix.length());
|
||||||
if (noTestsMode == "error") {
|
if (noTestsMode == "error") {
|
||||||
this->Impl->NoTestsMode = cmCTest::NoTests::Error;
|
this->Impl->NoTestsMode = cmCTest::NoTests::Error;
|
||||||
} else if (noTestsMode != "ignore") {
|
} else if (noTestsMode != "ignore") {
|
||||||
errormsg = "'--no-tests=' given unknown value '" + noTestsMode + "'";
|
errormsg =
|
||||||
|
cmStrCat("'--no-tests=' given unknown value '", noTestsMode, '\'');
|
||||||
return false;
|
return false;
|
||||||
} else {
|
} else {
|
||||||
this->Impl->NoTestsMode = cmCTest::NoTests::Ignore;
|
this->Impl->NoTestsMode = cmCTest::NoTests::Ignore;
|
||||||
|
Reference in New Issue
Block a user