Skip to content

Commit

Permalink
Fix skip_to_escape on BE architectures
Browse files Browse the repository at this point in the history
  • Loading branch information
purplesyringa committed Aug 11, 2024
1 parent 2cab07e commit 8eba786
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 8 deletions.
9 changes: 2 additions & 7 deletions src/read.rs
Original file line number Diff line number Diff line change
Expand Up @@ -453,22 +453,17 @@ impl<'a> SliceRead<'a> {
const ONE_BYTES: Chunk = Chunk::MAX / 255; // 0x0101...01

for chunk in rest.chunks_exact(STEP) {
let chars = Chunk::from_ne_bytes(chunk.try_into().unwrap());
let chars = Chunk::from_le_bytes(chunk.try_into().unwrap());
let contains_ctrl = chars.wrapping_sub(ONE_BYTES * 0x20) & !chars;
let chars_quote = chars ^ (ONE_BYTES * Chunk::from(b'"'));
let contains_quote = chars_quote.wrapping_sub(ONE_BYTES) & !chars_quote;
let chars_backslash = chars ^ (ONE_BYTES * Chunk::from(b'\\'));
let contains_backslash = chars_backslash.wrapping_sub(ONE_BYTES) & !chars_backslash;
let masked = (contains_ctrl | contains_quote | contains_backslash) & (ONE_BYTES << 7);
if masked != 0 {
let addresswise_first_bit = if cfg!(target_endian = "little") {
masked.trailing_zeros()
} else {
masked.leading_zeros()
};
// SAFETY: chunk is in-bounds for slice
self.index = unsafe { chunk.as_ptr().offset_from(self.slice.as_ptr()) } as usize
+ addresswise_first_bit as usize / 8;
+ masked.trailing_zeros() as usize / 8;
return;
}
}
Expand Down
2 changes: 1 addition & 1 deletion tests/test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2504,7 +2504,7 @@ fn test_control_character_search() {
for n in 0..16 {
for m in 0..16 {
test_parse_err::<String>(&[(
&format!("\"{}\n{}\"", ".".repeat(n), ".".repeat(m)),
&format!("\"{}\n{}\"", " ".repeat(n), " ".repeat(m)),
"control character (\\u0000-\\u001F) found while parsing a string at line 2 column 0",
)]);
}
Expand Down

0 comments on commit 8eba786

Please sign in to comment.