Skip to content

Commit 0fffbc3

Browse files
committed
sped up parsing by ~0..30%
1 parent b8a9d7f commit 0fffbc3

File tree

1 file changed

+19
-6
lines changed

1 file changed

+19
-6
lines changed

include/tao/json/events/set_value.hpp

Lines changed: 19 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
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();

0 commit comments

Comments
 (0)