@@ -117,20 +117,23 @@ struct number_writer {
117
117
parser &doc_parser;
118
118
119
119
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);
121
121
std::memcpy (&doc_parser.doc .tape [doc_parser.current_loc ], &value, sizeof (value));
122
122
++doc_parser.current_loc ;
123
123
}
124
124
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);
126
126
doc_parser.doc .tape [doc_parser.current_loc ++] = value;
127
127
}
128
128
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);
130
130
static_assert (sizeof (value) == sizeof (doc_parser.doc .tape [doc_parser.current_loc ]), " mismatch size" );
131
131
memcpy (&doc_parser.doc .tape [doc_parser.current_loc ++], &value, sizeof (double ));
132
132
// doc.tape[doc.current_loc++] = *((uint64_t *)&d);
133
133
}
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
+ }
134
137
}; // struct number_writer
135
138
136
139
struct structural_parser {
@@ -148,7 +151,7 @@ struct structural_parser {
148
151
WARN_UNUSED really_inline bool start_scope (internal::tape_type type, ret_address continue_state) {
149
152
doc_parser.containing_scope [depth].tape_index = doc_parser.current_loc ;
150
153
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
152
155
doc_parser.ret_address [depth] = continue_state;
153
156
depth++;
154
157
return depth >= doc_parser.max_depth ();
@@ -171,7 +174,7 @@ struct structural_parser {
171
174
depth--;
172
175
// write our doc.tape location to the header scope
173
176
// 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);
175
178
// count can overflow if it exceeds 24 bits... so we saturate
176
179
// the convention being that a cnt of 0xffffff or more is undetermined in value (>= 0xffffff).
177
180
const uint32_t start_tape_index = doc_parser.containing_scope [depth].tape_index ;
@@ -191,18 +194,22 @@ struct structural_parser {
191
194
end_scope (internal::tape_type::ROOT);
192
195
}
193
196
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.
198
205
really_inline void increment_count () {
199
206
doc_parser.containing_scope [depth - 1 ].count ++; // we have a key value pair in the object at parser.depth - 1
200
207
}
201
208
202
209
really_inline uint8_t *on_start_string () noexcept {
203
210
/* we advance the point, accounting for the fact that we have a NULL
204
211
* 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);
206
213
return doc_parser.current_string_buf_loc + sizeof (uint32_t );
207
214
}
208
215
@@ -240,15 +247,15 @@ struct structural_parser {
240
247
switch (structurals.current_char ()) {
241
248
case ' t' :
242
249
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);
244
251
break ;
245
252
case ' f' :
246
253
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);
248
255
break ;
249
256
case ' n' :
250
257
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);
252
259
break ;
253
260
default :
254
261
return true ;
@@ -260,15 +267,15 @@ struct structural_parser {
260
267
switch (structurals.current_char ()) {
261
268
case ' t' :
262
269
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);
264
271
break ;
265
272
case ' f' :
266
273
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);
268
275
break ;
269
276
case ' n' :
270
277
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);
272
279
break ;
273
280
default :
274
281
return true ;
0 commit comments