Skip to content

Commit 13e16b7

Browse files
committed
Removes memory_resource.
1 parent e11502e commit 13e16b7

File tree

6 files changed

+69
-61
lines changed

6 files changed

+69
-61
lines changed

examples/cpp20_serialization.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ auto tag_invoke(value_to_tag<user>, value const& jv)
7676
}
7777

7878
// Serialization
79-
void to_bulk(std::pmr::string& to, user const& u)
79+
void to_bulk(std::string& to, user const& u)
8080
{
8181
redis::resp3::to_bulk(to, serialize(value_from(u)));
8282
}

include/boost/redis/connection.hpp

Lines changed: 23 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -21,20 +21,19 @@ namespace boost::redis {
2121
* For more details, please see the documentation of each individual
2222
* function.
2323
*
24-
* @tparam AsyncReadWriteStream A stream that supports reading and
25-
* writing.
24+
* @tparam Socket The socket type e.g. asio::ip::tcp::socket.
2625
*/
27-
template <class AsyncReadWriteStream>
26+
template <class Socket>
2827
class basic_connection :
2928
private detail::connection_base<
30-
typename AsyncReadWriteStream::executor_type,
31-
basic_connection<AsyncReadWriteStream>> {
29+
typename Socket::executor_type,
30+
basic_connection<Socket>> {
3231
public:
3332
/// Executor type.
34-
using executor_type = typename AsyncReadWriteStream::executor_type;
33+
using executor_type = typename Socket::executor_type;
3534

3635
/// Type of the next layer
37-
using next_layer_type = AsyncReadWriteStream;
36+
using next_layer_type = Socket;
3837

3938
/// Rebinds the socket type to another executor.
4039
template <class Executor1>
@@ -44,23 +43,19 @@ class basic_connection :
4443
using other = basic_connection<typename next_layer_type::template rebind_executor<Executor1>::other>;
4544
};
4645

47-
using base_type = detail::connection_base<executor_type, basic_connection<AsyncReadWriteStream>>;
46+
using base_type = detail::connection_base<executor_type, basic_connection<Socket>>;
4847

4948
/// Contructs from an executor.
5049
explicit
51-
basic_connection(
52-
executor_type ex,
53-
std::pmr::memory_resource* resource = std::pmr::get_default_resource())
54-
: base_type{ex, resource}
50+
basic_connection(executor_type ex)
51+
: base_type{ex}
5552
, stream_{ex}
5653
{}
5754

5855
/// Contructs from a context.
5956
explicit
60-
basic_connection(
61-
asio::io_context& ioc,
62-
std::pmr::memory_resource* resource = std::pmr::get_default_resource())
63-
: basic_connection(ioc.get_executor(), resource)
57+
basic_connection(asio::io_context& ioc)
58+
: basic_connection(ioc.get_executor())
6459
{ }
6560

6661
/// Returns the associated executor.
@@ -190,6 +185,17 @@ class basic_connection :
190185
void set_max_buffer_read_size(std::size_t max_read_size) noexcept
191186
{ base_type::set_max_buffer_read_size(max_read_size); }
192187

188+
/** @brief Reserve memory on the read and write internal buffers.
189+
*
190+
* This function will call `std::string::reserve` on the
191+
* underlying buffers.
192+
*
193+
* @param read The new capacity of the read buffer.
194+
* @param write The new capacity of the write buffer.
195+
*/
196+
void reserve(std::size_t read, std::size_t write)
197+
{ base_type::reserve(read, write); }
198+
193199
private:
194200
using this_type = basic_connection<next_layer_type>;
195201

@@ -206,7 +212,7 @@ class basic_connection :
206212
auto is_open() const noexcept { return stream_.is_open(); }
207213
auto lowest_layer() noexcept -> auto& { return stream_.lowest_layer(); }
208214

209-
AsyncReadWriteStream stream_;
215+
Socket stream_;
210216
};
211217

212218
/** \brief A connection that uses a asio::ip::tcp::socket.

include/boost/redis/detail/connection_base.hpp

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,6 @@
2424
#include <chrono>
2525
#include <memory>
2626
#include <type_traits>
27-
#include <memory_resource>
2827

2928
namespace boost::redis::detail {
3029

@@ -43,13 +42,10 @@ class connection_base {
4342
using executor_type = Executor;
4443
using this_type = connection_base<Executor, Derived>;
4544

46-
connection_base(executor_type ex, std::pmr::memory_resource* resource)
45+
connection_base(executor_type ex)
4746
: writer_timer_{ex}
4847
, read_timer_{ex}
4948
, channel_{ex}
50-
, read_buffer_{resource}
51-
, write_buffer_{resource}
52-
, reqs_{resource}
5349
{
5450
writer_timer_.expires_at(std::chrono::steady_clock::time_point::max());
5551
read_timer_.expires_at(std::chrono::steady_clock::time_point::max());
@@ -166,6 +162,13 @@ class connection_base {
166162
void set_max_buffer_read_size(std::size_t max_read_size) noexcept
167163
{max_read_size_ = max_read_size;}
168164

165+
// Reserves memory in the read and write buffer.
166+
void reserve(std::size_t read, std::size_t write)
167+
{
168+
read_buffer_.reserve(read);
169+
write_buffer_.reserve(write);
170+
}
171+
169172
private:
170173
using clock_type = std::chrono::steady_clock;
171174
using clock_traits_type = asio::wait_traits<clock_type>;
@@ -269,7 +272,7 @@ class connection_base {
269272
reqs_.erase(std::remove(std::begin(reqs_), std::end(reqs_), info));
270273
}
271274

272-
using reqs_type = std::pmr::deque<std::shared_ptr<req_info>>;
275+
using reqs_type = std::deque<std::shared_ptr<req_info>>;
273276

274277
template <class> friend struct detail::reader_op;
275278
template <class> friend struct detail::writer_op;
@@ -383,8 +386,8 @@ class connection_base {
383386
timer_type read_timer_;
384387
channel_type channel_;
385388

386-
std::pmr::string read_buffer_;
387-
std::pmr::string write_buffer_;
389+
std::string read_buffer_;
390+
std::string write_buffer_;
388391
reqs_type reqs_;
389392
std::size_t max_read_size_ = (std::numeric_limits<std::size_t>::max)();
390393
};

include/boost/redis/resp3/request.hpp

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@
1111

1212
#include <string>
1313
#include <tuple>
14-
#include <memory_resource>
1514

1615
// NOTE: Consider detecting tuples in the type in the parameter pack
1716
// to calculate the header size correctly.
@@ -164,7 +163,7 @@ void add_separator(Request& to)
164163
*
165164
* \li Non-string types will be converted to string by using \c
166165
* to_bulk, which must be made available over ADL.
167-
* \li Uses a std::pmr::string for internal storage.
166+
* \li Uses a std::string for internal storage.
168167
*/
169168
class request {
170169
public:
@@ -211,9 +210,8 @@ class request {
211210
* \param resource Memory resource.
212211
*/
213212
explicit
214-
request(config cfg = config{true, true, false, true, true},
215-
std::pmr::memory_resource* resource = std::pmr::get_default_resource())
216-
: cfg_{cfg}, payload_(resource) {}
213+
request(config cfg = config{true, true, false, true, true})
214+
: cfg_{cfg} {}
217215

218216
//// Returns the number of commands contained in this request.
219217
[[nodiscard]] auto size() const noexcept -> std::size_t
@@ -232,7 +230,7 @@ class request {
232230
commands_ = 0;
233231
}
234232

235-
/// Calls std::pmr::string::reserve on the internal storage.
233+
/// Calls std::string::reserve on the internal storage.
236234
void reserve(std::size_t new_cap = 0)
237235
{ payload_.reserve(new_cap); }
238236

@@ -395,7 +393,7 @@ class request {
395393
}
396394

397395
config cfg_;
398-
std::pmr::string payload_;
396+
std::string payload_;
399397
std::size_t commands_ = 0;
400398
bool has_hello_priority_ = false;
401399
};

include/boost/redis/ssl/connection.hpp

Lines changed: 23 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -25,18 +25,17 @@ class basic_connection;
2525
* commands can be sent at any time. For more details, please see the
2626
* documentation of each individual function.
2727
*
28-
* @tparam AsyncReadWriteStream A stream that supports reading and
29-
* writing.
28+
* @tparam Socket The socket type e.g. asio::ip::tcp::socket.
3029
*
3130
*/
32-
template <class AsyncReadWriteStream>
33-
class basic_connection<asio::ssl::stream<AsyncReadWriteStream>> :
31+
template <class Socket>
32+
class basic_connection<asio::ssl::stream<Socket>> :
3433
private redis::detail::connection_base<
35-
typename asio::ssl::stream<AsyncReadWriteStream>::executor_type,
36-
basic_connection<asio::ssl::stream<AsyncReadWriteStream>>> {
34+
typename asio::ssl::stream<Socket>::executor_type,
35+
basic_connection<asio::ssl::stream<Socket>>> {
3736
public:
3837
/// Type of the next layer
39-
using next_layer_type = asio::ssl::stream<AsyncReadWriteStream>;
38+
using next_layer_type = asio::ssl::stream<Socket>;
4039

4140
/// Executor type.
4241
using executor_type = typename next_layer_type::executor_type;
@@ -46,28 +45,22 @@ class basic_connection<asio::ssl::stream<AsyncReadWriteStream>> :
4645
struct rebind_executor
4746
{
4847
/// The socket type when rebound to the specified executor.
49-
using other = basic_connection<asio::ssl::stream<typename AsyncReadWriteStream::template rebind_executor<Executor1>::other>>;
48+
using other = basic_connection<asio::ssl::stream<typename Socket::template rebind_executor<Executor1>::other>>;
5049
};
5150

52-
using base_type = redis::detail::connection_base<executor_type, basic_connection<asio::ssl::stream<AsyncReadWriteStream>>>;
51+
using base_type = redis::detail::connection_base<executor_type, basic_connection<asio::ssl::stream<Socket>>>;
5352

5453
/// Constructor
5554
explicit
56-
basic_connection(
57-
executor_type ex,
58-
asio::ssl::context& ctx,
59-
std::pmr::memory_resource* resource = std::pmr::get_default_resource())
60-
: base_type{ex, resource}
55+
basic_connection(executor_type ex, asio::ssl::context& ctx)
56+
: base_type{ex}
6157
, stream_{ex, ctx}
6258
{ }
6359

6460
/// Constructor
6561
explicit
66-
basic_connection(
67-
asio::io_context& ioc,
68-
asio::ssl::context& ctx,
69-
std::pmr::memory_resource* resource = std::pmr::get_default_resource())
70-
: basic_connection(ioc.get_executor(), ctx, resource)
62+
basic_connection(asio::io_context& ioc, asio::ssl::context& ctx)
63+
: basic_connection(ioc.get_executor(), ctx)
7164
{ }
7265

7366
/// Returns the associated executor.
@@ -137,6 +130,17 @@ class basic_connection<asio::ssl::stream<AsyncReadWriteStream>> :
137130
void set_max_buffer_read_size(std::size_t max_read_size) noexcept
138131
{ base_type::set_max_buffer_read_size(max_read_size); }
139132

133+
/** @brief Reserve memory on the read and write internal buffers.
134+
*
135+
* This function will call `std::string::reserve` on the
136+
* underlying buffers.
137+
*
138+
* @param read The new capacity of the read buffer.
139+
* @param write The new capacity of the write buffer.
140+
*/
141+
void reserve(std::size_t read, std::size_t write)
142+
{ base_type::reserve(read, write); }
143+
140144
private:
141145
using this_type = basic_connection<next_layer_type>;
142146

tests/request.cpp

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55
*/
66

77
#include <iostream>
8-
#include <memory_resource>
98

109
#define BOOST_TEST_MODULE low level
1110
#include <boost/test/included/unit_test.hpp>
@@ -19,26 +18,24 @@ using boost::redis::resp3::request;
1918

2019
BOOST_AUTO_TEST_CASE(single_arg_allocator)
2120
{
22-
char buf[4096];
23-
std::pmr::monotonic_buffer_resource resource{buf, 4096};
24-
request req1{{}, &resource};
21+
request req1;
2522
req1.push("PING");
26-
BOOST_CHECK_EQUAL(req1.payload(), std::pmr::string{"*1\r\n$4\r\nPING\r\n"});
23+
BOOST_CHECK_EQUAL(req1.payload(), std::string{"*1\r\n$4\r\nPING\r\n"});
2724
}
2825

2926
BOOST_AUTO_TEST_CASE(arg_int)
3027
{
3128
request req;
3229
req.push("PING", 42);
33-
BOOST_CHECK_EQUAL(req.payload(), std::pmr::string{"*2\r\n$4\r\nPING\r\n$2\r\n42\r\n"});
30+
BOOST_CHECK_EQUAL(req.payload(), std::string{"*2\r\n$4\r\nPING\r\n$2\r\n42\r\n"});
3431
}
3532

3633
BOOST_AUTO_TEST_CASE(multiple_args)
3734
{
3835
char const* res = "*5\r\n$3\r\nSET\r\n$3\r\nkey\r\n$5\r\nvalue\r\n$2\r\nEX\r\n$1\r\n2\r\n";
3936
request req;
4037
req.push("SET", "key", "value", "EX", "2");
41-
BOOST_CHECK_EQUAL(req.payload(), std::pmr::string{res});
38+
BOOST_CHECK_EQUAL(req.payload(), std::string{res});
4239
}
4340

4441
BOOST_AUTO_TEST_CASE(container_and_range)
@@ -49,9 +46,9 @@ BOOST_AUTO_TEST_CASE(container_and_range)
4946

5047
request req1;
5148
req1.push_range("HSET", "key", in);
52-
BOOST_CHECK_EQUAL(req1.payload(), std::pmr::string{res});
49+
BOOST_CHECK_EQUAL(req1.payload(), std::string{res});
5350

5451
request req2;
5552
req2.push_range("HSET", "key", std::cbegin(in), std::cend(in));
56-
BOOST_CHECK_EQUAL(req2.payload(), std::pmr::string{res});
53+
BOOST_CHECK_EQUAL(req2.payload(), std::string{res});
5754
}

0 commit comments

Comments
 (0)