mirror of
https://github.com/Kitware/CMake.git
synced 2025-10-15 20:46:37 +08:00
source: Pass cm::string_view by value
This commit is contained in:

committed by
Brad King

parent
1c3300998f
commit
0c4040057a
@@ -14,11 +14,9 @@ namespace ArgumentParser {
|
||||
auto KeywordActionMap::Emplace(cm::string_view name, KeywordAction action)
|
||||
-> std::pair<iterator, bool>
|
||||
{
|
||||
auto const it =
|
||||
std::lower_bound(this->begin(), this->end(), name,
|
||||
[](value_type const& elem, cm::string_view const& k) {
|
||||
return elem.first < k;
|
||||
});
|
||||
auto const it = std::lower_bound(
|
||||
this->begin(), this->end(), name,
|
||||
[](value_type const& elem, cm::string_view k) { return elem.first < k; });
|
||||
return (it != this->end() && it->first == name)
|
||||
? std::make_pair(it, false)
|
||||
: 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 const it =
|
||||
std::lower_bound(this->begin(), this->end(), name,
|
||||
[](value_type const& elem, cm::string_view const& k) {
|
||||
return elem.first < k;
|
||||
});
|
||||
auto const it = std::lower_bound(
|
||||
this->begin(), this->end(), name,
|
||||
[](value_type const& elem, cm::string_view k) { return elem.first < k; });
|
||||
return (it != this->end() && it->first == name) ? it : this->end();
|
||||
}
|
||||
|
||||
|
@@ -215,7 +215,7 @@ void cmExportFileGenerator::AddImportPrefix(std::string& exportDirs) const
|
||||
cmGeneratorExpression::Split(exportDirs, entries);
|
||||
exportDirs.clear();
|
||||
char const* sep = "";
|
||||
cm::string_view const& prefixWithSlash = this->GetImportPrefixWithSlash();
|
||||
cm::string_view const prefixWithSlash = this->GetImportPrefixWithSlash();
|
||||
for (std::string const& e : entries) {
|
||||
exportDirs += sep;
|
||||
sep = ";";
|
||||
|
@@ -75,7 +75,7 @@ protected:
|
||||
|
||||
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);
|
||||
}
|
||||
virtual char GetConfigFileNameSeparator() const = 0;
|
||||
|
@@ -214,7 +214,7 @@ static std::string stripAllGeneratorExpressions(std::string const& input)
|
||||
}
|
||||
|
||||
static void prefixItems(std::string const& content, std::string& result,
|
||||
cm::string_view const& prefix)
|
||||
cm::string_view prefix)
|
||||
{
|
||||
std::vector<std::string> entries;
|
||||
cmGeneratorExpression::Split(content, entries);
|
||||
@@ -401,8 +401,7 @@ std::string cmGeneratorExpression::Collect(
|
||||
return extractAllGeneratorExpressions(input, &collected);
|
||||
}
|
||||
|
||||
cm::string_view::size_type cmGeneratorExpression::Find(
|
||||
cm::string_view const& input)
|
||||
cm::string_view::size_type cmGeneratorExpression::Find(cm::string_view input)
|
||||
{
|
||||
cm::string_view::size_type const openpos = input.find("$<");
|
||||
if (openpos != cm::string_view::npos &&
|
||||
|
@@ -70,7 +70,7 @@ public:
|
||||
static void Split(std::string const& input,
|
||||
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);
|
||||
|
||||
|
@@ -24,7 +24,7 @@
|
||||
|
||||
namespace {
|
||||
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,
|
||||
cmScriptGeneratorIndent indent, F transform)
|
||||
{
|
||||
@@ -42,7 +42,7 @@ void WriteMultiArgument(std::ostream& os, cm::string_view const& keyword,
|
||||
}
|
||||
|
||||
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&
|
||||
items,
|
||||
std::string const& config, cmScriptGeneratorIndent indent)
|
||||
@@ -53,8 +53,7 @@ void WriteFilesArgument(
|
||||
-> std::string { return cmStrCat('"', i->GetItemPath(config), '"'); });
|
||||
}
|
||||
|
||||
void WriteGenexEvaluatorArgument(std::ostream& os,
|
||||
cm::string_view const& keyword,
|
||||
void WriteGenexEvaluatorArgument(std::ostream& os, cm::string_view keyword,
|
||||
std::vector<std::string> const& genexes,
|
||||
std::string const& config,
|
||||
cmLocalGenerator* lg,
|
||||
|
@@ -96,7 +96,7 @@ struct cmJSONHelperBuilder
|
||||
}
|
||||
|
||||
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)
|
||||
{
|
||||
return this->BindPrivate(
|
||||
@@ -106,7 +106,7 @@ struct cmJSONHelperBuilder
|
||||
required);
|
||||
}
|
||||
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)
|
||||
{
|
||||
return this->BindPrivate(
|
||||
@@ -119,7 +119,7 @@ struct cmJSONHelperBuilder
|
||||
required);
|
||||
}
|
||||
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);
|
||||
}
|
||||
@@ -197,7 +197,7 @@ struct cmJSONHelperBuilder
|
||||
JsonErrors::ObjectErrorGenerator Error;
|
||||
bool AllowExtra;
|
||||
|
||||
Object& BindPrivate(cm::string_view const& name, MemberFunction&& func,
|
||||
Object& BindPrivate(cm::string_view name, MemberFunction&& func,
|
||||
bool required)
|
||||
{
|
||||
this->Members.emplace_back(name, std::move(func), required);
|
||||
|
@@ -719,7 +719,7 @@ bool cmPackageInfoReader::ImportTargets(cmMakefile* makefile,
|
||||
Json::Value const& components = this->Data["components"];
|
||||
|
||||
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 =
|
||||
cmSystemTools::LowerCase((*ci)["type"].asString());
|
||||
|
||||
@@ -798,7 +798,7 @@ bool cmPackageInfoReader::ImportTargetConfigurations(
|
||||
|
||||
for (auto ci = components.begin(), ce = components.end(); ci != ce; ++ci) {
|
||||
// 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 });
|
||||
if (ti == this->ComponentTargets.end()) {
|
||||
status.SetError(cmStrCat("component "_s, name, " was not found"_s));
|
||||
|
@@ -87,7 +87,7 @@ struct IntoString<std::string> : std::true_type
|
||||
template <>
|
||||
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 <>
|
||||
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 <>
|
||||
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 <>
|
||||
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 <>
|
||||
|
@@ -3296,8 +3296,8 @@ bool cmSystemTools::GuessLibraryInstallName(std::string const& fullPath,
|
||||
return false;
|
||||
}
|
||||
|
||||
static std::string::size_type cmSystemToolsFindRPath(
|
||||
cm::string_view const& have, cm::string_view const& want)
|
||||
static std::string::size_type cmSystemToolsFindRPath(cm::string_view have,
|
||||
cm::string_view want)
|
||||
{
|
||||
std::string::size_type pos = 0;
|
||||
while (pos < have.size()) {
|
||||
|
Reference in New Issue
Block a user