Coverage Report

Created: 2026-01-16 06:36

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/simdjson/include/simdjson/generic/dom_parser_implementation.h
Line
Count
Source
1
#ifndef SIMDJSON_GENERIC_DOM_PARSER_IMPLEMENTATION_H
2
3
#ifndef SIMDJSON_CONDITIONAL_INCLUDE
4
#define SIMDJSON_GENERIC_DOM_PARSER_IMPLEMENTATION_H
5
#include "simdjson/generic/base.h"
6
#include "simdjson/internal/dom_parser_implementation.h"
7
#endif // SIMDJSON_CONDITIONAL_INCLUDE
8
9
namespace simdjson {
10
namespace SIMDJSON_IMPLEMENTATION {
11
12
// expectation: sizeof(open_container) = 64/8.
13
struct open_container {
14
  uint32_t tape_index; // where, on the tape, does the scope ([,{) begins
15
  uint32_t count; // how many elements in the scope
16
}; // struct open_container
17
18
static_assert(sizeof(open_container) == 64/8, "Open container must be 64 bits");
19
20
class dom_parser_implementation final : public internal::dom_parser_implementation {
21
public:
22
  /** Tape location of each open { or [ */
23
  std::unique_ptr<open_container[]> open_containers{};
24
  /** Whether each open container is a [ or { */
25
  std::unique_ptr<bool[]> is_array{};
26
  /** Buffer passed to stage 1 */
27
  const uint8_t *buf{};
28
  /** Length passed to stage 1 */
29
  size_t len{0};
30
  /** Document passed to stage 2 */
31
  dom::document *doc{};
32
33
  inline dom_parser_implementation() noexcept;
34
  inline dom_parser_implementation(dom_parser_implementation &&other) noexcept;
35
  inline dom_parser_implementation &operator=(dom_parser_implementation &&other) noexcept;
36
  dom_parser_implementation(const dom_parser_implementation &) = delete;
37
  dom_parser_implementation &operator=(const dom_parser_implementation &) = delete;
38
39
  simdjson_warn_unused error_code parse(const uint8_t *buf, size_t len, dom::document &doc) noexcept final;
40
  simdjson_warn_unused error_code stage1(const uint8_t *buf, size_t len, stage1_mode partial) noexcept final;
41
  simdjson_warn_unused error_code stage2(dom::document &doc) noexcept final;
42
  simdjson_warn_unused error_code stage2_next(dom::document &doc) noexcept final;
43
  simdjson_warn_unused uint8_t *parse_string(const uint8_t *src, uint8_t *dst, bool allow_replacement) const noexcept final;
44
  simdjson_warn_unused uint8_t *parse_wobbly_string(const uint8_t *src, uint8_t *dst) const noexcept final;
45
  inline simdjson_warn_unused error_code set_capacity(size_t capacity) noexcept final;
46
  inline simdjson_warn_unused error_code set_max_depth(size_t max_depth) noexcept final;
47
private:
48
  simdjson_inline simdjson_warn_unused error_code set_capacity_stage1(size_t capacity);
49
50
};
51
52
} // namespace SIMDJSON_IMPLEMENTATION
53
} // namespace simdjson
54
55
namespace simdjson {
56
namespace SIMDJSON_IMPLEMENTATION {
57
58
122k
inline dom_parser_implementation::dom_parser_implementation() noexcept = default;
simdjson::haswell::dom_parser_implementation::dom_parser_implementation()
Line
Count
Source
58
98.2k
inline dom_parser_implementation::dom_parser_implementation() noexcept = default;
Unexecuted instantiation: simdjson::icelake::dom_parser_implementation::dom_parser_implementation()
simdjson::westmere::dom_parser_implementation::dom_parser_implementation()
Line
Count
Source
58
12.1k
inline dom_parser_implementation::dom_parser_implementation() noexcept = default;
simdjson::fallback::dom_parser_implementation::dom_parser_implementation()
Line
Count
Source
58
12.1k
inline dom_parser_implementation::dom_parser_implementation() noexcept = default;
59
inline dom_parser_implementation::dom_parser_implementation(dom_parser_implementation &&other) noexcept = default;
60
0
inline dom_parser_implementation &dom_parser_implementation::operator=(dom_parser_implementation &&other) noexcept = default;
Unexecuted instantiation: simdjson::fallback::dom_parser_implementation::operator=(simdjson::fallback::dom_parser_implementation&&)
Unexecuted instantiation: simdjson::haswell::dom_parser_implementation::operator=(simdjson::haswell::dom_parser_implementation&&)
Unexecuted instantiation: simdjson::icelake::dom_parser_implementation::operator=(simdjson::icelake::dom_parser_implementation&&)
Unexecuted instantiation: simdjson::westmere::dom_parser_implementation::operator=(simdjson::westmere::dom_parser_implementation&&)
61
62
// Leaving these here so they can be inlined if so desired
63
122k
inline simdjson_warn_unused error_code dom_parser_implementation::set_capacity(size_t capacity) noexcept {
64
122k
  if(capacity > SIMDJSON_MAXSIZE_BYTES) { return CAPACITY; }
65
  // Stage 1 index output
66
122k
  size_t max_structures = SIMDJSON_ROUNDUP_N(capacity, 64) + 2 + 7;
67
122k
  structural_indexes.reset( new (std::nothrow) uint32_t[max_structures] );
68
122k
  if (!structural_indexes) { _capacity = 0; return MEMALLOC; }
69
122k
  structural_indexes[0] = 0;
70
122k
  n_structural_indexes = 0;
71
72
122k
  _capacity = capacity;
73
122k
  return SUCCESS;
74
122k
}
simdjson::fallback::dom_parser_implementation::set_capacity(unsigned long)
Line
Count
Source
63
12.1k
inline simdjson_warn_unused error_code dom_parser_implementation::set_capacity(size_t capacity) noexcept {
64
12.1k
  if(capacity > SIMDJSON_MAXSIZE_BYTES) { return CAPACITY; }
65
  // Stage 1 index output
66
12.1k
  size_t max_structures = SIMDJSON_ROUNDUP_N(capacity, 64) + 2 + 7;
67
12.1k
  structural_indexes.reset( new (std::nothrow) uint32_t[max_structures] );
68
12.1k
  if (!structural_indexes) { _capacity = 0; return MEMALLOC; }
69
12.1k
  structural_indexes[0] = 0;
70
12.1k
  n_structural_indexes = 0;
71
72
12.1k
  _capacity = capacity;
73
12.1k
  return SUCCESS;
74
12.1k
}
simdjson::haswell::dom_parser_implementation::set_capacity(unsigned long)
Line
Count
Source
63
98.2k
inline simdjson_warn_unused error_code dom_parser_implementation::set_capacity(size_t capacity) noexcept {
64
98.2k
  if(capacity > SIMDJSON_MAXSIZE_BYTES) { return CAPACITY; }
65
  // Stage 1 index output
66
98.2k
  size_t max_structures = SIMDJSON_ROUNDUP_N(capacity, 64) + 2 + 7;
67
98.2k
  structural_indexes.reset( new (std::nothrow) uint32_t[max_structures] );
68
98.2k
  if (!structural_indexes) { _capacity = 0; return MEMALLOC; }
69
98.2k
  structural_indexes[0] = 0;
70
98.2k
  n_structural_indexes = 0;
71
72
98.2k
  _capacity = capacity;
73
98.2k
  return SUCCESS;
74
98.2k
}
Unexecuted instantiation: simdjson::icelake::dom_parser_implementation::set_capacity(unsigned long)
simdjson::westmere::dom_parser_implementation::set_capacity(unsigned long)
Line
Count
Source
63
12.1k
inline simdjson_warn_unused error_code dom_parser_implementation::set_capacity(size_t capacity) noexcept {
64
12.1k
  if(capacity > SIMDJSON_MAXSIZE_BYTES) { return CAPACITY; }
65
  // Stage 1 index output
66
12.1k
  size_t max_structures = SIMDJSON_ROUNDUP_N(capacity, 64) + 2 + 7;
67
12.1k
  structural_indexes.reset( new (std::nothrow) uint32_t[max_structures] );
68
12.1k
  if (!structural_indexes) { _capacity = 0; return MEMALLOC; }
69
12.1k
  structural_indexes[0] = 0;
70
12.1k
  n_structural_indexes = 0;
71
72
12.1k
  _capacity = capacity;
73
12.1k
  return SUCCESS;
74
12.1k
}
75
76
122k
inline simdjson_warn_unused error_code dom_parser_implementation::set_max_depth(size_t max_depth) noexcept {
77
  // Stage 2 stacks
78
122k
  open_containers.reset(new (std::nothrow) open_container[max_depth]);
79
122k
  is_array.reset(new (std::nothrow) bool[max_depth]);
80
122k
  if (!is_array || !open_containers) { _max_depth = 0; return MEMALLOC; }
81
82
122k
  _max_depth = max_depth;
83
122k
  return SUCCESS;
84
122k
}
simdjson::fallback::dom_parser_implementation::set_max_depth(unsigned long)
Line
Count
Source
76
12.1k
inline simdjson_warn_unused error_code dom_parser_implementation::set_max_depth(size_t max_depth) noexcept {
77
  // Stage 2 stacks
78
12.1k
  open_containers.reset(new (std::nothrow) open_container[max_depth]);
79
12.1k
  is_array.reset(new (std::nothrow) bool[max_depth]);
80
12.1k
  if (!is_array || !open_containers) { _max_depth = 0; return MEMALLOC; }
81
82
12.1k
  _max_depth = max_depth;
83
12.1k
  return SUCCESS;
84
12.1k
}
simdjson::haswell::dom_parser_implementation::set_max_depth(unsigned long)
Line
Count
Source
76
98.2k
inline simdjson_warn_unused error_code dom_parser_implementation::set_max_depth(size_t max_depth) noexcept {
77
  // Stage 2 stacks
78
98.2k
  open_containers.reset(new (std::nothrow) open_container[max_depth]);
79
98.2k
  is_array.reset(new (std::nothrow) bool[max_depth]);
80
98.2k
  if (!is_array || !open_containers) { _max_depth = 0; return MEMALLOC; }
81
82
98.2k
  _max_depth = max_depth;
83
98.2k
  return SUCCESS;
84
98.2k
}
Unexecuted instantiation: simdjson::icelake::dom_parser_implementation::set_max_depth(unsigned long)
simdjson::westmere::dom_parser_implementation::set_max_depth(unsigned long)
Line
Count
Source
76
12.1k
inline simdjson_warn_unused error_code dom_parser_implementation::set_max_depth(size_t max_depth) noexcept {
77
  // Stage 2 stacks
78
12.1k
  open_containers.reset(new (std::nothrow) open_container[max_depth]);
79
12.1k
  is_array.reset(new (std::nothrow) bool[max_depth]);
80
12.1k
  if (!is_array || !open_containers) { _max_depth = 0; return MEMALLOC; }
81
82
12.1k
  _max_depth = max_depth;
83
12.1k
  return SUCCESS;
84
12.1k
}
85
86
} // namespace SIMDJSON_IMPLEMENTATION
87
} // namespace simdjson
88
89
#endif // SIMDJSON_GENERIC_DOM_PARSER_IMPLEMENTATION_H