@@ -31,7 +31,6 @@ class json_container
31
31
using view_allocator_type = typename std::allocator_traits<allocator_type>:: template rebind_alloc<json_ref>;
32
32
using buffer_type = std::basic_string<char ,std::char_traits<char >,char_allocator_type>;
33
33
34
- buffer_type buf_;
35
34
json_ref* root_{nullptr };
36
35
std::size_t root_capacity_{ 0 };
37
36
// The string pool used by JSON values (nullable).
@@ -41,52 +40,51 @@ class json_container
41
40
public:
42
41
json_container () = default ;
43
42
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,
45
44
uint8_t * hdr, std::size_t hdr_capacity,
46
45
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 ),
48
47
alloc_{alloc}
49
48
{
50
49
}
51
50
json_container (const json_container& other) = delete ;
52
51
json_container (json_container&& other) noexcept
53
52
: root_(nullptr ), hdr_(nullptr ), hdr_capacity_(0 )
54
53
{
55
- std::swap (buf_, other.buf_ );
56
54
std::swap (root_, other.root_ );
57
55
std::swap (hdr_, other.hdr_ );
58
56
std::swap (hdr_capacity_, other.hdr_capacity_ );
59
57
}
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
- }
73
58
74
59
~json_container ()
75
60
{
76
61
if (hdr_ != nullptr )
77
62
{
78
- u8_allocator_type u8_alloc{alloc_};
63
+ u8_allocator_type u8_alloc{ alloc_ };
79
64
std::allocator_traits<allocator_type>::deallocate (u8_alloc, (uint8_t *)hdr_, hdr_capacity_);
80
65
hdr_ = nullptr ;
81
66
}
82
67
if (root_ != nullptr )
83
68
{
84
- view_allocator_type view_alloc{alloc_};
69
+ view_allocator_type view_alloc{ alloc_ };
85
70
std::allocator_traits<view_allocator_type>::deallocate (view_alloc, root_, root_capacity_);
86
71
root_ = nullptr ;
87
72
}
88
73
}
89
74
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
+
90
88
json_view root ()
91
89
{
92
90
return json_view (root_);
@@ -126,21 +124,21 @@ class json_container
126
124
read_json_flags flg,
127
125
const allocator_type& alloc);
128
126
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,
130
128
std::size_t hdr_capacity,
131
129
uint8_t *cur,
132
130
uint8_t *end,
133
131
read_json_flags flags,
134
132
const allocator_type& alloc);
135
133
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,
137
135
std::size_t hdr_capacity,
138
136
uint8_t *cur,
139
137
uint8_t *end,
140
138
read_json_flags flags,
141
139
const allocator_type& alloc);
142
140
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,
144
142
std::size_t hdr_capacity,
145
143
uint8_t *cur,
146
144
uint8_t *end,
@@ -1630,7 +1628,7 @@ std::size_t fread_safe(void *buf, std::size_t size, FILE *file) {
1630
1628
1631
1629
/* * Read single value JSON document. */
1632
1630
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(
1634
1632
uint8_t *hdr,
1635
1633
std::size_t hdr_capacity,
1636
1634
uint8_t *cur,
@@ -1742,7 +1740,7 @@ parse_json_result<json_container<Allocator>> json_container<Allocator>::read_roo
1742
1740
}
1743
1741
1744
1742
// if (pre && *pre) **pre = '\0';
1745
- return json_container{std::move (buf), val_hdr, alc_len,
1743
+ return json_container{val_hdr, alc_len,
1746
1744
(flags & read_json_flags::insitu) != read_json_flags{} ? nullptr : hdr, hdr_capacity, alloc};
1747
1745
1748
1746
fail_comment:
@@ -1757,7 +1755,7 @@ parse_json_result<json_container<Allocator>> json_container<Allocator>::read_roo
1757
1755
1758
1756
/* * Read JSON document (accept all style, but optimized for minify). */
1759
1757
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(
1761
1759
uint8_t *hdr,
1762
1760
std::size_t hdr_capacity,
1763
1761
uint8_t *cur,
@@ -2226,7 +2224,7 @@ parse_json_result<json_container<Allocator>> json_container<Allocator>::read_roo
2226
2224
2227
2225
// if (pre && *pre) **pre = '\0';
2228
2226
2229
- return json_container{std::move (buf), val_hdr, alc_len,
2227
+ return json_container{val_hdr, alc_len,
2230
2228
(flags & read_json_flags::insitu) != read_json_flags{} ? nullptr : hdr, hdr_capacity, alloc};
2231
2229
2232
2230
fail_alloc:
@@ -2246,7 +2244,7 @@ parse_json_result<json_container<Allocator>> json_container<Allocator>::read_roo
2246
2244
2247
2245
/* * Read JSON document (accept all style, but optimized for pretty). */
2248
2246
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(
2250
2248
uint8_t *hdr,
2251
2249
std::size_t hdr_capacity,
2252
2250
uint8_t *cur,
@@ -2752,7 +2750,7 @@ parse_json_result<json_container<Allocator>> json_container<Allocator>::read_roo
2752
2750
if (JSONCONS_UNLIKELY (cur < end)) goto fail_garbage;
2753
2751
}
2754
2752
2755
- return json_container{std::move (buf), val_hdr, alc_len,
2753
+ return json_container{val_hdr, alc_len,
2756
2754
(flags & read_json_flags::insitu) != read_json_flags{} ? nullptr : hdr, hdr_capacity, alloc};
2757
2755
2758
2756
fail_alloc:
@@ -2831,17 +2829,15 @@ parse_json_result<json_container<Allocator>> json_container<Allocator>::parse(ch
2831
2829
}
2832
2830
}
2833
2831
2834
- buffer_type buf{alloc};
2835
-
2836
2832
/* read json document */
2837
2833
if (JSONCONS_LIKELY (char_is_container (*cur))) {
2838
2834
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);
2840
2836
} 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);
2842
2838
}
2843
2839
} 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);
2845
2841
}
2846
2842
2847
2843
#if 0
@@ -2929,17 +2925,15 @@ parse_json_result<json_container<Allocator>> json_container<Allocator>::yyjson_r
2929
2925
}
2930
2926
}
2931
2927
2932
- buffer_type buf{alloc};
2933
-
2934
2928
/* read json document */
2935
2929
if (JSONCONS_LIKELY (char_is_container (*cur))) {
2936
2930
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);
2938
2932
} 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);
2940
2934
}
2941
2935
} 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);
2943
2937
}
2944
2938
#if 0
2945
2939
/* check result */
0 commit comments