using allocator for bson

This commit is contained in:
alex 2023-09-29 09:45:55 +02:00
parent fac07e22c5
commit cf81aa75b6

View File

@ -6903,7 +6903,10 @@ class json_sax_dom_parser
/// the parsed JSON value /// the parsed JSON value
BasicJsonType& root; BasicJsonType& root;
/// stack to model hierarchy of values /// stack to model hierarchy of values
std::vector<BasicJsonType*> ref_stack {};
using allocator_type = typename BasicJsonType::allocator_type;
std::vector<BasicJsonType*,allocator_type> ref_stack {};
/// helper to hold the reference for the next object element /// helper to hold the reference for the next object element
BasicJsonType* object_element = nullptr; BasicJsonType* object_element = nullptr;
/// whether a syntax error occurred /// whether a syntax error occurred
@ -8915,8 +8918,10 @@ scan_number_done:
position_t position {}; position_t position {};
/// raw input token string (for error messages) /// raw input token string (for error messages)
std::vector<char_type> token_string {};
using allocator_type = typename BasicJsonType::allocator_type;
std::vector<char_type,allocator_type> token_string {};
/// buffer for variable-length tokens (numbers, strings) /// buffer for variable-length tokens (numbers, strings)
string_t token_buffer {}; string_t token_buffer {};
@ -11791,7 +11796,7 @@ class binary_reader
case token_type::value_unsigned: case token_type::value_unsigned:
return sax->number_unsigned(number_lexer.get_number_unsigned()); return sax->number_unsigned(number_lexer.get_number_unsigned());
case token_type::value_float: case token_type::value_float:
return sax->number_float(number_lexer.get_number_float(), std::move(number_string)); return sax->number_float(number_lexer.get_number_float(), std::move(static_cast<string_t>(number_string)));
case token_type::uninitialized: case token_type::uninitialized:
case token_type::literal_true: case token_type::literal_true:
case token_type::literal_false: case token_type::literal_false:
@ -12165,7 +12170,7 @@ class parser
using string_t = typename BasicJsonType::string_t; using string_t = typename BasicJsonType::string_t;
using lexer_t = lexer<BasicJsonType, InputAdapterType>; using lexer_t = lexer<BasicJsonType, InputAdapterType>;
using token_type = typename lexer_t::token_type; using token_type = typename lexer_t::token_type;
using allocator_type = typename BasicJsonType::string_t::allocator_type;
public: public:
/// a parser reading from an input adapter /// a parser reading from an input adapter
explicit parser(InputAdapterType&& adapter, explicit parser(InputAdapterType&& adapter,
@ -12279,9 +12284,10 @@ class parser
JSON_HEDLEY_NON_NULL(2) JSON_HEDLEY_NON_NULL(2)
bool sax_parse_internal(SAX* sax) bool sax_parse_internal(SAX* sax)
{ {
using allocator_type = typename BasicJsonType::allocator_type;
// stack to remember the hierarchy of structured values we are parsing // stack to remember the hierarchy of structured values we are parsing
// true = array; false = object // true = array; false = object
std::vector<bool> states; std::vector<bool,allocator_type> states;
// value to avoid a goto (see comment where set to true) // value to avoid a goto (see comment where set to true)
bool skip_to_state_evaluation = false; bool skip_to_state_evaluation = false;
@ -14950,7 +14956,10 @@ class output_adapter
public: public:
template<typename AllocatorType = std::allocator<CharType>> template<typename AllocatorType = std::allocator<CharType>>
output_adapter(std::vector<CharType, AllocatorType>& vec) output_adapter(std::vector<CharType, AllocatorType>& vec)
: oa(std::make_shared<output_vector_adapter<CharType, AllocatorType>>(vec)) {} {
AllocatorType alloc;
oa = std::allocate_shared<output_vector_adapter<CharType, AllocatorType>>(alloc ,vec);
}
#ifndef JSON_NO_IO #ifndef JSON_NO_IO
output_adapter(std::basic_ostream<CharType>& s) output_adapter(std::basic_ostream<CharType>& s)
@ -16061,7 +16070,7 @@ class binary_writer
const std::size_t embedded_document_size = std::accumulate(std::begin(value), std::end(value), static_cast<std::size_t>(0), [&array_index](std::size_t result, const typename BasicJsonType::array_t::value_type & el) const std::size_t embedded_document_size = std::accumulate(std::begin(value), std::end(value), static_cast<std::size_t>(0), [&array_index](std::size_t result, const typename BasicJsonType::array_t::value_type & el)
{ {
return result + calc_bson_element_size(std::to_string(array_index++), el); return result + calc_bson_element_size(static_cast<string_t>(std::to_string(array_index++)), el);
}); });
return sizeof(std::int32_t) + embedded_document_size + 1ul; return sizeof(std::int32_t) + embedded_document_size + 1ul;
@ -16088,7 +16097,7 @@ class binary_writer
for (const auto& el : value) for (const auto& el : value)
{ {
write_bson_element(std::to_string(array_index++), el); write_bson_element(static_cast<string_t>(std::to_string(array_index++)), el);
} }
oa->write_character(to_char_type(0x00)); oa->write_character(to_char_type(0x00));
@ -19780,7 +19789,7 @@ class basic_json // NOLINT(cppcoreguidelines-special-member-functions,hicpp-spec
if (t == value_t::array || t == value_t::object) if (t == value_t::array || t == value_t::object)
{ {
// flatten the current json_value to a heap-allocated stack // flatten the current json_value to a heap-allocated stack
std::vector<basic_json> stack; std::vector<basic_json,AllocatorType<basic_json>> stack;
// move the top-level items to stack // move the top-level items to stack
if (t == value_t::array) if (t == value_t::array)