simdjson  3.1.6
Ridiculously Fast JSON
stringparsing.h
1 #ifndef SIMDJSON_WESTMERE_STRINGPARSING_H
2 #define SIMDJSON_WESTMERE_STRINGPARSING_H
3 
4 namespace simdjson {
5 namespace SIMDJSON_IMPLEMENTATION {
6 namespace {
7 
8 using namespace simd;
9 
10 // Holds backslashes and quotes locations.
11 struct backslash_and_quote {
12 public:
13  static constexpr uint32_t BYTES_PROCESSED = 32;
14  simdjson_inline static backslash_and_quote copy_and_find(const uint8_t *src, uint8_t *dst);
15 
16  simdjson_inline bool has_quote_first() { return ((bs_bits - 1) & quote_bits) != 0; }
17  simdjson_inline bool has_backslash() { return bs_bits != 0; }
18  simdjson_inline int quote_index() { return trailing_zeroes(quote_bits); }
19  simdjson_inline int backslash_index() { return trailing_zeroes(bs_bits); }
20 
21  uint32_t bs_bits;
22  uint32_t quote_bits;
23 }; // struct backslash_and_quote
24 
25 simdjson_inline backslash_and_quote backslash_and_quote::copy_and_find(const uint8_t *src, uint8_t *dst) {
26  // this can read up to 31 bytes beyond the buffer size, but we require
27  // SIMDJSON_PADDING of padding
28  static_assert(SIMDJSON_PADDING >= (BYTES_PROCESSED - 1), "backslash and quote finder must process fewer than SIMDJSON_PADDING bytes");
29  simd8<uint8_t> v0(src);
30  simd8<uint8_t> v1(src + 16);
31  v0.store(dst);
32  v1.store(dst + 16);
33  uint64_t bs_and_quote = simd8x64<bool>(v0 == '\\', v1 == '\\', v0 == '"', v1 == '"').to_bitmask();
34  return {
35  uint32_t(bs_and_quote), // bs_bits
36  uint32_t(bs_and_quote >> 32) // quote_bits
37  };
38 }
39 
40 } // unnamed namespace
41 } // namespace SIMDJSON_IMPLEMENTATION
42 } // namespace simdjson
43 
44 #endif // SIMDJSON_WESTMERE_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