Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 5 additions & 5 deletions src/impls/avx2/deser.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ use arch::{
};

use crate::{
Deserializer, Result, SillyWrapper,
Deserializer, InputView, Result, SillyWrapper,
error::ErrorType,
macros::static_cast_u32,
safer_unchecked::GetSaferUnchecked,
Expand All @@ -24,10 +24,10 @@ use crate::{
clippy::too_many_lines
)]
#[cfg_attr(not(feature = "no-inline"), inline)]
pub(crate) unsafe fn parse_str<'invoke, 'de>(
pub(crate) unsafe fn parse_str<'de>(
input: SillyWrapper<'de>,
data: &'invoke [u8],
buffer: &'invoke mut [u8],
data: InputView,
buffer: &mut [u8],
mut idx: usize,
) -> Result<&'de str> {
unsafe {
Expand All @@ -42,7 +42,7 @@ pub(crate) unsafe fn parse_str<'invoke, 'de>(
// This is safe since we check sub's length in the range access above and only
// create sub sliced form sub to `sub.len()`.

let src: &[u8] = data.get_kinda_unchecked(idx..);
let src: &[u8] = data.tail(idx);
let mut src_i: usize = 0;
let mut len = src_i;
loop {
Expand Down
36 changes: 22 additions & 14 deletions src/impls/native/deser.rs
Original file line number Diff line number Diff line change
@@ -1,30 +1,33 @@
use crate::{
Deserializer, ErrorType, Result, SillyWrapper,
Deserializer, ErrorType, InputView, Result, SillyWrapper,
safer_unchecked::GetSaferUnchecked,
stringparse::{ESCAPE_MAP, get_unicode_codepoint},
};

// `data` may alias the buffer written through `input` (the padded path), so reads
// interleaved with the escape writes below go through the raw pointer; the only
// slices materialized are transient and dead before the writes that follow them.
#[allow(clippy::cast_possible_truncation)]
pub(crate) unsafe fn parse_str<'invoke, 'de>(
pub(crate) unsafe fn parse_str<'de>(
input: SillyWrapper<'de>,
data: &'invoke [u8],
_buffer: &'invoke mut [u8],
data: InputView,
_buffer: &mut [u8],
idx: usize,
) -> Result<&'de str> {
use ErrorType::{InvalidEscape, InvalidUnicodeCodepoint};

let input = input.input;
// skip leading `"`
let src: &[u8] = unsafe { data.get_kinda_unchecked(idx + 1..) };
let src: *const u8 = unsafe { data.ptr.add(idx + 1) };
let input = unsafe { input.add(idx + 1) };

let mut src_i = 0;
let mut b = unsafe { *src.get_kinda_unchecked(src_i) };
let mut b = unsafe { src.add(src_i).read() };

// quickly skip all the "good stuff"
while b != b'"' && b != b'\\' {
src_i += 1;
b = unsafe { *src.get_kinda_unchecked(src_i) };
b = unsafe { src.add(src_i).read() };
}
if b == b'"' {
let v = unsafe { std::str::from_utf8_unchecked(std::slice::from_raw_parts(input, src_i)) };
Expand All @@ -37,13 +40,13 @@ pub(crate) unsafe fn parse_str<'invoke, 'de>(
while b != b'"' {
if b == b'\\' {
// don't advance i yet
let escape_char = unsafe { *src.get_kinda_unchecked(src_i + 1) };
let escape_char = unsafe { src.add(src_i + 1).read() };
if escape_char == b'u' {
// got to reduce by 1 since we have to include the '\\' for get_unicode_codepoint
let (cp, src_offset) =
unsafe { get_unicode_codepoint(src.get_kinda_unchecked(src_i..)) }.map_err(
|_| Deserializer::error_c(idx + 1 + src_i, 'u', InvalidUnicodeCodepoint),
)?;
let (cp, src_offset) = unsafe { get_unicode_codepoint(data.tail(idx + 1 + src_i)) }
.map_err(|_| {
Deserializer::error_c(idx + 1 + src_i, 'u', InvalidUnicodeCodepoint)
})?;

// from codepoint_to_utf8 since we write directly to input
unsafe {
Expand Down Expand Up @@ -101,7 +104,7 @@ pub(crate) unsafe fn parse_str<'invoke, 'de>(
dst_i += 1;
}
src_i += 1;
b = unsafe { *src.get_kinda_unchecked(src_i) };
b = unsafe { src.add(src_i).read() };
}
unsafe {
Ok(std::str::from_utf8_unchecked(std::slice::from_raw_parts(
Expand All @@ -121,7 +124,12 @@ mod test {
let mut buffer = vec![0; 1024];

let r = unsafe {
super::parse_str(input.as_mut_ptr().into(), &input2, buffer.as_mut_slice(), 0)?
super::parse_str(
input.as_mut_ptr().into(),
crate::InputView::from_slice(&input2),
buffer.as_mut_slice(),
0,
)?
};
Ok(String::from(r))
}
Expand Down
9 changes: 5 additions & 4 deletions src/impls/neon/deser.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
use crate::Deserializer;
use crate::InputView;
use crate::Result;
use crate::SillyWrapper;
use crate::error::ErrorType;
Expand Down Expand Up @@ -42,10 +43,10 @@ fn find_bs_bits_and_quote_bits(v0: uint8x16_t, v1: uint8x16_t) -> (u32, u32) {

#[allow(clippy::if_not_else, clippy::too_many_lines)]
#[cfg_attr(not(feature = "no-inline"), inline)]
pub(crate) fn parse_str<'invoke, 'de>(
pub(crate) fn parse_str<'de>(
input: SillyWrapper<'de>,
data: &'invoke [u8],
buffer: &'invoke mut [u8],
data: InputView,
buffer: &mut [u8],
mut idx: usize,
) -> Result<&'de str> {
use ErrorType::{InvalidEscape, InvalidUnicodeCodepoint};
Expand All @@ -59,7 +60,7 @@ pub(crate) fn parse_str<'invoke, 'de>(
// This is safe since we check sub's length in the range access above and only
// create sub sliced form sub to `sub.len()`.

let src: &[u8] = unsafe { data.get_kinda_unchecked(idx..) };
let src: &[u8] = unsafe { data.tail(idx) };
let mut src_i: usize = 0;
let mut len = src_i;
loop {
Expand Down
10 changes: 5 additions & 5 deletions src/impls/portable/deser.rs
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
use std::simd::{SimdPartialEq, ToBitMask, u8x32};

use crate::{
Deserializer, ErrorType, Result, SillyWrapper,
Deserializer, ErrorType, InputView, Result, SillyWrapper,
safer_unchecked::GetSaferUnchecked,
stringparse::{ESCAPE_MAP, handle_unicode_codepoint},
};

#[cfg_attr(not(feature = "no-inline"), inline)]
pub(crate) unsafe fn parse_str<'invoke, 'de>(
pub(crate) unsafe fn parse_str<'de>(
input: SillyWrapper<'de>,
data: &'invoke [u8],
buffer: &'invoke mut [u8],
data: InputView,
buffer: &mut [u8],
mut idx: usize,
) -> Result<&'de str> {
let input = input.input;
Expand All @@ -26,7 +26,7 @@ pub(crate) unsafe fn parse_str<'invoke, 'de>(
// This is safe since we check sub's length in the range access above and only
// create sub sliced form sub to `sub.len()`.

let src: &[u8] = data.get_kinda_unchecked(idx..);
let src: &[u8] = data.tail(idx);
let mut src_i: usize = 0;
let mut len = src_i;
loop {
Expand Down
10 changes: 5 additions & 5 deletions src/impls/simd128/deser.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use std::arch::wasm32::{u8x16_bitmask, u8x16_eq, u8x16_splat, v128, v128_load, v128_store};

use crate::{
Deserializer, Result, SillyWrapper,
Deserializer, InputView, Result, SillyWrapper,
error::ErrorType,
safer_unchecked::GetSaferUnchecked,
stringparse::{ESCAPE_MAP, handle_unicode_codepoint},
Expand All @@ -14,10 +14,10 @@ use crate::{
clippy::too_many_lines
)]
#[cfg_attr(not(feature = "no-inline"), inline)]
pub(crate) fn parse_str<'invoke, 'de>(
pub(crate) fn parse_str<'de>(
input: SillyWrapper<'de>,
data: &'invoke [u8],
buffer: &'invoke mut [u8],
data: InputView,
buffer: &mut [u8],
mut idx: usize,
) -> Result<&'de str> {
use ErrorType::{InvalidEscape, InvalidUnicodeCodepoint};
Expand All @@ -29,7 +29,7 @@ pub(crate) fn parse_str<'invoke, 'de>(
// This is safe since we check sub's length in the range access above and only
// create sub sliced form sub to `sub.len()`.

let src = unsafe { data.get_kinda_unchecked(idx..) };
let src = unsafe { data.tail(idx) };
let mut src_i = 0;
let mut len = src_i;
loop {
Expand Down
10 changes: 5 additions & 5 deletions src/impls/sse42/deser.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ use std::arch::x86 as arch;
use std::arch::x86_64 as arch;

use crate::{
Deserializer, Result, SillyWrapper,
Deserializer, InputView, Result, SillyWrapper,
error::ErrorType,
safer_unchecked::GetSaferUnchecked,
stringparse::{ESCAPE_MAP, handle_unicode_codepoint},
Expand All @@ -17,10 +17,10 @@ use arch::{
#[target_feature(enable = "sse4.2")]
#[allow(clippy::if_not_else, clippy::cast_possible_wrap)]
#[cfg_attr(not(feature = "no-inline"), inline)]
pub(crate) unsafe fn parse_str<'invoke, 'de>(
pub(crate) unsafe fn parse_str<'de>(
input: SillyWrapper<'de>,
data: &'invoke [u8],
buffer: &'invoke mut [u8],
data: InputView,
buffer: &mut [u8],
mut idx: usize,
) -> Result<&'de str> {
unsafe {
Expand All @@ -33,7 +33,7 @@ pub(crate) unsafe fn parse_str<'invoke, 'de>(
// This is safe since we check sub's length in the range access above and only
// create sub sliced form sub to `sub.len()`.

let src: &[u8] = data.get_kinda_unchecked(idx..);
let src: &[u8] = data.tail(idx);
let mut src_i: usize = 0;
let mut len = src_i;
loop {
Expand Down
Loading