@@ -3,34 +3,33 @@ namespace stage2 {
33class structural_iterator {
44public:
55 const uint8_t * const buf;
6- uint32_t *next_structural;
7- uint8_t c{0 }; // used to track the (structural) character we are looking at
6+ uint32_t *current_structural;
87 dom_parser_implementation &parser;
98
10- really_inline structural_iterator (dom_parser_implementation &_parser, size_t next_structural_index)
9+ // Start a structural
10+ really_inline structural_iterator (dom_parser_implementation &_parser, size_t start_structural_index)
1111 : buf{_parser.buf },
12- next_structural {&_parser.structural_indexes [next_structural_index ]},
12+ current_structural {&_parser.structural_indexes [start_structural_index ]},
1313 parser{_parser} {
1414 }
15- really_inline char advance_char () {
16- c = buf[*next_structural];
17- next_structural++;
18- return c;
15+ // Get the buffer position of the current structural character
16+ really_inline const uint8_t * current () {
17+ return &buf[*current_structural];
1918 }
19+ // Get the current structural character
2020 really_inline char current_char () {
21- return c ;
21+ return buf[*current_structural] ;
2222 }
23+ // Get the next structural character without advancing
2324 really_inline char peek_char () {
24- return buf[*next_structural ];
25+ return buf[*(current_structural+ 1 ) ];
2526 }
26- really_inline const uint8_t * current () {
27- return &buf[current_structural_index ()];
27+ really_inline char advance_char () {
28+ current_structural++;
29+ return buf[*current_structural];
2830 }
2931 really_inline size_t remaining_len () {
30- return parser.len - current_structural_index ();
31- }
32- really_inline uint32_t current_structural_index () {
33- return *(next_structural-1 );
32+ return parser.len - *current_structural;
3433 }
3534 template <typename F>
3635 really_inline bool with_space_terminated_copy (const F& f) {
@@ -53,18 +52,18 @@ class structural_iterator {
5352 }
5453 memcpy (copy, buf, parser.len );
5554 memset (copy + parser.len , ' ' , SIMDJSON_PADDING);
56- bool result = f (reinterpret_cast <const uint8_t *>(copy), current_structural_index () );
55+ bool result = f (reinterpret_cast <const uint8_t *>(copy), *current_structural );
5756 free (copy);
5857 return result;
5958 }
6059 really_inline bool past_end (uint32_t n_structural_indexes) {
61- return next_structural > &parser.structural_indexes [n_structural_indexes];
60+ return current_structural >= &parser.structural_indexes [n_structural_indexes];
6261 }
6362 really_inline bool at_end (uint32_t n_structural_indexes) {
64- return next_structural == &parser.structural_indexes [n_structural_indexes];
63+ return current_structural == &parser.structural_indexes [n_structural_indexes];
6564 }
6665 really_inline bool at_beginning () {
67- return next_structural == & parser.structural_indexes [ 0 ] ;
66+ return current_structural == parser.structural_indexes . get () ;
6867 }
6968};
7069
0 commit comments