8000 Move on_start/end_string to stage 2 code · JavaScriptExpert/simdjson@65d784e · GitHub
[go: up one dir, main page]

Skip to content

Commit 65d784e

Browse files
committed
Move on_start/end_string to stage 2 code
1 parent 35afb6c commit 65d784e

File tree

3 files changed

+22
-25
lines changed

3 files changed

+22
-25
lines changed

include/simdjson/document.h

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1022,9 +1022,6 @@ class parser {
10221022
// Parser callbacks: these are internal!
10231023
//
10241024

1025-
/** @private this should be called when parsing (right before writing the tapes) */
1026-
really_inline uint8_t *on_start_string() noexcept; ///< @private
1027-
really_inline bool on_end_string(uint8_t *dst) noexcept; ///< @private
10281025
really_inline bool on_number_s64(int64_t value) noexcept; ///< @private
10291026
really_inline bool on_number_u64(uint64_t value) noexcept; ///< @private
10301027
really_inline bool on_number_double(double value) noexcept; ///< @private

src/document_parser_callbacks.h

Lines changed: 0 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -10,26 +10,6 @@ namespace dom {
1010
// Parser callbacks
1111
//
1212

13-
really_inline uint8_t *parser::on_start_string() noexcept {
14-
/* we advance the point, accounting for the fact that we have a NULL
15-
* termination */
16-
write_tape(current_string_buf_loc - doc.string_buf.get(), internal::tape_type::STRING);
17-
return current_string_buf_loc + sizeof(uint32_t);
18-
}
19-
20-
really_inline bool parser::on_end_string(uint8_t *dst) noexcept {
21-
uint32_t str_length = uint32_t(dst - (current_string_buf_loc + sizeof(uint32_t)));
22-
// TODO check for overflow in case someone has a crazy string (>=4GB?)
23-
// But only add the overflow check when the document itself exceeds 4GB
24-
// Currently unneeded because we refuse to parse docs larger or equal to 4GB.
25-
memcpy(current_string_buf_loc, &str_length, sizeof(uint32_t));
26-
// NULL termination is still handy if you expect all your strings to
27-
// be NULL terminated? It comes at a small cost
28-
*dst = 0;
29-
current_string_buf_loc = dst + 1;
30-
return true;
31-
}
32-
3313
really_inline bool parser::on_number_s64(int64_t value) noexcept {
3414
write_tape(0, internal::tape_type::INT64);
3515
std::memcpy(&doc.tape[current_loc], &value, sizeof(value));

src/generic/stage2_build_tape.h

Lines changed: 22 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -179,13 +179,33 @@ struct structural_parser {
179179
doc_parser.containing_scope[depth - 1].count++; // we have a key value pair in the object at parser.depth - 1
180180
}
181181

182+
really_inline uint8_t *on_start_string() noexcept {
183+
/* we advance the point, accounting for the fact that we have a NULL
184+
* termination */
185+
doc_parser.write_tape(doc_parser.current_string_buf_loc - doc_parser.doc.string_buf.get(), internal::tape_type::STRING);
186+
return doc_parser.current_string_buf_loc + sizeof(uint32_t);
187+
}
188+
189+
really_inline bool on_end_string(uint8_t *dst) noexcept {
190+
uint32_t str_length = uint32_t(dst - (doc_parser.current_string_buf_loc + sizeof(uint32_t)));
191+
// TODO check for overflow in case someone has a crazy string (>=4GB?)
192+
// But only add the overflow check when the document itself exceeds 4GB
193+
// Currently unneeded because we refuse to parse docs larger or equal to 4GB.
194+
memcpy(doc_parser.current_string_buf_loc, &str_length, sizeof(uint32_t));
195+
// NULL termination is still handy if you expect all your strings to
196+
// be NULL terminated? It comes at a small cost
197+
*dst = 0;
198+
doc_parser.current_string_buf_loc = dst + 1;
199+
return true;
200+
}
201+
182202
WARN_UNUSED really_inline bool parse_string() {
183-
uint8_t *dst = doc_parser.on_start_string();
203+
uint8_t *dst = on_start_string();
184204
dst = stringparsing::parse_string(structurals.current(), dst);
185205
if (dst == nullptr) {
186206
return true;
187207
}
188-
return !doc_parser.on_end_string(dst);
208+
return !on_end_string(dst);
189209
}
190210

191211
WARN_UNUSED really_inline bool parse_number(const uint8_t *src, bool found_minus) {

0 commit comments

Comments
 (0)
0