Skip to content

Commit d05b03f

Browse files
committed
fix: fix string parsing (mostly, thanks to @Licenser)
1 parent 81b9fa5 commit d05b03f

File tree

2 files changed

+10
-16
lines changed

2 files changed

+10
-16
lines changed

src/lib.rs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -181,7 +181,10 @@ impl<'de> Deserializer<'de> {
181181

182182
let counts = Deserializer::validate(input, &structural_indexes)?;
183183

184-
let strings = Vec::with_capacity(len + SIMDJSON_PADDING);
184+
let mut strings = Vec::with_capacity(len + SIMDJSON_PADDING);
185+
unsafe {
186+
strings.set_len(len + SIMDJSON_PADDING);
187+
}
185188

186189
Ok(Deserializer {
187190
counts,

src/neon/deser.rs

Lines changed: 6 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -9,24 +9,13 @@ pub use crate::neon::utf8check::*;
99
pub use crate::stringparse::*;
1010

1111
pub use crate::neon::intrinsics::*;
12-
use std::io::Write;
1312

14-
unsafe fn find_bs_bits_and_quote_bits(src: &[u8], dstx: Option<&mut [u8]>) -> ParseStringHelper {
13+
unsafe fn find_bs_bits_and_quote_bits(src: &[u8]) -> ParseStringHelper {
1514
// this can read up to 31 bytes beyond the buffer size, but we require
1615
// SIMDJSON_PADDING of padding
1716
let v0 : uint8x16_t = vld1q_u8(src.as_ptr());
1817
let v1 : uint8x16_t = vld1q_u8(src.as_ptr().add(16));
1918

20-
match dstx {
21-
Some(mut dst) => {
22-
// vst1q_u8(dst.as_mut_ptr(), v0);
23-
// vst1q_u8(dst.as_mut_ptr().add(16), v1);
24-
dst.write(&src[0..16]).unwrap();
25-
dst.write(&src[16..32]).unwrap();
26-
},
27-
_ => ()
28-
}
29-
3019
let bs_mask : uint8x16_t = vmovq_n_u8('\\' as u8);
3120
let qt_mask : uint8x16_t = vmovq_n_u8('"' as u8);
3221

@@ -84,7 +73,7 @@ impl<'de> Deserializer<'de> {
8473
}
8574
};
8675

87-
let ParseStringHelper { bs_bits, quote_bits } = unsafe { find_bs_bits_and_quote_bits(&srcx, None) };
76+
let ParseStringHelper { bs_bits, quote_bits } = unsafe { find_bs_bits_and_quote_bits(&srcx) };
8877

8978
if (bs_bits.wrapping_sub(1) & quote_bits) != 0 {
9079
// we encountered quotes first. Move dst to point to quotes and exit
@@ -123,7 +112,7 @@ impl<'de> Deserializer<'de> {
123112
}
124113

125114
let mut dst_i: usize = 0;
126-
let dst: &mut [u8] = &mut self.strings;
115+
let dst: &mut [u8] = self.strings.as_mut_slice();
127116

128117
loop {
129118
let srcx = if src.len() >= src_i + 32 {
@@ -137,9 +126,11 @@ impl<'de> Deserializer<'de> {
137126
}
138127
};
139128

129+
dst[dst_i..dst_i + 32].copy_from_slice(&srcx[..32]);
130+
140131
// store to dest unconditionally - we can overwrite the bits we don't like
141132
// later
142-
let ParseStringHelper { bs_bits, quote_bits } = unsafe { find_bs_bits_and_quote_bits(&srcx, Some(dst)) };
133+
let ParseStringHelper { bs_bits, quote_bits } = unsafe { find_bs_bits_and_quote_bits(&srcx) };
143134

144135
if (bs_bits.wrapping_sub(1) & quote_bits) != 0 {
145136
// we encountered quotes first. Move dst to point to quotes and exit

0 commit comments

Comments
 (0)