simdjson  3.1.6
Ridiculously Fast JSON
stringparsing.h
1 #ifndef SIMDJSON_HASWELL_STRINGPARSING_H
2 #define SIMDJSON_HASWELL_STRINGPARSING_H
3 
4 #include "simdjson/base.h"
5 #include "simdjson/haswell/simd.h"
6 #include "simdjson/haswell/bitmanipulation.h"
7 
8 namespace simdjson {
9 namespace SIMDJSON_IMPLEMENTATION {
10 namespace {
11 
12 using namespace simd;
13 
14 // Holds backslashes and quotes locations.
15 struct backslash_and_quote {
16 public:
17  static constexpr uint32_t BYTES_PROCESSED = 32;
18  simdjson_inline static backslash_and_quote copy_and_find(const uint8_t *src, uint8_t *dst);
19 
20  simdjson_inline bool has_quote_first() { return ((bs_bits - 1) & quote_bits) != 0; }
21  simdjson_inline bool has_backslash() { return ((quote_bits - 1) & bs_bits) != 0; }
22  simdjson_inline int quote_index() { return trailing_zeroes(quote_bits); }
23  simdjson_inline int backslash_index() { return trailing_zeroes(bs_bits); }
24 
25  uint32_t bs_bits;
26  uint32_t quote_bits;
27 }; // struct backslash_and_quote
28 
29 simdjson_inline backslash_and_quote backslash_and_quote::copy_and_find(const uint8_t *src, uint8_t *dst) {
30  // this can read up to 15 bytes beyond the buffer size, but we require
31  // SIMDJSON_PADDING of padding
32  static_assert(SIMDJSON_PADDING >= (BYTES_PROCESSED - 1), "backslash and quote finder must process fewer than SIMDJSON_PADDING bytes");
33  simd8<uint8_t> v(src);
34  // store to dest unconditionally - we can overwrite the bits we don't like later
35  v.store(dst);
36  return {
37  static_cast<uint32_t>((v == '\\').to_bitmask()), // bs_bits
38  static_cast<uint32_t>((v == '"').to_bitmask()), // quote_bits
39  };
40 }
41 
42 } // unnamed namespace
43 } // namespace SIMDJSON_IMPLEMENTATION
44 } // namespace simdjson
45 
46 #endif // SIMDJSON_HASWELL_STRINGPARSING_H
We want to support argument-dependent lookup (ADL).
constexpr size_t SIMDJSON_PADDING
The amount of padding needed in a buffer to parse JSON.
Definition: common_defs.h:45