Skip to content

Commit f347a5f

Browse files
committed
Compile-time Reduction Techniques
This commit hilights the effect of hiding the MPL details into the base class instead of a typedef. Instead of just a typedef, use Boost.MPL metafunctions as base classes. i.e. instead of: typedef typename mpl::inherit_linearly<...>::type tag_name; Do this instead: struct tag_name : mpl::inherit_linearly<...>::type {}; This then makes the tag back into an opaque type that the compiler doesn't have to keep instantiating over and over again in the cases where the tag is used. Also because all the metafunctions deal with opaque tags and whether they inherit from specific root/base tags, then the compile times are greatly reduced. You can call this type erasure at compile-time using OOP facilities.
1 parent 3efd6c0 commit f347a5f

File tree

9 files changed

+16
-31
lines changed

9 files changed

+16
-31
lines changed

boost/network/protocol/http/client.hpp

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -26,9 +26,6 @@
2626
#include <boost/network/protocol/http/client/facade.hpp>
2727
#include <boost/network/protocol/http/client/pimpl.hpp>
2828

29-
#include <boost/network/support/sync_only.hpp>
30-
31-
3229
namespace boost { namespace network { namespace http {
3330

3431
template <class Tag, unsigned version_major, unsigned version_minor>
@@ -39,7 +36,7 @@ namespace boost { namespace network { namespace http {
3936
typedef basic_client_impl<Tag,version_major,version_minor> pimpl_type;
4037
typedef basic_client_facade<Tag, basic_client<Tag,version_major,version_minor> > base_facade_type;
4138
public:
42-
typedef basic_request<typename sync_only<Tag>::type> request;
39+
typedef basic_request<Tag> request;
4340
typedef basic_response<Tag> response;
4441
typedef typename string<Tag>::type string_type;
4542
typedef Tag tag_type;

boost/network/protocol/http/client/async_impl.hpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@
1010
#include <boost/asio/strand.hpp>
1111
#include <boost/thread/thread.hpp>
1212
#include <boost/bind.hpp>
13-
#include <boost/network/support/sync_only.hpp>
1413

1514
namespace boost { namespace network { namespace http {
1615

@@ -56,7 +55,7 @@ namespace boost { namespace network { namespace http {
5655
}
5756

5857
basic_response<Tag> const request_skeleton(
59-
basic_request<typename sync_only<Tag>::type> const & request_,
58+
basic_request<Tag> const & request_,
6059
string_type const & method,
6160
bool get_body
6261
)

boost/network/protocol/http/client/facade.hpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@
88

99
#include <boost/network/protocol/http/request.hpp>
1010
#include <boost/network/protocol/http/response.hpp>
11-
#include <boost/network/protocol/http/support/sync_only.hpp>
1211

1312
namespace boost { namespace network { namespace http {
1413

@@ -22,7 +21,7 @@ namespace boost { namespace network { namespace http {
2221
struct basic_client_facade {
2322

2423
typedef typename string<Tag>::type string_type;
25-
typedef basic_request<typename sync_only<Tag>::type> request;
24+
typedef basic_request<Tag> request;
2625
typedef basic_response<Tag> response;
2726

2827
basic_client_facade()

boost/network/protocol/http/client/pimpl.hpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@
1515

1616
#include <boost/network/protocol/http/traits/connection_policy.hpp>
1717
#include <boost/network/protocol/http/client/async_impl.hpp>
18-
#include <boost/network/support/sync_only.hpp>
1918

2019
namespace boost { namespace network { namespace http {
2120

@@ -47,7 +46,7 @@ namespace boost { namespace network { namespace http {
4746

4847
~sync_client() {}
4948

50-
basic_response<Tag> const request_skeleton(basic_request<typename sync_only<Tag>::type> const & request_, string_type method, bool get_body) {
49+
basic_response<Tag> const request_skeleton(basic_request<Tag> const & request_, string_type method, bool get_body) {
5150
typename connection_base::connection_ptr connection_;
5251
connection_ = connection_base::get_connection(resolver_, request_);
5352
return connection_->send_request(method, request_, get_body);

boost/network/protocol/http/detail/connection_helper.hpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@
1111
#include <boost/network/protocol/http/traits/connection_keepalive.hpp>
1212
#include <boost/asio/streambuf.hpp>
1313
#include <boost/network/traits/string.hpp>
14-
#include <boost/network/support/sync_only.hpp>
1514

1615
namespace boost { namespace network { namespace http { namespace detail {
1716

@@ -21,7 +20,7 @@ namespace boost { namespace network { namespace http { namespace detail {
2120

2221
typedef typename string<Tag>::type string_type;
2322

24-
void create_request(boost::asio::streambuf & request_buffer, string_type const & method, basic_request<typename sync_only<Tag>::type> const & request_) const {
23+
void create_request(boost::asio::streambuf & request_buffer, string_type const & method, basic_request<Tag> const & request_) const {
2524
// TODO make this use Boost.Karma instead of an ad-hoc implementation
2625
std::ostream request_stream(&request_buffer);
2726

boost/network/protocol/http/impl/async_connection_base.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ namespace boost { namespace network { namespace http { namespace impl {
2121
typedef typename resolver_base::resolver_type resolver_type;
2222
typedef typename resolver_base::resolve_function resolve_function;
2323
typedef typename string<Tag>::type string_type;
24-
typedef basic_request<typename sync_only<Tag>::type> request;
24+
typedef basic_request<Tag> request;
2525
typedef basic_response<Tag> response;
2626

2727
static boost::shared_ptr<async_connection_base<Tag,version_major,version_minor> > new_connection(resolve_function resolve, boost::shared_ptr<resolver_type> resolver, bool follow_redirect, bool https) {

boost/network/protocol/http/impl/request.hpp

Lines changed: 5 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020

2121
#include <boost/network/protocol/http/message/async_message.hpp>
2222
#include <boost/network/support/is_async.hpp>
23+
#include <boost/network/protocol/http/support/sync_only.hpp>
2324

2425
#include <boost/cstdint.hpp>
2526

@@ -33,24 +34,15 @@ namespace boost { namespace network { namespace http {
3334
*/
3435

3536
template <class Tag>
36-
struct request_base
37-
: mpl::if_<
38-
is_async<Tag>,
39-
async_message<Tag>,
40-
basic_message<Tag>
41-
>
42-
{};
43-
44-
template <class Tag>
45-
struct basic_request : public request_base<Tag>::type
37+
struct basic_request : public basic_message<Tag>
4638
{
4739

4840
mutable boost::network::uri::http::uri uri_;
49-
typedef typename request_base<Tag>::type base_type;
41+
typedef basic_message<Tag> base_type;
5042

5143
public:
52-
typedef Tag tag;
53-
typedef typename string<Tag>::type string_type;
44+
typedef typename sync_only<Tag>::type tag;
45+
typedef typename string<tag>::type string_type;
5446
typedef boost::uint16_t port_type;
5547

5648
explicit basic_request(string_type const & uri_)

boost/network/protocol/http/policies/async_connection.hpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ namespace boost { namespace network { namespace http {
4141
pimpl = impl::async_connection_base<Tag,version_major,version_minor>::new_connection(resolve, resolver, follow_redirect, https);
4242
}
4343

44-
basic_response<Tag> send_request(string_type const & method, basic_request<typename sync_only<Tag>::type> const & request_, bool get_body) {
44+
basic_response<Tag> send_request(string_type const & method, basic_request<Tag> const & request_, bool get_body) {
4545
return pimpl->start(request_, method, get_body);
4646
}
4747

@@ -52,7 +52,7 @@ namespace boost { namespace network { namespace http {
5252
};
5353

5454
typedef boost::shared_ptr<connection_impl> connection_ptr;
55-
connection_ptr get_connection(boost::shared_ptr<resolver_type> resolver, basic_request<typename sync_only<Tag>::type> const & request_) {
55+
connection_ptr get_connection(boost::shared_ptr<resolver_type> resolver, basic_request<Tag> const & request_) {
5656
string_type protocol_ = protocol(request_);
5757
connection_ptr connection_(
5858
new connection_impl(

boost/network/tags.hpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -30,11 +30,11 @@ namespace boost { namespace network { namespace tags {
3030
// Tag Definition Macro Helper
3131
#ifndef BOOST_NETWORK_DEFINE_TAG
3232
#define BOOST_NETWORK_DEFINE_TAG(name) \
33-
typedef mpl::inherit_linearly< \
33+
struct name : mpl::inherit_linearly< \
3434
name##_tags, \
3535
mpl::inherit<mpl::placeholders::_1, mpl::placeholders::_2> \
36-
>::type name; \
37-
template <> struct components<name> { \
36+
>::type {}; \
37+
template <> struct components<name> { \
3838
typedef name##_tags type; \
3939
};
4040
#endif // BOOST_NETWORK_DEFINE_TAG

0 commit comments

Comments
 (0)