From 0c4040057a842093885cac7d3b08f1ec785a114a Mon Sep 17 00:00:00 2001 From: Daniel Pfeifer Date: Tue, 15 Jul 2025 17:55:47 +0200 Subject: [PATCH] source: Pass cm::string_view by value --- Source/cmArgumentParser.cxx | 16 ++++++---------- Source/cmExportFileGenerator.cxx | 2 +- Source/cmExportInstallFileGenerator.h | 2 +- Source/cmGeneratorExpression.cxx | 5 ++--- Source/cmGeneratorExpression.h | 2 +- .../cmInstallGetRuntimeDependenciesGenerator.cxx | 7 +++---- Source/cmJSONHelpers.h | 8 ++++---- Source/cmPackageInfoReader.cxx | 4 ++-- Source/cmString.hxx | 16 ++++++++++++---- Source/cmSystemTools.cxx | 4 ++-- 10 files changed, 34 insertions(+), 32 deletions(-) diff --git a/Source/cmArgumentParser.cxx b/Source/cmArgumentParser.cxx index 2ea2e6a8cf..765e9cb88c 100644 --- a/Source/cmArgumentParser.cxx +++ b/Source/cmArgumentParser.cxx @@ -14,11 +14,9 @@ namespace ArgumentParser { auto KeywordActionMap::Emplace(cm::string_view name, KeywordAction action) -> std::pair { - 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(); } diff --git a/Source/cmExportFileGenerator.cxx b/Source/cmExportFileGenerator.cxx index 477453dcd2..fdf0dbdad0 100644 --- a/Source/cmExportFileGenerator.cxx +++ b/Source/cmExportFileGenerator.cxx @@ -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 = ";"; diff --git a/Source/cmExportInstallFileGenerator.h b/Source/cmExportInstallFileGenerator.h index 2df326487d..85da19578b 100644 --- a/Source/cmExportInstallFileGenerator.h +++ b/Source/cmExportInstallFileGenerator.h @@ -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; diff --git a/Source/cmGeneratorExpression.cxx b/Source/cmGeneratorExpression.cxx index f35ee52e5f..24a66c4ab2 100644 --- a/Source/cmGeneratorExpression.cxx +++ b/Source/cmGeneratorExpression.cxx @@ -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 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 && diff --git a/Source/cmGeneratorExpression.h b/Source/cmGeneratorExpression.h index e5269b1d99..bda35f48ac 100644 --- a/Source/cmGeneratorExpression.h +++ b/Source/cmGeneratorExpression.h @@ -70,7 +70,7 @@ public: static void Split(std::string const& input, std::vector& 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); diff --git a/Source/cmInstallGetRuntimeDependenciesGenerator.cxx b/Source/cmInstallGetRuntimeDependenciesGenerator.cxx index 9e1ecc1082..0ba9f14434 100644 --- a/Source/cmInstallGetRuntimeDependenciesGenerator.cxx +++ b/Source/cmInstallGetRuntimeDependenciesGenerator.cxx @@ -24,7 +24,7 @@ namespace { template -void WriteMultiArgument(std::ostream& os, cm::string_view const& keyword, +void WriteMultiArgument(std::ostream& os, cm::string_view keyword, std::vector 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> 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 const& genexes, std::string const& config, cmLocalGenerator* lg, diff --git a/Source/cmJSONHelpers.h b/Source/cmJSONHelpers.h index a5f71ddf28..ab96c64287 100644 --- a/Source/cmJSONHelpers.h +++ b/Source/cmJSONHelpers.h @@ -96,7 +96,7 @@ struct cmJSONHelperBuilder } template - 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 - 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 - 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); diff --git a/Source/cmPackageInfoReader.cxx b/Source/cmPackageInfoReader.cxx index abf5e695dc..0def09d03f 100644 --- a/Source/cmPackageInfoReader.cxx +++ b/Source/cmPackageInfoReader.cxx @@ -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)); diff --git a/Source/cmString.hxx b/Source/cmString.hxx index 3c2b49b171..c346230c5d 100644 --- a/Source/cmString.hxx +++ b/Source/cmString.hxx @@ -87,7 +87,7 @@ struct IntoString : std::true_type template <> struct IntoString : 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::true_type template <> struct AsStringView : 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 : 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 : 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 <> diff --git a/Source/cmSystemTools.cxx b/Source/cmSystemTools.cxx index cd7fa08e58..1f16f14959 100644 --- a/Source/cmSystemTools.cxx +++ b/Source/cmSystemTools.cxx @@ -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()) {