MCPcopy Create free account
hub / github.com/bytedance/sonic-cpp / SkipString

Function SkipString

include/sonic/internal/arch/common/arm_common/skip.inc.h:77–122  ·  view source on GitHub ↗

pos is the after the ending quote

Source from the content-addressed store, hash-verified

75
76// pos is the after the ending quote
77sonic_force_inline int SkipString(const uint8_t *data, size_t &pos,
78 size_t len) {
79 const static int kEscaped = 2;
80 const static int kNormal = 1;
81 const static int kUnclosed = 0;
82 uint64_t quote_bits = 0;
83 uint64_t bs_bits = 0;
84 int ret = kNormal;
85 while (pos + VEC_LEN <= len) {
86 // const simd::simd256<uint8_t> v(data + pos);
87 uint8x16_t v = vld1q_u8(data + pos);
88 bs_bits = to_bitmask(vceqq_u8(v, vdupq_n_u8('\\')));
89 quote_bits = to_bitmask(vceqq_u8(v, vdupq_n_u8('"')));
90 if (((bs_bits - 1) & quote_bits) != 0) {
91 pos += (TrailingZeroes(quote_bits) >> 2) + 1;
92 return ret;
93 }
94 if (bs_bits) {
95 ret = kEscaped;
96 pos += ((TrailingZeroes(bs_bits) >> 2) + 2);
97 while (pos < len) {
98 if (data[pos] == '\\') {
99 pos += 2;
100 } else {
101 break;
102 }
103 }
104 } else {
105 pos += VEC_LEN;
106 }
107 }
108 while (pos < len) {
109 if (data[pos] == '\\') {
110 if (pos + 1 >= len) {
111 return kUnclosed;
112 }
113 ret = kEscaped;
114 pos += 2;
115 continue;
116 }
117 if (data[pos++] == '"') {
118 return ret;
119 }
120 };
121 return kUnclosed;
122}
123
124// return true if container is closed.
125template <typename T>

Callers

nothing calls this directly

Calls 2

to_bitmaskFunction · 0.85
TrailingZeroesFunction · 0.70

Tested by

no test coverage detected