Pass string views by value
string_view should always be passed by value; This commit is a sed
replace of the code to make all string_views pass by value, per general
coding guidelines[1].
[1] https://quuxplusone.github.io/blog/2021/11/09/pass-string-view-by-value/
Tested: Code compiles.
Signed-off-by: Ed Tanous <edtanous@google.com>
Change-Id: I55b342a29a0fbfce0a4ed9ea63db6014d03b134c
diff --git a/redfish-core/include/event_service_manager.hpp b/redfish-core/include/event_service_manager.hpp
index 976d043..9668e5d 100644
--- a/redfish-core/include/event_service_manager.hpp
+++ b/redfish-core/include/event_service_manager.hpp
@@ -114,7 +114,7 @@
return nullptr;
}
-static const Message* formatMessage(const std::string_view& messageID)
+static const Message* formatMessage(std::string_view messageID)
{
// Redfish MessageIds are in the form
// RegistryName.MajorVersion.MinorVersion.MessageKey, so parse it to find
diff --git a/redfish-core/include/privileges.hpp b/redfish-core/include/privileges.hpp
index 6227681..08e554a 100644
--- a/redfish-core/include/privileges.hpp
+++ b/redfish-core/include/privileges.hpp
@@ -110,7 +110,7 @@
* @return None
*
*/
- bool setSinglePrivilege(const std::string_view privilege)
+ bool setSinglePrivilege(std::string_view privilege)
{
for (size_t searchIndex = 0; searchIndex < privilegeNames.size();
searchIndex++)
diff --git a/redfish-core/include/redfish_aggregator.hpp b/redfish-core/include/redfish_aggregator.hpp
index c2c2e1d..080e67e 100644
--- a/redfish-core/include/redfish_aggregator.hpp
+++ b/redfish-core/include/redfish_aggregator.hpp
@@ -44,7 +44,7 @@
// Determines if the passed property contains a URI. Those property names
// either end with a case-insensitive version of "uri" or are specifically
// defined in the above array.
-inline bool isPropertyUri(const std::string_view propertyName)
+inline bool isPropertyUri(std::string_view propertyName)
{
return boost::iends_with(propertyName, "uri") ||
std::binary_search(nonUriProperties.begin(), nonUriProperties.end(),
diff --git a/redfish-core/include/registries.hpp b/redfish-core/include/registries.hpp
index da8fa85..03e8bc5 100644
--- a/redfish-core/include/registries.hpp
+++ b/redfish-core/include/registries.hpp
@@ -61,7 +61,7 @@
{
std::string ret;
size_t reserve = msg.size();
- for (const std::string_view& arg : messageArgs)
+ for (std::string_view arg : messageArgs)
{
reserve += arg.size();
}
@@ -102,7 +102,7 @@
std::string msg =
redfish::registries::fillMessageArgs(args, entry.second.message);
nlohmann::json jArgs = nlohmann::json::array();
- for (const std::string_view arg : args)
+ for (std::string_view arg : args)
{
jArgs.push_back(arg);
}
diff --git a/redfish-core/include/resource_messages.hpp b/redfish-core/include/resource_messages.hpp
index 3153935..309b293 100644
--- a/redfish-core/include/resource_messages.hpp
+++ b/redfish-core/include/resource_messages.hpp
@@ -11,7 +11,7 @@
inline nlohmann::json
getLogResourceEvent(redfish::registries::resource_event::Index name,
- std::span<const std::string_view> args)
+ std::span<std::string_view> args)
{
size_t index = static_cast<size_t>(name);
if (index >= redfish::registries::resource_event::registry.size())
diff --git a/redfish-core/lib/certificate_service.hpp b/redfish-core/lib/certificate_service.hpp
index 16f26e3..93cb366 100644
--- a/redfish-core/lib/certificate_service.hpp
+++ b/redfish-core/lib/certificate_service.hpp
@@ -148,7 +148,7 @@
* @return None
*/
static void updateCertIssuerOrSubject(nlohmann::json& out,
- const std::string_view value)
+ std::string_view value)
{
// example: O=openbmc-project.xyz,CN=localhost
std::string_view::iterator i = value.begin();
@@ -163,16 +163,14 @@
{
break;
}
- const std::string_view key(tokenBegin,
- static_cast<size_t>(i - tokenBegin));
+ std::string_view key(tokenBegin, static_cast<size_t>(i - tokenBegin));
++i;
tokenBegin = i;
while (i != value.end() && *i != ',')
{
++i;
}
- const std::string_view val(tokenBegin,
- static_cast<size_t>(i - tokenBegin));
+ std::string_view val(tokenBegin, static_cast<size_t>(i - tokenBegin));
if (key == "L")
{
out["City"] = val;
diff --git a/redfish-core/lib/log_services.hpp b/redfish-core/lib/log_services.hpp
index bb9552a..ee57557 100644
--- a/redfish-core/lib/log_services.hpp
+++ b/redfish-core/lib/log_services.hpp
@@ -91,7 +91,7 @@
return nullptr;
}
-static const Message* getMessage(const std::string_view& messageID)
+static const Message* getMessage(std::string_view messageID)
{
// Redfish MessageIds are in the form
// RegistryName.MajorVersion.MinorVersion.MessageKey, so parse it to find
@@ -157,7 +157,7 @@
}
inline static int getJournalMetadata(sd_journal* journal,
- const std::string_view& field,
+ std::string_view field,
std::string_view& contents)
{
const char* data = nullptr;
@@ -179,8 +179,8 @@
}
inline static int getJournalMetadata(sd_journal* journal,
- const std::string_view& field,
- const int& base, long int& contents)
+ std::string_view field, const int& base,
+ long int& contents)
{
int ret = 0;
std::string_view metadata;
@@ -3321,8 +3321,7 @@
invalid,
};
-inline OEMDiagnosticType
- getOEMDiagnosticType(const std::string_view& oemDiagStr)
+inline OEMDiagnosticType getOEMDiagnosticType(std::string_view oemDiagStr)
{
if (oemDiagStr == "OnDemand")
{
diff --git a/redfish-core/lib/redfish_v1.hpp b/redfish-core/lib/redfish_v1.hpp
index b4349ab..4cae985 100644
--- a/redfish-core/lib/redfish_v1.hpp
+++ b/redfish-core/lib/redfish_v1.hpp
@@ -83,7 +83,7 @@
json["Name"] = "JsonSchemaFile Collection";
json["Description"] = "Collection of JsonSchemaFiles";
nlohmann::json::array_t members;
- for (const std::string_view schema : schemas)
+ for (std::string_view schema : schemas)
{
nlohmann::json::object_t member;
member["@odata.id"] = crow::utility::urlFromPieces(
diff --git a/redfish-core/lib/task.hpp b/redfish-core/lib/task.hpp
index 563f06f..95fa0c0 100644
--- a/redfish-core/lib/task.hpp
+++ b/redfish-core/lib/task.hpp
@@ -196,7 +196,7 @@
});
}
- static void sendTaskEvent(const std::string_view state, size_t index)
+ static void sendTaskEvent(std::string_view state, size_t index)
{
std::string origin =
"/redfish/v1/TaskService/Tasks/" + std::to_string(index);