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/http/http_request.hpp b/http/http_request.hpp
index d203077..405db87 100644
--- a/http/http_request.hpp
+++ b/http/http_request.hpp
@@ -92,7 +92,7 @@
return req.target();
}
- bool target(const std::string_view target)
+ bool target(std::string_view target)
{
req.target(target);
return setUrlInfo();
diff --git a/http/http_response.hpp b/http/http_response.hpp
index f9204e4..5cbdb28 100644
--- a/http/http_response.hpp
+++ b/http/http_response.hpp
@@ -27,7 +27,7 @@
nlohmann::json jsonValue;
- void addHeader(const std::string_view key, const std::string_view value)
+ void addHeader(std::string_view key, std::string_view value)
{
stringResponse->set(key, value);
}
diff --git a/http/routing.hpp b/http/routing.hpp
index 5b3ddfe..ae63f05 100644
--- a/http/routing.hpp
+++ b/http/routing.hpp
@@ -422,7 +422,7 @@
return *p;
}
- self_t& name(const std::string_view name) noexcept
+ self_t& name(std::string_view name) noexcept
{
self_t* self = static_cast<self_t*>(this);
self->nameStr = name;
@@ -663,7 +663,7 @@
}
template <typename Func>
- void operator()(const std::string_view name, Func&& f)
+ void operator()(std::string_view name, Func&& f)
{
nameStr = name;
(*this).template operator()<Func>(std::forward(f));
@@ -807,7 +807,7 @@
}
std::pair<unsigned, RoutingParams>
- find(const std::string_view reqUrl, const Node* node = nullptr,
+ find(std::string_view reqUrl, const Node* node = nullptr,
size_t pos = 0, RoutingParams* params = nullptr) const
{
RoutingParams empty;
diff --git a/http/utility.hpp b/http/utility.hpp
index 4ea44d5..71f39c8 100644
--- a/http/utility.hpp
+++ b/http/utility.hpp
@@ -378,7 +378,7 @@
using arg = std::tuple_element_t<i, boost::callable_traits::args_t<T>>;
};
-inline std::string base64encode(const std::string_view data)
+inline std::string base64encode(std::string_view data)
{
const std::array<char, 64> key = {
'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M',
@@ -438,7 +438,7 @@
// TODO this is temporary and should be deleted once base64 is refactored out of
// crow
-inline bool base64Decode(const std::string_view input, std::string& output)
+inline bool base64Decode(std::string_view input, std::string& output)
{
static const char nop = static_cast<char>(-1);
// See note on encoding_data[] in above function
@@ -541,8 +541,7 @@
return true;
}
-inline bool constantTimeStringCompare(const std::string_view a,
- const std::string_view b)
+inline bool constantTimeStringCompare(std::string_view a, std::string_view b)
{
// Important note, this function is ONLY constant time if the two input
// sizes are the same
@@ -555,7 +554,7 @@
struct ConstantTimeCompare
{
- bool operator()(const std::string_view a, const std::string_view b) const
+ bool operator()(std::string_view a, std::string_view b) const
{
return constantTimeStringCompare(a, b);
}
@@ -567,7 +566,7 @@
appendUrlPieces(boost::urls::url& url,
const std::initializer_list<std::string_view> args)
{
- for (const std::string_view& arg : args)
+ for (std::string_view arg : args)
{
url.segments().push_back(arg);
}
@@ -696,7 +695,7 @@
inline boost::urls::url replaceUrlSegment(const boost::urls::url_view& urlView,
const uint replaceLoc,
- const std::string_view newSegment)
+ std::string_view newSegment)
{
const boost::urls::segments_view& urlSegments = urlView.segments();
boost::urls::url url("/");
diff --git a/http/websocket.hpp b/http/websocket.hpp
index 0ab13f2..c36e579 100644
--- a/http/websocket.hpp
+++ b/http/websocket.hpp
@@ -148,7 +148,7 @@
});
}
- void sendBinary(const std::string_view msg) override
+ void sendBinary(std::string_view msg) override
{
ws.binary(true);
outBuffer.emplace_back(msg);
@@ -162,7 +162,7 @@
doWrite();
}
- void sendText(const std::string_view msg) override
+ void sendText(std::string_view msg) override
{
ws.text(true);
outBuffer.emplace_back(msg);
@@ -176,7 +176,7 @@
doWrite();
}
- void close(const std::string_view msg) override
+ void close(std::string_view msg) override
{
ws.async_close(
{boost::beast::websocket::close_code::normal, msg},