File tree Expand file tree Collapse file tree 1 file changed +19
-6
lines changed Expand file tree Collapse file tree 1 file changed +19
-6
lines changed Original file line number Diff line number Diff line change 66
77#include < cstddef>
88#include < cstdint>
9+ #include < deque>
910#include < string>
1011#include < string_view>
1112#include < utility>
@@ -22,14 +23,27 @@ namespace tao::json::events
2223 template < template < typename ... > class Traits >
2324 struct set_basic_value
2425 {
25- static constexpr size_t count_ = 4 ;
26- struct ArrayElements
26+ static constexpr size_t count_ = 42 ;
27+ struct InPlaceVector
2728 {
28- basic_value< Traits > array[ count_ ];
29+ union
30+ {
31+ basic_value< Traits > array[ count_ ];
32+ };
2933 size_t count = 0 ;
34+ InPlaceVector () {}
35+ ~InPlaceVector ()
36+ {
37+ std::destroy_n ( array, std::min ( count, count_ ) );
38+ }
39+ void emplace_back ( basic_value< Traits >&& v )
40+ {
41+ ::new ( array + count ) basic_value< Traits >{ std::move ( v ) };
42+ ++count;
43+ }
3044 };
3145 std::vector< basic_value< Traits > > stack_;
32- std::vector< ArrayElements > elements_;
46+ std::deque< InPlaceVector > elements_;
3347 std::vector< std::string > keys_;
3448 basic_value< Traits >& value_;
3549
@@ -118,8 +132,7 @@ namespace tao::json::events
118132 {
119133 auto & elements = elements_.back ();
120134 if ( elements.count < count_ ) {
121- elements.array [ elements.count ] = std::move ( value_ );
122- ++elements.count ;
135+ elements.emplace_back ( std::move ( value_ ) );
123136 return ;
124137 }
125138 auto & a = stack_.back ().get_array ();
You can’t perform that action at this time.
0 commit comments