From 4a7fbefdff330f06d5698a1e60ce893225cd389e Mon Sep 17 00:00:00 2001 From: Ed Tanous Date: Sat, 6 Apr 2024 16:03:49 -0700 Subject: Fix large copies with url_view and segments_view Despite these objects being called "view" they are still relatively large, as clang-tidy correctly flags, and we ignore. Change all function uses to capture by: const boost::urls::url_view_base& Which is the base class of all boost URL types, and any class (url, url_view, etc) is convertible to that base. Change-Id: I8ee2ea3f4cfba38331303a7e4eb520a2b6f8ba92 Signed-off-by: Ed Tanous --- http/http_client.hpp | 13 +++++++------ http/logging.hpp | 21 ++++----------------- http/utility.hpp | 37 ++++++++++++++----------------------- 3 files changed, 25 insertions(+), 46 deletions(-) (limited to 'http') diff --git a/http/http_client.hpp b/http/http_client.hpp index 59804789ee..75304f69a1 100644 --- a/http/http_client.hpp +++ b/http/http_client.hpp @@ -41,7 +41,7 @@ #include #include #include -#include +#include #include #include @@ -637,7 +637,7 @@ class ConnectionInfo : public std::enable_shared_from_this explicit ConnectionInfo( boost::asio::io_context& iocIn, const std::string& idIn, const std::shared_ptr& connPolicyIn, - boost::urls::url_view hostIn, unsigned int connIdIn) : + const boost::urls::url_view_base& hostIn, unsigned int connIdIn) : subId(idIn), connPolicy(connPolicyIn), host(hostIn), connId(connIdIn), ioc(iocIn), resolver(iocIn), conn(iocIn), timer(iocIn) @@ -728,7 +728,7 @@ class ConnectionPool : public std::enable_shared_from_this } } - void sendData(std::string&& data, boost::urls::url_view destUri, + void sendData(std::string&& data, const boost::urls::url_view_base& destUri, const boost::beast::http::fields& httpHeader, const boost::beast::http::verb verb, const std::function& resHandler) @@ -836,7 +836,7 @@ class ConnectionPool : public std::enable_shared_from_this explicit ConnectionPool( boost::asio::io_context& iocIn, const std::string& idIn, const std::shared_ptr& connPolicyIn, - boost::urls::url_view destIPIn) : + const boost::urls::url_view_base& destIPIn) : ioc(iocIn), id(idIn), connPolicy(connPolicyIn), destIP(destIPIn) { @@ -879,7 +879,7 @@ class HttpClient // Send a request to destIP where additional processing of the // result is not required - void sendData(std::string&& data, boost::urls::url_view destUri, + void sendData(std::string&& data, const boost::urls::url_view_base& destUri, const boost::beast::http::fields& httpHeader, const boost::beast::http::verb verb) { @@ -889,7 +889,8 @@ class HttpClient // Send request to destIP and use the provided callback to // handle the response - void sendDataWithCallback(std::string&& data, boost::urls::url_view destUrl, + void sendDataWithCallback(std::string&& data, + const boost::urls::url_view_base& destUrl, const boost::beast::http::fields& httpHeader, const boost::beast::http::verb verb, const std::function& resHandler) diff --git a/http/logging.hpp b/http/logging.hpp index 2f88c90b14..de14d99e8f 100644 --- a/http/logging.hpp +++ b/http/logging.hpp @@ -5,7 +5,7 @@ #include #include #include -#include +#include #include #include @@ -46,27 +46,14 @@ struct std::formatter } }; -template <> -struct std::formatter -{ - constexpr auto parse(std::format_parse_context& ctx) - { - return ctx.begin(); - } - auto format(const boost::urls::url& msg, auto& ctx) const - { - return std::format_to(ctx.out(), "{}", std::string_view(msg.buffer())); - } -}; - -template <> -struct std::formatter +template URL> +struct std::formatter { constexpr auto parse(std::format_parse_context& ctx) { return ctx.begin(); } - auto format(const boost::urls::url& msg, auto& ctx) const + auto format(const URL& msg, auto& ctx) const { return std::format_to(ctx.out(), "{}", std::string_view(msg.buffer())); } diff --git a/http/utility.hpp b/http/utility.hpp index 7633c395af..5a2dc67d5b 100644 --- a/http/utility.hpp +++ b/http/utility.hpp @@ -8,6 +8,7 @@ #include #include #include +#include #include #include @@ -398,18 +399,18 @@ class UrlSegmentMatcherVisitor std::string_view segment; }; -inline bool readUrlSegments(boost::urls::url_view url, +inline bool readUrlSegments(const boost::urls::url_view_base& url, std::initializer_list segments) { - boost::urls::segments_view urlSegments = url.segments(); + const boost::urls::segments_view& urlSegments = url.segments(); if (!urlSegments.is_absolute()) { return false; } - boost::urls::segments_view::iterator it = urlSegments.begin(); - boost::urls::segments_view::iterator end = urlSegments.end(); + boost::urls::segments_view::const_iterator it = urlSegments.begin(); + boost::urls::segments_view::const_iterator end = urlSegments.end(); for (const auto& segment : segments) { @@ -442,16 +443,17 @@ inline bool readUrlSegments(boost::urls::url_view url, } // namespace details template -inline bool readUrlSegments(boost::urls::url_view url, Args&&... args) +inline bool readUrlSegments(const boost::urls::url_view_base& url, + Args&&... args) { return details::readUrlSegments(url, {std::forward(args)...}); } -inline boost::urls::url replaceUrlSegment(boost::urls::url_view urlView, - const uint replaceLoc, - std::string_view newSegment) +inline boost::urls::url + replaceUrlSegment(const boost::urls::url_view_base& urlView, + const uint replaceLoc, std::string_view newSegment) { - boost::urls::segments_view urlSegments = urlView.segments(); + const boost::urls::segments_view& urlSegments = urlView.segments(); boost::urls::url url("/"); if (!urlSegments.is_absolute()) @@ -533,22 +535,11 @@ inline void setPortDefaults(boost::urls::url& url) namespace nlohmann { -template <> -struct adl_serializer -{ - // nlohmann requires a specific casing to look these up in adl - // NOLINTNEXTLINE(readability-identifier-naming) - static void to_json(json& j, const boost::urls::url& url) - { - j = url.buffer(); - } -}; - -template <> -struct adl_serializer +template URL> +struct adl_serializer { // NOLINTNEXTLINE(readability-identifier-naming) - static void to_json(json& j, boost::urls::url_view url) + static void to_json(json& j, const URL& url) { j = url.buffer(); } -- cgit v1.2.3