Skip to content

Commit 5525c6f

Browse files
committed
Stop using jsoncharutils.h in JsonStream
1 parent eb147d9 commit 5525c6f

File tree

5 files changed

+21
-21
lines changed

5 files changed

+21
-21
lines changed

include/simdjson/jsonstream.h

Lines changed: 19 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@
77
#include <thread>
88
#include "simdjson/padded_string.h"
99
#include "simdjson/simdjson.h"
10-
#include "jsoncharutils.h"
1110

1211

1312
namespace simdjson {
@@ -233,6 +232,22 @@ template <class string_container> JsonStream<string_container>::~JsonStream() {
233232
#endif
234233
}
235234

235+
namespace internal {
236+
// returns true if the provided byte value is an ASCII character
237+
static inline bool is_ascii(char c) {
238+
return ((unsigned char)c) <= 127;
239+
}
240+
241+
// if the string ends with UTF-8 values, backtrack
242+
// up to the first ASCII character. May return 0.
243+
static inline size_t trimmed_length_safe_utf8(const char * c, size_t len) {
244+
while ((len > 0) and (not is_ascii(c[len - 1]))) {
245+
len--;
246+
}
247+
return len;
248+
}
249+
}
250+
236251
#ifdef SIMDJSON_THREADS_ENABLED
237252

238253
// threaded version of json_parse
@@ -257,7 +272,7 @@ int JsonStream<string_container>::json_parse(document::parser &parser) {
257272
// First time loading
258273
if (!stage_1_thread.joinable()) {
259274
_batch_size = (std::min)(_batch_size, remaining());
260-
_batch_size = trimmed_length_safe_utf8((const char *)buf(), _batch_size);
275+
_batch_size = internal::trimmed_length_safe_utf8((const char *)buf(), _batch_size);
261276
if (_batch_size == 0) {
262277
return parser.error = simdjson::UTF8_ERROR;
263278
}
@@ -291,7 +306,7 @@ int JsonStream<string_container>::json_parse(document::parser &parser) {
291306
parser.structural_indexes[find_last_json_buf_idx(buf(), _batch_size, parser)];
292307
_batch_size = (std::min)(_batch_size, remaining() - last_json_buffer_loc);
293308
if (_batch_size > 0) {
294-
_batch_size = trimmed_length_safe_utf8(
309+
_batch_size = internal::trimmed_length_safe_utf8(
295310
(const char *)(buf() + last_json_buffer_loc), _batch_size);
296311
if (_batch_size == 0) {
297312
return parser.error = simdjson::UTF8_ERROR;
@@ -343,7 +358,7 @@ int JsonStream<string_container>::json_parse(document::parser &parser) {
343358
advance(current_buffer_loc);
344359
n_bytes_parsed += current_buffer_loc;
345360
_batch_size = (std::min)(_batch_size, remaining());
346-
_batch_size = trimmed_length_safe_utf8((const char *)buf(), _batch_size);
361+
_batch_size = internal::trimmed_length_safe_utf8((const char *)buf(), _batch_size);
347362
auto stage1_is_ok = (error_code)simdjson::active_implementation->stage1(buf(), _batch_size, parser, true);
348363
if (stage1_is_ok != simdjson::SUCCESS) {
349364
return parser.on_error(stage1_is_ok);

src/CMakeLists.txt

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,6 @@ set(SIMDJSON_SRC_HEADERS
3030
error.cpp
3131
implementation.cpp
3232
isadetection.h
33-
jsoncharutils.h
3433
jsonioutil.cpp
3534
jsonminifier.cpp
3635
simdprune_tables.h

src/error.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ namespace simdjson {
66
const std::map<int, const std::string> error_strings = {
77
{SUCCESS, "No error"},
88
{SUCCESS_AND_HAS_MORE, "No error and buffer still has more data"},
9-
{CAPACITY, "This ParsedJson can't support a document that big"},
9+
{CAPACITY, "This parser can't support a document that big"},
1010
{MEMALLOC, "Error allocating memory, we're most likely out of memory"},
1111
{TAPE_ERROR, "Something went wrong while writing to the tape"},
1212
{STRING_ERROR, "Problem while parsing a string"},

src/generic/stage2_streaming_build_tape.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
namespace stage2 {
22

33
struct streaming_structural_parser: structural_parser {
4-
really_inline streaming_structural_parser(const uint8_t *_buf, size_t _len, ParsedJson &_doc_parser, size_t _i) : structural_parser(_buf, _len, _doc_parser, _i) {}
4+
really_inline streaming_structural_parser(const uint8_t *_buf, size_t _len, document::parser &_doc_parser, size_t _i) : structural_parser(_buf, _len, _doc_parser, _i) {}
55

66
// override to add streaming
77
WARN_UNUSED really_inline error_code start(ret_address finish_parser) {

src/jsoncharutils.h

Lines changed: 0 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22
#define SIMDJSON_JSONCHARUTILS_H
33

44
#include "simdjson/common_defs.h"
5-
#include "simdjson/parsedjson.h"
65

76
namespace simdjson {
87
// structural chars here are
@@ -264,19 +263,6 @@ static inline bool is_utf8_continuing(char c) {
264263
// go up to 0b11111 (-1)... so we want all values from -128 to -65 (which is 0b10111111)
265264
return ((signed char)c) <= -65;
266265
}
267-
// returns true if the provided byte value is an ASCII character
268-
static inline bool is_ascii(char c) {
269-
return ((unsigned char)c) <= 127;
270-
}
271-
272-
// if the string ends with UTF-8 values, backtrack
273-
// up to the first ASCII character. May return 0.
274-
static inline size_t trimmed_length_safe_utf8(const char * c, size_t len) {
275-
while ((len > 0) and (not is_ascii(c[len - 1]))) {
276-
len--;
277-
}
278-
return len;
279-
}
280266

281267

282268

0 commit comments

Comments
 (0)