Skip to content

Commit cd6f204

Browse files
committed
Move write_tape() to stage 2 code
1 parent 269131e commit cd6f204

File tree

4 files changed

+23
-42
lines changed

4 files changed

+23
-42
lines changed

include/simdjson/document.h

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1018,11 +1018,6 @@ class parser {
10181018
/** @private Private and deprecated: use `parser.parse(...).doc.dump_raw_tape()` instead */
10191019
inline bool dump_raw_tape(std::ostream &os) const noexcept;
10201020

1021-
//
1022-
// Parser callbacks: these are internal!
1023-
//
1024-
1025-
inline void write_tape(uint64_t val, internal::tape_type t) noexcept;
10261021
private:
10271022
/**
10281023
* The maximum document length this parser will automatically support.

src/document_parser_callbacks.h

Lines changed: 0 additions & 20 deletions
This file was deleted.

src/generic/stage2_build_tape.h

Lines changed: 23 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -117,20 +117,23 @@ struct number_writer {
117117
parser &doc_parser;
118118

119119
really_inline void write_s64(int64_t value) noexcept {
120-
doc_parser.write_tape(0, internal::tape_type::INT64);
120+
write_tape(0, internal::tape_type::INT64);
121121
std::memcpy(&doc_parser.doc.tape[doc_parser.current_loc], &value, sizeof(value));
122122
++doc_parser.current_loc;
123123
}
124124
really_inline void write_u64(uint64_t value) noexcept {
125-
doc_parser.write_tape(0, internal::tape_type::UINT64);
125+
write_tape(0, internal::tape_type::UINT64);
126126
doc_parser.doc.tape[doc_parser.current_loc++] = value;
127127
}
128128
really_inline void write_double(double value) noexcept {
129-
doc_parser.write_tape(0, internal::tape_type::DOUBLE);
129+
write_tape(0, internal::tape_type::DOUBLE);
130130
static_assert(sizeof(value) == sizeof(doc_parser.doc.tape[doc_parser.current_loc]), "mismatch size");
131131
memcpy(&doc_parser.doc.tape[doc_parser.current_loc++], &value, sizeof(double));
132132
// doc.tape[doc.current_loc++] = *((uint64_t *)&d);
133133
}
134+
really_inline void write_tape(uint64_t val, internal::tape_type t) noexcept {
135+
doc_parser.doc.tape[doc_parser.current_loc++] = val | ((uint64_t(char(t))) << 56);
136+
}
134137
}; // struct number_writer
135138

136139
struct structural_parser {
@@ -148,7 +151,7 @@ struct structural_parser {
148151
WARN_UNUSED really_inline bool start_scope(internal::tape_type type, ret_address continue_state) {
149152
doc_parser.containing_scope[depth].tape_index = doc_parser.current_loc;
150153
doc_parser.containing_scope[depth].count = 0;
151-
doc_parser.write_tape(0, type); // if the document is correct, this gets rewritten later
154+
write_tape(0, type); // if the document is correct, this gets rewritten later
152155
doc_parser.ret_address[depth] = continue_state;
153156
depth++;
154157
return depth >= doc_parser.max_depth();
@@ -171,7 +174,7 @@ struct structural_parser {
171174
depth--;
172175
// write our doc.tape location to the header scope
173176
// The root scope gets written *at* the previous location.
174-
doc_parser.write_tape(doc_parser.containing_scope[depth].tape_index, type);
177+
write_tape(doc_parser.containing_scope[depth].tape_index, type);
175178
// count can overflow if it exceeds 24 bits... so we saturate
176179
// the convention being that a cnt of 0xffffff or more is undetermined in value (>= 0xffffff).
177180
const uint32_t start_tape_index = doc_parser.containing_scope[depth].tape_index;
@@ -191,18 +194,22 @@ struct structural_parser {
191194
end_scope(internal::tape_type::ROOT);
192195
}
193196

194-
// increment_count increments the count of keys in an object or values in an array.
195-
// Note that if you are at the level of the values or elements, the count
196-
// must be increment in the preceding depth (depth-1) where the array or
197-
// the object resides.
197+
really_inline void write_tape(uint64_t val, internal::tape_type t) noexcept {
198+
doc_parser.doc.tape[doc_parser.current_loc++] = val | ((uint64_t(char(t))) << 56);
199+
}
200+
201+
// increment_count increments the count of keys in an object or values in an array.
202+
// Note that if you are at the level of the values or elements, the count
203+
// must be increment in the preceding depth (depth-1) where the array or
204+
// the object resides.
198205
really_inline void increment_count() {
199206
doc_parser.containing_scope[depth - 1].count++; // we have a key value pair in the object at parser.depth - 1
200207
}
201208

202209
really_inline uint8_t *on_start_string() noexcept {
203210
/* we advance the point, accounting for the fact that we have a NULL
204211
* termination */
205-
doc_parser.write_tape(doc_parser.current_string_buf_loc - doc_parser.doc.string_buf.get(), internal::tape_type::STRING);
212+
write_tape(doc_parser.current_string_buf_loc - doc_parser.doc.string_buf.get(), internal::tape_type::STRING);
206213
return doc_parser.current_string_buf_loc + sizeof(uint32_t);
207214
}
208215

@@ -240,15 +247,15 @@ struct structural_parser {
240247
switch (structurals.current_char()) {
241248
case 't':
242249
if (!atomparsing::is_valid_true_atom(structurals.current())) { return true; }
243-
doc_parser.write_tape(0, internal::tape_type::TRUE_VALUE);
250+
write_tape(0, internal::tape_type::TRUE_VALUE);
244251
break;
245252
case 'f':
246253
if (!atomparsing::is_valid_false_atom(structurals.current())) { return true; }
247-
doc_parser.write_tape(0, internal::tape_type::FALSE_VALUE);
254+
write_tape(0, internal::tape_type::FALSE_VALUE);
248255
break;
249256
case 'n':
250257
if (!atomparsing::is_valid_null_atom(structurals.current())) { return true; }
251-
doc_parser.write_tape(0, internal::tape_type::NULL_VALUE);
258+
write_tape(0, internal::tape_type::NULL_VALUE);
252259
break;
253260
default:
254261
return true;
@@ -260,15 +267,15 @@ struct structural_parser {
260267
switch (structurals.current_char()) {
261268
case 't':
262269
if (!atomparsing::is_valid_true_atom(structurals.current(), structurals.remaining_len())) { return true; }
263-
doc_parser.write_tape(0, internal::tape_type::TRUE_VALUE);
270+
write_tape(0, internal::tape_type::TRUE_VALUE);
264271
break;
265272
case 'f':
266273
if (!atomparsing::is_valid_false_atom(structurals.current(), structurals.remaining_len())) { return true; }
267-
doc_parser.write_tape(0, internal::tape_type::FALSE_VALUE);
274+
write_tape(0, internal::tape_type::FALSE_VALUE);
268275
break;
269276
case 'n':
270277
if (!atomparsing::is_valid_null_atom(structurals.current(), structurals.remaining_len())) { return true; }
271-
doc_parser.write_tape(0, internal::tape_type::NULL_VALUE);
278+
write_tape(0, internal::tape_type::NULL_VALUE);
272279
break;
273280
default:
274281
return true;

src/stage2_build_tape.cpp

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22
#include <cassert>
33
#include <cstring>
44
#include "jsoncharutils.h"
5-
#include "document_parser_callbacks.h"
65

76
using namespace simdjson;
87

0 commit comments

Comments
 (0)