1
0
mirror of https://github.com/Kitware/CMake.git synced 2025-10-16 14:08:35 +08:00

source: Pass cm::string_view by value

This commit is contained in:
Daniel Pfeifer
2025-07-15 17:55:47 +02:00
committed by Brad King
parent 1c3300998f
commit 0c4040057a
10 changed files with 34 additions and 32 deletions

View File

@@ -14,11 +14,9 @@ namespace ArgumentParser {
auto KeywordActionMap::Emplace(cm::string_view name, KeywordAction action) auto KeywordActionMap::Emplace(cm::string_view name, KeywordAction action)
-> std::pair<iterator, bool> -> std::pair<iterator, bool>
{ {
auto const it = auto const it = std::lower_bound(
std::lower_bound(this->begin(), this->end(), name, this->begin(), this->end(), name,
[](value_type const& elem, cm::string_view const& k) { [](value_type const& elem, cm::string_view k) { return elem.first < k; });
return elem.first < k;
});
return (it != this->end() && it->first == name) return (it != this->end() && it->first == name)
? std::make_pair(it, false) ? std::make_pair(it, false)
: std::make_pair(this->emplace(it, name, std::move(action)), true); : std::make_pair(this->emplace(it, name, std::move(action)), true);
@@ -26,11 +24,9 @@ auto KeywordActionMap::Emplace(cm::string_view name, KeywordAction action)
auto KeywordActionMap::Find(cm::string_view name) const -> const_iterator auto KeywordActionMap::Find(cm::string_view name) const -> const_iterator
{ {
auto const it = auto const it = std::lower_bound(
std::lower_bound(this->begin(), this->end(), name, this->begin(), this->end(), name,
[](value_type const& elem, cm::string_view const& k) { [](value_type const& elem, cm::string_view k) { return elem.first < k; });
return elem.first < k;
});
return (it != this->end() && it->first == name) ? it : this->end(); return (it != this->end() && it->first == name) ? it : this->end();
} }

View File

@@ -215,7 +215,7 @@ void cmExportFileGenerator::AddImportPrefix(std::string& exportDirs) const
cmGeneratorExpression::Split(exportDirs, entries); cmGeneratorExpression::Split(exportDirs, entries);
exportDirs.clear(); exportDirs.clear();
char const* sep = ""; char const* sep = "";
cm::string_view const& prefixWithSlash = this->GetImportPrefixWithSlash(); cm::string_view const prefixWithSlash = this->GetImportPrefixWithSlash();
for (std::string const& e : entries) { for (std::string const& e : entries) {
exportDirs += sep; exportDirs += sep;
sep = ";"; sep = ";";

View File

@@ -75,7 +75,7 @@ protected:
std::string GetInstallPrefix() const std::string GetInstallPrefix() const
{ {
cm::string_view const& prefixWithSlash = this->GetImportPrefixWithSlash(); cm::string_view const prefixWithSlash = this->GetImportPrefixWithSlash();
return std::string(prefixWithSlash.data(), prefixWithSlash.length() - 1); return std::string(prefixWithSlash.data(), prefixWithSlash.length() - 1);
} }
virtual char GetConfigFileNameSeparator() const = 0; virtual char GetConfigFileNameSeparator() const = 0;

View File

@@ -214,7 +214,7 @@ static std::string stripAllGeneratorExpressions(std::string const& input)
} }
static void prefixItems(std::string const& content, std::string& result, static void prefixItems(std::string const& content, std::string& result,
cm::string_view const& prefix) cm::string_view prefix)
{ {
std::vector<std::string> entries; std::vector<std::string> entries;
cmGeneratorExpression::Split(content, entries); cmGeneratorExpression::Split(content, entries);
@@ -401,8 +401,7 @@ std::string cmGeneratorExpression::Collect(
return extractAllGeneratorExpressions(input, &collected); return extractAllGeneratorExpressions(input, &collected);
} }
cm::string_view::size_type cmGeneratorExpression::Find( cm::string_view::size_type cmGeneratorExpression::Find(cm::string_view input)
cm::string_view const& input)
{ {
cm::string_view::size_type const openpos = input.find("$<"); cm::string_view::size_type const openpos = input.find("$<");
if (openpos != cm::string_view::npos && if (openpos != cm::string_view::npos &&

View File

@@ -70,7 +70,7 @@ public:
static void Split(std::string const& input, static void Split(std::string const& input,
std::vector<std::string>& output); std::vector<std::string>& output);
static cm::string_view::size_type Find(cm::string_view const& input); static cm::string_view::size_type Find(cm::string_view input);
static bool IsValidTargetName(std::string const& input); static bool IsValidTargetName(std::string const& input);

View File

@@ -24,7 +24,7 @@
namespace { namespace {
template <typename T, typename F> template <typename T, typename F>
void WriteMultiArgument(std::ostream& os, cm::string_view const& keyword, void WriteMultiArgument(std::ostream& os, cm::string_view keyword,
std::vector<T> const& list, std::vector<T> const& list,
cmScriptGeneratorIndent indent, F transform) cmScriptGeneratorIndent indent, F transform)
{ {
@@ -42,7 +42,7 @@ void WriteMultiArgument(std::ostream& os, cm::string_view const& keyword,
} }
void WriteFilesArgument( void WriteFilesArgument(
std::ostream& os, cm::string_view const& keyword, std::ostream& os, cm::string_view keyword,
std::vector<std::unique_ptr<cmInstallRuntimeDependencySet::Item>> const& std::vector<std::unique_ptr<cmInstallRuntimeDependencySet::Item>> const&
items, items,
std::string const& config, cmScriptGeneratorIndent indent) std::string const& config, cmScriptGeneratorIndent indent)
@@ -53,8 +53,7 @@ void WriteFilesArgument(
-> std::string { return cmStrCat('"', i->GetItemPath(config), '"'); }); -> std::string { return cmStrCat('"', i->GetItemPath(config), '"'); });
} }
void WriteGenexEvaluatorArgument(std::ostream& os, void WriteGenexEvaluatorArgument(std::ostream& os, cm::string_view keyword,
cm::string_view const& keyword,
std::vector<std::string> const& genexes, std::vector<std::string> const& genexes,
std::string const& config, std::string const& config,
cmLocalGenerator* lg, cmLocalGenerator* lg,

View File

@@ -96,7 +96,7 @@ struct cmJSONHelperBuilder
} }
template <typename U, typename M, typename F> template <typename U, typename M, typename F>
Object& Bind(cm::string_view const& name, M U::*member, F func, Object& Bind(cm::string_view name, M U::*member, F func,
bool required = true) bool required = true)
{ {
return this->BindPrivate( return this->BindPrivate(
@@ -106,7 +106,7 @@ struct cmJSONHelperBuilder
required); required);
} }
template <typename M, typename F> template <typename M, typename F>
Object& Bind(cm::string_view const& name, std::nullptr_t, F func, Object& Bind(cm::string_view name, std::nullptr_t, F func,
bool required = true) bool required = true)
{ {
return this->BindPrivate( return this->BindPrivate(
@@ -119,7 +119,7 @@ struct cmJSONHelperBuilder
required); required);
} }
template <typename F> template <typename F>
Object& Bind(cm::string_view const& name, F func, bool required = true) Object& Bind(cm::string_view name, F func, bool required = true)
{ {
return this->BindPrivate(name, MemberFunction(func), required); return this->BindPrivate(name, MemberFunction(func), required);
} }
@@ -197,7 +197,7 @@ struct cmJSONHelperBuilder
JsonErrors::ObjectErrorGenerator Error; JsonErrors::ObjectErrorGenerator Error;
bool AllowExtra; bool AllowExtra;
Object& BindPrivate(cm::string_view const& name, MemberFunction&& func, Object& BindPrivate(cm::string_view name, MemberFunction&& func,
bool required) bool required)
{ {
this->Members.emplace_back(name, std::move(func), required); this->Members.emplace_back(name, std::move(func), required);

View File

@@ -719,7 +719,7 @@ bool cmPackageInfoReader::ImportTargets(cmMakefile* makefile,
Json::Value const& components = this->Data["components"]; Json::Value const& components = this->Data["components"];
for (auto ci = components.begin(), ce = components.end(); ci != ce; ++ci) { for (auto ci = components.begin(), ce = components.end(); ci != ce; ++ci) {
cm::string_view const& name = IterKey(ci); cm::string_view const name = IterKey(ci);
std::string const& type = std::string const& type =
cmSystemTools::LowerCase((*ci)["type"].asString()); cmSystemTools::LowerCase((*ci)["type"].asString());
@@ -798,7 +798,7 @@ bool cmPackageInfoReader::ImportTargetConfigurations(
for (auto ci = components.begin(), ce = components.end(); ci != ce; ++ci) { for (auto ci = components.begin(), ce = components.end(); ci != ce; ++ci) {
// Get component name and look up target. // Get component name and look up target.
cm::string_view const& name = IterKey(ci); cm::string_view const name = IterKey(ci);
auto const& ti = this->ComponentTargets.find(std::string{ name }); auto const& ti = this->ComponentTargets.find(std::string{ name });
if (ti == this->ComponentTargets.end()) { if (ti == this->ComponentTargets.end()) {
status.SetError(cmStrCat("component "_s, name, " was not found"_s)); status.SetError(cmStrCat("component "_s, name, " was not found"_s));

View File

@@ -87,7 +87,7 @@ struct IntoString<std::string> : std::true_type
template <> template <>
struct IntoString<char> : std::true_type struct IntoString<char> : std::true_type
{ {
static std::string into_string(char const& c) { return std::string(1, c); } static std::string into_string(char c) { return std::string(1, c); }
}; };
/** /**
@@ -142,19 +142,27 @@ struct AsStringView<std::string> : std::true_type
template <> template <>
struct AsStringView<char> : std::true_type struct AsStringView<char> : std::true_type
{ {
static string_view view(char const& s) { return string_view(&s, 1); } static string_view view(
char const& s) // clazy:exclude=function-args-by-value
{
return string_view(&s, 1);
}
}; };
template <> template <>
struct AsStringView<string_view> : std::true_type struct AsStringView<string_view> : std::true_type
{ {
static string_view view(string_view const& s) { return s; } static string_view view(string_view s) { return s; }
}; };
template <> template <>
struct AsStringView<static_string_view> : std::true_type struct AsStringView<static_string_view> : std::true_type
{ {
static string_view view(static_string_view const& s) { return s; } static string_view view(
static_string_view const& s) // clazy:exclude=function-args-by-value
{
return s;
}
}; };
template <> template <>

View File

@@ -3296,8 +3296,8 @@ bool cmSystemTools::GuessLibraryInstallName(std::string const& fullPath,
return false; return false;
} }
static std::string::size_type cmSystemToolsFindRPath( static std::string::size_type cmSystemToolsFindRPath(cm::string_view have,
cm::string_view const& have, cm::string_view const& want) cm::string_view want)
{ {
std::string::size_type pos = 0; std::string::size_type pos = 0;
while (pos < have.size()) { while (pos < have.size()) {