From cb22512a903b05bc3f619a0771af432e009ba014 Mon Sep 17 00:00:00 2001 From: Christopher Kohlhoff Date: Fri, 23 Sep 2016 08:16:51 +1000 Subject: [PATCH] Use string_view in basic_resolver and basic_resolver_entry. --- asio/include/asio/ip/basic_resolver.hpp | 71 +++++++++++-------- asio/include/asio/ip/basic_resolver_entry.hpp | 7 +- 2 files changed, 47 insertions(+), 31 deletions(-) diff --git a/asio/include/asio/ip/basic_resolver.hpp b/asio/include/asio/ip/basic_resolver.hpp index d4dac0b6..3aa61fb8 100644 --- a/asio/include/asio/ip/basic_resolver.hpp +++ b/asio/include/asio/ip/basic_resolver.hpp @@ -20,6 +20,7 @@ #include "asio/async_result.hpp" #include "asio/basic_io_object.hpp" #include "asio/detail/handler_type_requirements.hpp" +#include "asio/detail/string_view.hpp" #include "asio/detail/throw_error.hpp" #include "asio/error.hpp" #include "asio/io_context.hpp" @@ -269,7 +270,8 @@ public: * c:\\windows\\system32\\drivers\\etc\\services. Operating systems * may use additional locations when resolving service names. */ - results_type resolve(const std::string& host, const std::string& service) + results_type resolve(ASIO_STRING_VIEW_PARAM host, + ASIO_STRING_VIEW_PARAM service) { return resolve(host, service, resolver_base::flags()); } @@ -307,8 +309,8 @@ public: * c:\\windows\\system32\\drivers\\etc\\services. Operating systems * may use additional locations when resolving service names. */ - results_type resolve(const std::string& host, const std::string& service, - asio::error_code& ec) + results_type resolve(ASIO_STRING_VIEW_PARAM host, + ASIO_STRING_VIEW_PARAM service, asio::error_code& ec) { return resolve(host, service, resolver_base::flags(), ec); } @@ -350,11 +352,12 @@ public: * c:\\windows\\system32\\drivers\\etc\\services. Operating systems * may use additional locations when resolving service names. */ - results_type resolve(const std::string& host, const std::string& service, - resolver_base::flags resolve_flags) + results_type resolve(ASIO_STRING_VIEW_PARAM host, + ASIO_STRING_VIEW_PARAM service, resolver_base::flags resolve_flags) { asio::error_code ec; - basic_resolver_query q(host, service, resolve_flags); + basic_resolver_query q(static_cast(host), + static_cast(service), resolve_flags); results_type r = this->get_service().resolve( this->get_implementation(), q, ec); asio::detail::throw_error(ec, "resolve"); @@ -398,10 +401,12 @@ public: * c:\\windows\\system32\\drivers\\etc\\services. Operating systems * may use additional locations when resolving service names. */ - results_type resolve(const std::string& host, const std::string& service, - resolver_base::flags resolve_flags, asio::error_code& ec) + results_type resolve(ASIO_STRING_VIEW_PARAM host, + ASIO_STRING_VIEW_PARAM service, resolver_base::flags resolve_flags, + asio::error_code& ec) { - basic_resolver_query q(host, service, resolve_flags); + basic_resolver_query q(static_cast(host), + static_cast(service), resolve_flags); return this->get_service().resolve(this->get_implementation(), q, ec); } @@ -441,8 +446,8 @@ public: * c:\\windows\\system32\\drivers\\etc\\services. Operating systems * may use additional locations when resolving service names. */ - results_type resolve(const protocol_type& protocol, const std::string& host, - const std::string& service) + results_type resolve(const protocol_type& protocol, + ASIO_STRING_VIEW_PARAM host, ASIO_STRING_VIEW_PARAM service) { return resolve(protocol, host, service, resolver_base::flags()); } @@ -483,8 +488,9 @@ public: * c:\\windows\\system32\\drivers\\etc\\services. Operating systems * may use additional locations when resolving service names. */ - results_type resolve(const protocol_type& protocol, const std::string& host, - const std::string& service, asio::error_code& ec) + results_type resolve(const protocol_type& protocol, + ASIO_STRING_VIEW_PARAM host, ASIO_STRING_VIEW_PARAM service, + asio::error_code& ec) { return resolve(protocol, host, service, resolver_base::flags(), ec); } @@ -529,12 +535,14 @@ public: * c:\\windows\\system32\\drivers\\etc\\services. Operating systems * may use additional locations when resolving service names. */ - results_type resolve(const protocol_type& protocol, const std::string& host, - const std::string& service, resolver_base::flags resolve_flags) + results_type resolve(const protocol_type& protocol, + ASIO_STRING_VIEW_PARAM host, ASIO_STRING_VIEW_PARAM service, + resolver_base::flags resolve_flags) { asio::error_code ec; basic_resolver_query q( - protocol, host, service, resolve_flags); + protocol, static_cast(host), + static_cast(service), resolve_flags); results_type r = this->get_service().resolve( this->get_implementation(), q, ec); asio::detail::throw_error(ec, "resolve"); @@ -581,12 +589,13 @@ public: * c:\\windows\\system32\\drivers\\etc\\services. Operating systems * may use additional locations when resolving service names. */ - results_type resolve(const protocol_type& protocol, const std::string& host, - const std::string& service, resolver_base::flags resolve_flags, - asio::error_code& ec) + results_type resolve(const protocol_type& protocol, + ASIO_STRING_VIEW_PARAM host, ASIO_STRING_VIEW_PARAM service, + resolver_base::flags resolve_flags, asio::error_code& ec) { basic_resolver_query q( - protocol, host, service, resolve_flags); + protocol, static_cast(host), + static_cast(service), resolve_flags); return this->get_service().resolve(this->get_implementation(), q, ec); } @@ -685,7 +694,8 @@ public: template ASIO_INITFN_RESULT_TYPE(ResolveHandler, void (asio::error_code, results_type)) - async_resolve(const std::string& host, const std::string& service, + async_resolve(ASIO_STRING_VIEW_PARAM host, + ASIO_STRING_VIEW_PARAM service, ASIO_MOVE_ARG(ResolveHandler) handler) { return async_resolve(host, service, resolver_base::flags(), @@ -741,7 +751,8 @@ public: template ASIO_INITFN_RESULT_TYPE(ResolveHandler, void (asio::error_code, results_type)) - async_resolve(const std::string& host, const std::string& service, + async_resolve(ASIO_STRING_VIEW_PARAM host, + ASIO_STRING_VIEW_PARAM service, resolver_base::flags resolve_flags, ASIO_MOVE_ARG(ResolveHandler) handler) { @@ -750,7 +761,8 @@ public: ASIO_RESOLVE_HANDLER_CHECK( ResolveHandler, handler, results_type) type_check; - basic_resolver_query q(host, service, resolve_flags); + basic_resolver_query q(static_cast(host), + static_cast(service), resolve_flags); #if defined(ASIO_ENABLE_OLD_SERVICES) return this->get_service().async_resolve(this->get_implementation(), q, @@ -814,8 +826,9 @@ public: template ASIO_INITFN_RESULT_TYPE(ResolveHandler, void (asio::error_code, results_type)) - async_resolve(const protocol_type& protocol, const std::string& host, - const std::string& service, ASIO_MOVE_ARG(ResolveHandler) handler) + async_resolve(const protocol_type& protocol, + ASIO_STRING_VIEW_PARAM host, ASIO_STRING_VIEW_PARAM service, + ASIO_MOVE_ARG(ResolveHandler) handler) { return async_resolve(protocol, host, service, resolver_base::flags(), ASIO_MOVE_CAST(ResolveHandler)(handler)); @@ -873,8 +886,9 @@ public: template ASIO_INITFN_RESULT_TYPE(ResolveHandler, void (asio::error_code, results_type)) - async_resolve(const protocol_type& protocol, const std::string& host, - const std::string& service, resolver_base::flags resolve_flags, + async_resolve(const protocol_type& protocol, + ASIO_STRING_VIEW_PARAM host, ASIO_STRING_VIEW_PARAM service, + resolver_base::flags resolve_flags, ASIO_MOVE_ARG(ResolveHandler) handler) { // If you get an error on the following line it means that your handler does @@ -883,7 +897,8 @@ public: ResolveHandler, handler, results_type) type_check; basic_resolver_query q( - protocol, host, service, resolve_flags); + protocol, static_cast(host), + static_cast(service), resolve_flags); #if defined(ASIO_ENABLE_OLD_SERVICES) return this->get_service().async_resolve(this->get_implementation(), q, diff --git a/asio/include/asio/ip/basic_resolver_entry.hpp b/asio/include/asio/ip/basic_resolver_entry.hpp index 524ce16f..ce689aa7 100644 --- a/asio/include/asio/ip/basic_resolver_entry.hpp +++ b/asio/include/asio/ip/basic_resolver_entry.hpp @@ -17,6 +17,7 @@ #include "asio/detail/config.hpp" #include +#include "asio/detail/string_view.hpp" #include "asio/detail/push_options.hpp" @@ -49,10 +50,10 @@ public: /// Construct with specified endpoint, host name and service name. basic_resolver_entry(const endpoint_type& ep, - const std::string& host, const std::string& service) + ASIO_STRING_VIEW_PARAM host, ASIO_STRING_VIEW_PARAM service) : endpoint_(ep), - host_name_(host), - service_name_(service) + host_name_(static_cast(host)), + service_name_(static_cast(service)) { }