File tree Expand file tree Collapse file tree 3 files changed +15
-20
lines changed
Expand file tree Collapse file tree 3 files changed +15
-20
lines changed Original file line number Diff line number Diff line change @@ -1019,14 +1019,16 @@ class parser {
10191019 really_inline bool on_true_atom () noexcept ; // /< @private
10201020 really_inline bool on_false_atom () noexcept ; // /< @private
10211021 really_inline bool on_null_atom () noexcept ; // /< @private
1022- really_inline uint8_t *on_start_string () noexcept ; // /< @private
1023- really_inline bool on_end_string (uint8_t *dst) noexcept ; // /< @private
1022+ really_inline void write_string_length (uint32_t length) noexcept ; // /< @private
10241023 really_inline bool on_number_s64 (int64_t value) noexcept ; // /< @private
10251024 really_inline bool on_number_u64 (uint64_t value) noexcept ; // /< @private
10261025 really_inline bool on_number_double (double value) noexcept ; // /< @private
10271026
10281027 really_inline void increment_count (uint32_t depth) noexcept ; // /< @private
10291028 really_inline void end_scope (uint32_t depth) noexcept ; // /< @private
1029+
1030+ really_inline void write_tape (uint64_t val, internal::tape_type t) noexcept ;
1031+
10301032private:
10311033 /* *
10321034 * The maximum document length this parser will automatically support.
@@ -1071,8 +1073,6 @@ class parser {
10711073 //
10721074 //
10731075
1074- inline void write_tape (uint64_t val, internal::tape_type t) noexcept ;
1075-
10761076 /* *
10771077 * Ensure we have enough capacity to handle at least desired_capacity bytes,
10781078 * and auto-allocate if not.
Original file line number Diff line number Diff line change @@ -86,24 +86,11 @@ really_inline bool parser::on_null_atom() noexcept {
8686 return true ;
8787}
8888
89- really_inline uint8_t *parser::on_start_string () noexcept {
90- /* we advance the point, accounting for the fact that we have a NULL
91- * termination */
92- write_tape (current_string_buf_loc - doc.string_buf .get (), internal::tape_type::STRING);
93- return current_string_buf_loc + sizeof (uint32_t );
94- }
95-
96- really_inline bool parser::on_end_string (uint8_t *dst) noexcept {
97- uint32_t str_length = uint32_t (dst - (current_string_buf_loc + sizeof (uint32_t )));
89+ really_inline void parser::write_string_length (uint32_t str_length) noexcept {
9890 // TODO check for overflow in case someone has a crazy string (>=4GB?)
9991 // But only add the overflow check when the document itself exceeds 4GB
10092 // Currently unneeded because we refuse to parse docs larger or equal to 4GB.
10193 memcpy (current_string_buf_loc, &str_length, sizeof (uint32_t ));
102- // NULL termination is still handy if you expect all your strings to
103- // be NULL terminated? It comes at a small cost
104- *dst = 0 ;
105- current_string_buf_loc = dst + 1 ;
106- return true ;
10794}
10895
10996really_inline bool parser::on_number_s64 (int64_t value) noexcept {
Original file line number Diff line number Diff line change @@ -163,12 +163,20 @@ struct structural_parser {
163163 }
164164
165165 WARN_UNUSED really_inline bool parse_string () {
166- uint8_t *dst = doc_parser.on_start_string ();
166+ /* we advance the point, accounting for the fact that we have a NULL
167+ * termination */
168+ doc_parser.write_tape (doc_parser.current_string_buf_loc - doc_parser.doc .string_buf .get (), internal::tape_type::STRING);
169+ uint8_t *dst = doc_parser.current_string_buf_loc + sizeof (uint32_t );
167170 dst = stringparsing::parse_string (structurals.current (), dst);
168171 if (dst == nullptr ) {
169172 return true ;
170173 }
171- return !doc_parser.on_end_string (dst);
174+ uint32_t str_length = uint32_t (dst - (doc_parser.current_string_buf_loc + sizeof (uint32_t )));
175+ // doc_parser.write_string_length(str_length);
176+ memcpy (doc_parser.current_string_buf_loc , &str_length, sizeof (uint32_t ));
177+ *dst = 0 ;
178+ doc_parser.current_string_buf_loc = dst + 1 ;
179+ return false ;
172180 }
173181
174182 WARN_UNUSED really_inline bool parse_number (const uint8_t *src, bool found_minus) {
You can’t perform that action at this time.
0 commit comments