Skip to content

Commit 56c7e54

Browse files
committed
buf
1 parent c3b0b1b commit 56c7e54

File tree

1 file changed

+32
-38
lines changed

1 file changed

+32
-38
lines changed

include/jsoncons/views/json_container.hpp

Lines changed: 32 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,6 @@ class json_container
3131
using view_allocator_type = typename std::allocator_traits<allocator_type>:: template rebind_alloc<json_ref>;
3232
using buffer_type = std::basic_string<char,std::char_traits<char>,char_allocator_type>;
3333

34-
buffer_type buf_;
3534
json_ref* root_{nullptr};
3635
std::size_t root_capacity_{ 0 };
3736
// The string pool used by JSON values (nullable).
@@ -41,52 +40,51 @@ class json_container
4140
public:
4241
json_container() = default;
4342

44-
json_container(buffer_type&& buf, json_ref* root, std::size_t root_capacity,
43+
json_container(json_ref* root, std::size_t root_capacity,
4544
uint8_t* hdr, std::size_t hdr_capacity,
4645
const allocator_type& alloc)
47-
: buf_(std::move(buf)), root_(root), root_capacity_(root_capacity), hdr_(hdr), hdr_capacity_(0),
46+
: root_(root), root_capacity_(root_capacity), hdr_(hdr), hdr_capacity_(0),
4847
alloc_{alloc}
4948
{
5049
}
5150
json_container(const json_container& other) = delete;
5251
json_container(json_container&& other) noexcept
5352
: root_(nullptr), hdr_(nullptr), hdr_capacity_(0)
5453
{
55-
std::swap(buf_, other.buf_);
5654
std::swap(root_, other.root_);
5755
std::swap(hdr_, other.hdr_);
5856
std::swap(hdr_capacity_, other.hdr_capacity_);
5957
}
60-
json_container& operator=(const json_container& other) = delete;
61-
62-
json_container& operator=(json_container&& other) noexcept
63-
{
64-
if (this != &other)
65-
{
66-
std::swap(buf_, other.buf_);
67-
std::swap(root_, other.root_);
68-
std::swap(hdr_, other.hdr_);
69-
std::swap(hdr_capacity_, other.hdr_capacity_);
70-
}
71-
return *this;
72-
}
7358

7459
~json_container()
7560
{
7661
if (hdr_ != nullptr)
7762
{
78-
u8_allocator_type u8_alloc{alloc_};
63+
u8_allocator_type u8_alloc{ alloc_ };
7964
std::allocator_traits<allocator_type>::deallocate(u8_alloc, (uint8_t*)hdr_, hdr_capacity_);
8065
hdr_ = nullptr;
8166
}
8267
if (root_ != nullptr)
8368
{
84-
view_allocator_type view_alloc{alloc_};
69+
view_allocator_type view_alloc{ alloc_ };
8570
std::allocator_traits<view_allocator_type>::deallocate(view_alloc, root_, root_capacity_);
8671
root_ = nullptr;
8772
}
8873
}
8974

75+
json_container& operator=(const json_container& other) = delete;
76+
77+
json_container& operator=(json_container&& other) noexcept
78+
{
79+
if (this != &other)
80+
{
81+
std::swap(root_, other.root_);
82+
std::swap(hdr_, other.hdr_);
83+
std::swap(hdr_capacity_, other.hdr_capacity_);
84+
}
85+
return *this;
86+
}
87+
9088
json_view root()
9189
{
9290
return json_view(root_);
@@ -126,21 +124,21 @@ class json_container
126124
read_json_flags flg,
127125
const allocator_type& alloc);
128126

129-
static parse_json_result<json_container<Allocator>> read_root_single(buffer_type&& buf, uint8_t *hdr,
127+
static parse_json_result<json_container<Allocator>> read_root_single(uint8_t *hdr,
130128
std::size_t hdr_capacity,
131129
uint8_t *cur,
132130
uint8_t *end,
133131
read_json_flags flags,
134132
const allocator_type& alloc);
135133

136-
static parse_json_result<json_container<Allocator>> read_root_minify(buffer_type&& buf, uint8_t *hdr,
134+
static parse_json_result<json_container<Allocator>> read_root_minify(uint8_t *hdr,
137135
std::size_t hdr_capacity,
138136
uint8_t *cur,
139137
uint8_t *end,
140138
read_json_flags flags,
141139
const allocator_type& alloc);
142140

143-
static parse_json_result<json_container<Allocator>> read_root_pretty(buffer_type&& buf, uint8_t *hdr,
141+
static parse_json_result<json_container<Allocator>> read_root_pretty(uint8_t *hdr,
144142
std::size_t hdr_capacity,
145143
uint8_t *cur,
146144
uint8_t *end,
@@ -1630,7 +1628,7 @@ std::size_t fread_safe(void *buf, std::size_t size, FILE *file) {
16301628

16311629
/** Read single value JSON document. */
16321630
template <typename Allocator>
1633-
parse_json_result<json_container<Allocator>> json_container<Allocator>::read_root_single(buffer_type&& buf,
1631+
parse_json_result<json_container<Allocator>> json_container<Allocator>::read_root_single(
16341632
uint8_t *hdr,
16351633
std::size_t hdr_capacity,
16361634
uint8_t *cur,
@@ -1742,7 +1740,7 @@ parse_json_result<json_container<Allocator>> json_container<Allocator>::read_roo
17421740
}
17431741

17441742
//if (pre && *pre) **pre = '\0';
1745-
return json_container{std::move(buf), val_hdr, alc_len,
1743+
return json_container{val_hdr, alc_len,
17461744
(flags & read_json_flags::insitu) != read_json_flags{} ? nullptr : hdr, hdr_capacity, alloc};
17471745

17481746
fail_comment:
@@ -1757,7 +1755,7 @@ parse_json_result<json_container<Allocator>> json_container<Allocator>::read_roo
17571755

17581756
/** Read JSON document (accept all style, but optimized for minify). */
17591757
template <typename Allocator>
1760-
parse_json_result<json_container<Allocator>> json_container<Allocator>::read_root_minify(buffer_type&& buf,
1758+
parse_json_result<json_container<Allocator>> json_container<Allocator>::read_root_minify(
17611759
uint8_t *hdr,
17621760
std::size_t hdr_capacity,
17631761
uint8_t *cur,
@@ -2226,7 +2224,7 @@ parse_json_result<json_container<Allocator>> json_container<Allocator>::read_roo
22262224

22272225
//if (pre && *pre) **pre = '\0';
22282226

2229-
return json_container{std::move(buf), val_hdr, alc_len,
2227+
return json_container{val_hdr, alc_len,
22302228
(flags & read_json_flags::insitu) != read_json_flags{} ? nullptr : hdr, hdr_capacity, alloc};
22312229

22322230
fail_alloc:
@@ -2246,7 +2244,7 @@ parse_json_result<json_container<Allocator>> json_container<Allocator>::read_roo
22462244

22472245
/** Read JSON document (accept all style, but optimized for pretty). */
22482246
template <typename Allocator>
2249-
parse_json_result<json_container<Allocator>> json_container<Allocator>::read_root_pretty(buffer_type&& buf,
2247+
parse_json_result<json_container<Allocator>> json_container<Allocator>::read_root_pretty(
22502248
uint8_t *hdr,
22512249
std::size_t hdr_capacity,
22522250
uint8_t *cur,
@@ -2752,7 +2750,7 @@ parse_json_result<json_container<Allocator>> json_container<Allocator>::read_roo
27522750
if (JSONCONS_UNLIKELY(cur < end)) goto fail_garbage;
27532751
}
27542752

2755-
return json_container{std::move(buf), val_hdr, alc_len,
2753+
return json_container{val_hdr, alc_len,
27562754
(flags & read_json_flags::insitu) != read_json_flags{} ? nullptr : hdr, hdr_capacity, alloc};
27572755

27582756
fail_alloc:
@@ -2831,17 +2829,15 @@ parse_json_result<json_container<Allocator>> json_container<Allocator>::parse(ch
28312829
}
28322830
}
28332831

2834-
buffer_type buf{alloc};
2835-
28362832
/* read json document */
28372833
if (JSONCONS_LIKELY(char_is_container(*cur))) {
28382834
if (char_is_space(cur[1]) && char_is_space(cur[2])) {
2839-
return read_root_pretty(std::move(buf), hdr, hdr_capacity, cur, end, flags, alloc);
2835+
return read_root_pretty(hdr, hdr_capacity, cur, end, flags, alloc);
28402836
} else {
2841-
return read_root_minify(std::move(buf), hdr, hdr_capacity, cur, end, flags, alloc);
2837+
return read_root_minify(hdr, hdr_capacity, cur, end, flags, alloc);
28422838
}
28432839
} else {
2844-
return read_root_single(std::move(buf), hdr, hdr_capacity, cur, end, flags, alloc);
2840+
return read_root_single(hdr, hdr_capacity, cur, end, flags, alloc);
28452841
}
28462842

28472843
#if 0
@@ -2929,17 +2925,15 @@ parse_json_result<json_container<Allocator>> json_container<Allocator>::yyjson_r
29292925
}
29302926
}
29312927

2932-
buffer_type buf{alloc};
2933-
29342928
/* read json document */
29352929
if (JSONCONS_LIKELY(char_is_container(*cur))) {
29362930
if (char_is_space(cur[1]) && char_is_space(cur[2])) {
2937-
return read_root_pretty(std::move(buf), hdr, hdr_capacity, cur, end, flags, alloc);
2931+
return read_root_pretty(hdr, hdr_capacity, cur, end, flags, alloc);
29382932
} else {
2939-
return read_root_minify(std::move(buf), hdr, hdr_capacity, cur, end, flags, alloc);
2933+
return read_root_minify(hdr, hdr_capacity, cur, end, flags, alloc);
29402934
}
29412935
} else {
2942-
return read_root_single(std::move(buf), hdr, hdr_capacity, cur, end, flags, alloc);
2936+
return read_root_single(hdr, hdr_capacity, cur, end, flags, alloc);
29432937
}
29442938
#if 0
29452939
/* check result */

0 commit comments

Comments
 (0)