diff options
author | Ed Tanous <ed@tanous.net> | 2024-04-07 02:03:49 +0300 |
---|---|---|
committer | Ed Tanous <ed@tanous.net> | 2024-04-11 19:38:16 +0300 |
commit | 4a7fbefdff330f06d5698a1e60ce893225cd389e (patch) | |
tree | 036f2c7795de1d48d06834d6b0ccbe1d0d5c9e79 /http/utility.hpp | |
parent | d9e89dfd49538c54d280dce3750f4af264cfd5fc (diff) | |
download | bmcweb-4a7fbefdff330f06d5698a1e60ce893225cd389e.tar.xz |
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 <ed@tanous.net>
Diffstat (limited to 'http/utility.hpp')
-rw-r--r-- | http/utility.hpp | 37 |
1 files changed, 14 insertions, 23 deletions
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 <boost/url/parse.hpp> #include <boost/url/url.hpp> #include <boost/url/url_view.hpp> +#include <boost/url/url_view_base.hpp> #include <nlohmann/json.hpp> #include <array> @@ -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<UrlSegment> 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 <typename... Args> -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>(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<boost::urls::url> -{ - // 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<boost::urls::url_view> +template <std::derived_from<boost::urls::url_view_base> URL> +struct adl_serializer<URL> { // 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(); } |