Skip to content

Commit 8b314a7

Browse files
authored
Merge pull request #1173 from iex-rs/fix-big-endian
Oops, fix skip_to_escape on BE architectures
2 parents 2cab07e + 8eba786 commit 8b314a7

File tree

2 files changed

+3
-8
lines changed

2 files changed

+3
-8
lines changed

src/read.rs

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -453,22 +453,17 @@ impl<'a> SliceRead<'a> {
453453
const ONE_BYTES: Chunk = Chunk::MAX / 255; // 0x0101...01
454454

455455
for chunk in rest.chunks_exact(STEP) {
456-
let chars = Chunk::from_ne_bytes(chunk.try_into().unwrap());
456+
let chars = Chunk::from_le_bytes(chunk.try_into().unwrap());
457457
let contains_ctrl = chars.wrapping_sub(ONE_BYTES * 0x20) & !chars;
458458
let chars_quote = chars ^ (ONE_BYTES * Chunk::from(b'"'));
459459
let contains_quote = chars_quote.wrapping_sub(ONE_BYTES) & !chars_quote;
460460
let chars_backslash = chars ^ (ONE_BYTES * Chunk::from(b'\\'));
461461
let contains_backslash = chars_backslash.wrapping_sub(ONE_BYTES) & !chars_backslash;
462462
let masked = (contains_ctrl | contains_quote | contains_backslash) & (ONE_BYTES << 7);
463463
if masked != 0 {
464-
let addresswise_first_bit = if cfg!(target_endian = "little") {
465-
masked.trailing_zeros()
466-
} else {
467-
masked.leading_zeros()
468-
};
469464
// SAFETY: chunk is in-bounds for slice
470465
self.index = unsafe { chunk.as_ptr().offset_from(self.slice.as_ptr()) } as usize
471-
+ addresswise_first_bit as usize / 8;
466+
+ masked.trailing_zeros() as usize / 8;
472467
return;
473468
}
474469
}

tests/test.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2504,7 +2504,7 @@ fn test_control_character_search() {
25042504
for n in 0..16 {
25052505
for m in 0..16 {
25062506
test_parse_err::<String>(&[(
2507-
&format!("\"{}\n{}\"", ".".repeat(n), ".".repeat(m)),
2507+
&format!("\"{}\n{}\"", " ".repeat(n), " ".repeat(m)),
25082508
"control character (\\u0000-\\u001F) found while parsing a string at line 2 column 0",
25092509
)]);
25102510
}

0 commit comments

Comments
 (0)