Skip to content

Commit 4753e9b

Browse files
committed
Remove polymorphic allocator
1 parent 8098017 commit 4753e9b

File tree

2 files changed

+32
-50
lines changed

2 files changed

+32
-50
lines changed

include/jsoncons/basic_json.hpp

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -826,7 +826,7 @@ namespace jsoncons {
826826
array_storage(const array& val, semantic_tag tag, const Allocator& a)
827827
: storage_kind_(val.storage_kind_), length_(0), tag_(tag)
828828
{
829-
create(array_allocator(a), val);
829+
create(array_allocator(a), val, a);
830830
}
831831

832832
array_storage(const array_storage& val)
@@ -845,7 +845,7 @@ namespace jsoncons {
845845
array_storage(const array_storage& val, const Allocator& a)
846846
: storage_kind_(val.storage_kind_), length_(0), tag_(val.tag_)
847847
{
848-
create(array_allocator(a), *(val.ptr_));
848+
create(array_allocator(a), *(val.ptr_), a);
849849
}
850850
~array_storage() noexcept
851851
{
@@ -919,7 +919,7 @@ namespace jsoncons {
919919
explicit object_storage(const object& val, semantic_tag tag, const Allocator& a)
920920
: storage_kind_(val.storage_kind_), length_(0), tag_(tag)
921921
{
922-
create(object_allocator(a), val);
922+
create(object_allocator(a), val, a);
923923
}
924924

925925
explicit object_storage(const object_storage& val)
@@ -938,7 +938,7 @@ namespace jsoncons {
938938
explicit object_storage(const object_storage& val, const Allocator& a)
939939
: storage_kind_(val.storage_kind_), length_(0), tag_(val.tag_)
940940
{
941-
create(object_allocator(a), *(val.ptr_));
941+
create(object_allocator(a), *(val.ptr_), a);
942942
}
943943

944944
~object_storage() noexcept
@@ -2946,12 +2946,16 @@ namespace jsoncons {
29462946
construct<empty_object_storage>(tag);
29472947
}
29482948

2949-
// Undeprecated
2950-
explicit basic_json(const Allocator&)
2949+
#if !defined(JSONCONS_NO_DEPRECATED)
2950+
2951+
JSONCONS_DEPRECATED_MSG("Instead, use basic_json(json_object_t,semantic_tag,const Allocator&)")
2952+
explicit basic_json(const Allocator& alloc, semantic_tag tag = semantic_tag::none)
29512953
{
2952-
construct<empty_object_storage>(semantic_tag::none);
2954+
construct<object_storage>(object(alloc), tag);
29532955
}
29542956

2957+
#endif
2958+
29552959
basic_json(const basic_json& other)
29562960
{
29572961
Init_(other);

include/jsoncons/json_object.hpp

Lines changed: 21 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -61,8 +61,8 @@ namespace jsoncons {
6161
public:
6262
using key_type = KeyT;
6363
using value_type = ValueT;
64-
using string_view_type = typename value_type::string_view_type;
6564
using allocator_type = typename ValueT::allocator_type;
65+
using string_view_type = typename value_type::string_view_type;
6666
private:
6767

6868
key_type key_;
@@ -95,38 +95,15 @@ namespace jsoncons {
9595
{
9696
}
9797

98-
template <typename... Args>
99-
key_value(const key_type& name, Args&& ... args, const allocator_type& alloc)
100-
: key_(name, alloc), value_(std::forward<Args>(args)..., alloc)
101-
{
102-
}
103-
104-
template <typename... Args>
105-
key_value(key_type&& name, Args&& ... args, const allocator_type& alloc) noexcept
106-
: key_(std::move(name),alloc), value_(std::forward<Args>(args)...,alloc)
107-
{
108-
}
109-
11098
key_value(const key_value& member)
11199
: key_(member.key_), value_(member.value_)
112100
{
113101
}
114102

115-
key_value(const key_value& member, const allocator_type& alloc)
116-
: key_(member.key_, alloc), value_(member.value_, alloc)
117-
{
118-
}
119-
120103
key_value(key_value&& member) noexcept
121104
: key_(std::move(member.key_)), value_(std::move(member.value_))
122105
{
123106
}
124-
125-
key_value(key_value&& member, const allocator_type& alloc) noexcept
126-
: key_(std::move(member.key_), alloc), value_(std::move(member.value_), alloc)
127-
{
128-
}
129-
130107
template <typename... U1, typename... U2>
131108
JSONCONS_CONSTEXPR key_value(std::piecewise_construct_t /*unused*/, std::tuple<U1...> a,
132109
std::tuple<U2...>
@@ -339,23 +316,12 @@ namespace jsoncons {
339316
{
340317
}
341318

342-
sorted_json_object(const sorted_json_object& val, const allocator_type& alloc)
343-
: allocator_holder<allocator_type>(alloc),
344-
members_(val.members_,key_value_allocator_type(alloc))
345-
{
346-
}
347-
348319
sorted_json_object(sorted_json_object&& val)
349320
: allocator_holder<allocator_type>(val.get_allocator()),
350321
members_(std::move(val.members_))
351322
{
352323
}
353324

354-
sorted_json_object(sorted_json_object&& val,const allocator_type& alloc)
355-
: allocator_holder<allocator_type>(alloc), members_(std::move(val.members_),key_value_allocator_type(alloc))
356-
{
357-
}
358-
359325
sorted_json_object& operator=(const sorted_json_object& val)
360326
{
361327
allocator_holder<allocator_type>::operator=(val.get_allocator());
@@ -369,6 +335,17 @@ namespace jsoncons {
369335
return *this;
370336
}
371337

338+
sorted_json_object(const sorted_json_object& val, const allocator_type& alloc)
339+
: allocator_holder<allocator_type>(alloc),
340+
members_(val.members_,key_value_allocator_type(alloc))
341+
{
342+
}
343+
344+
sorted_json_object(sorted_json_object&& val,const allocator_type& alloc)
345+
: allocator_holder<allocator_type>(alloc), members_(std::move(val.members_),key_value_allocator_type(alloc))
346+
{
347+
}
348+
372349
template<class InputIt>
373350
sorted_json_object(InputIt first, InputIt last)
374351
{
@@ -690,7 +667,8 @@ namespace jsoncons {
690667
}
691668
else
692669
{
693-
it = members_.emplace(it, key_type(name.begin(),name.end()),
670+
it = members_.emplace(it,
671+
key_type(name.begin(),name.end()),
694672
std::forward<Args>(args)...);
695673
inserted = true;
696674
}
@@ -1094,13 +1072,6 @@ namespace jsoncons {
10941072
{
10951073
}
10961074

1097-
order_preserving_json_object(order_preserving_json_object&& val,const allocator_type& alloc)
1098-
: allocator_holder<allocator_type>(alloc),
1099-
members_(std::move(val.members_),key_value_allocator_type(alloc)),
1100-
index_(std::move(val.index_),index_allocator_type(alloc))
1101-
{
1102-
}
1103-
11041075
order_preserving_json_object(order_preserving_json_object&& val)
11051076
: allocator_holder<allocator_type>(val.get_allocator()),
11061077
members_(std::move(val.members_)),
@@ -1115,6 +1086,13 @@ namespace jsoncons {
11151086
{
11161087
}
11171088

1089+
order_preserving_json_object(order_preserving_json_object&& val,const allocator_type& alloc)
1090+
: allocator_holder<allocator_type>(alloc),
1091+
members_(std::move(val.members_),key_value_allocator_type(alloc)),
1092+
index_(std::move(val.index_),index_allocator_type(alloc))
1093+
{
1094+
}
1095+
11181096
template<class InputIt>
11191097
order_preserving_json_object(InputIt first, InputIt last)
11201098
{

0 commit comments

Comments
 (0)