Skip to content

Commit bdfa8ac

Browse files
committed
Separate interface from implementation to make interface clearer
1 parent 15eb1ad commit bdfa8ac

File tree

2 files changed

+302
-251
lines changed

2 files changed

+302
-251
lines changed

src/generic/stage2/json_iterator.h

Lines changed: 56 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -14,52 +14,20 @@ class json_iterator {
1414
template<bool STREAMING, typename V>
1515
SIMDJSON_WARN_UNUSED simdjson_really_inline error_code walk_document(V &visitor) noexcept;
1616

17-
// Start a structural
18-
simdjson_really_inline json_iterator(dom_parser_implementation &_dom_parser, size_t start_structural_index)
19-
: buf{_dom_parser.buf},
20-
next_structural{&_dom_parser.structural_indexes[start_structural_index]},
21-
dom_parser{_dom_parser} {
22-
}
17+
simdjson_really_inline json_iterator(dom_parser_implementation &_dom_parser, size_t start_structural_index);
2318

2419
// Get the buffer position of the current structural character
25-
simdjson_really_inline char peek_next_char() {
26-
return buf[*(next_structural)];
27-
}
28-
simdjson_really_inline const uint8_t *advance() {
29-
return &buf[*(next_structural++)];
30-
}
31-
simdjson_really_inline size_t remaining_len() {
32-
return dom_parser.len - *(next_structural-1);
33-
}
34-
35-
simdjson_really_inline bool at_end() {
36-
return next_structural == &dom_parser.structural_indexes[dom_parser.n_structural_indexes];
37-
}
38-
simdjson_really_inline bool at_beginning() {
39-
return next_structural == dom_parser.structural_indexes.get();
40-
}
41-
42-
simdjson_really_inline void log_value(const char *type) {
43-
logger::log_line(*this, "", type, "");
44-
}
45-
46-
simdjson_really_inline void log_start_value(const char *type) {
47-
logger::log_line(*this, "+", type, "");
48-
if (logger::LOG_ENABLED) { logger::log_depth++; }
49-
}
50-
51-
simdjson_really_inline void log_end_value(const char *type) {
52-
if (logger::LOG_ENABLED) { logger::log_depth--; }
53-
logger::log_line(*this, "-", type, "");
54-
}
55-
56-
simdjson_really_inline void log_error(const char *error) {
57-
logger::log_line(*this, "", "ERROR", error);
58-
}
59-
60-
simdjson_really_inline uint8_t last_structural() {
61-
return buf[dom_parser.structural_indexes[dom_parser.n_structural_indexes - 1]];
62-
}
20+
simdjson_really_inline char peek_next_char() const noexcept;
21+
simdjson_really_inline const uint8_t *advance() noexcept;
22+
simdjson_really_inline size_t remaining_len() const noexcept;
23+
simdjson_really_inline bool at_end() const noexcept;
24+
simdjson_really_inline bool at_beginning() const noexcept;
25+
simdjson_really_inline uint8_t last_structural() const noexcept;
26+
27+
simdjson_really_inline void log_value(const char *type) const noexcept;
28+
simdjson_really_inline void log_start_value(const char *type) const noexcept;
29+
simdjson_really_inline void log_end_value(const char *type) const noexcept;
30+
simdjson_really_inline void log_error(const char *error) const noexcept;
6331
};
6432

6533
template<bool STREAMING, typename V>
@@ -190,6 +158,50 @@ SIMDJSON_WARN_UNUSED simdjson_really_inline error_code json_iterator::walk_docum
190158

191159
} // walk_document()
192160

161+
simdjson_really_inline json_iterator::json_iterator(dom_parser_implementation &_dom_parser, size_t start_structural_index)
162+
: buf{_dom_parser.buf},
163+
next_structural{&_dom_parser.structural_indexes[start_structural_index]},
164+
dom_parser{_dom_parser} {
165+
}
166+
167+
simdjson_really_inline char json_iterator::peek_next_char() const noexcept {
168+
return buf[*(next_structural)];
169+
}
170+
simdjson_really_inline const uint8_t *json_iterator::advance() noexcept {
171+
return &buf[*(next_structural++)];
172+
}
173+
simdjson_really_inline size_t json_iterator::remaining_len() const noexcept {
174+
return dom_parser.len - *(next_structural-1);
175+
}
176+
177+
simdjson_really_inline bool json_iterator::at_end() const noexcept {
178+
return next_structural == &dom_parser.structural_indexes[dom_parser.n_structural_indexes];
179+
}
180+
simdjson_really_inline bool json_iterator::at_beginning() const noexcept {
181+
return next_structural == dom_parser.structural_indexes.get();
182+
}
183+
simdjson_really_inline uint8_t json_iterator::last_structural() const noexcept {
184+
return buf[dom_parser.structural_indexes[dom_parser.n_structural_indexes - 1]];
185+
}
186+
187+
simdjson_really_inline void json_iterator::log_value(const char *type) const noexcept {
188+
logger::log_line(*this, "", type, "");
189+
}
190+
191+
simdjson_really_inline void json_iterator::log_start_value(const char *type) const noexcept {
192+
logger::log_line(*this, "+", type, "");
193+
if (logger::LOG_ENABLED) { logger::log_depth++; }
194+
}
195+
196+
simdjson_really_inline void json_iterator::log_end_value(const char *type) const noexcept {
197+
if (logger::LOG_ENABLED) { logger::log_depth--; }
198+
logger::log_line(*this, "-", type, "");
199+
}
200+
201+
simdjson_really_inline void json_iterator::log_error(const char *error) const noexcept {
202+
logger::log_line(*this, "", "ERROR", error);
203+
}
204+
193205
} // namespace stage2
194206
} // namespace SIMDJSON_IMPLEMENTATION
195207
} // unnamed namespace

0 commit comments

Comments
 (0)