From 064cabc23e3d99a38b47e971531e4dca539a5071 Mon Sep 17 00:00:00 2001 From: Frank Steffahn Date: Thu, 28 Dec 2023 01:13:17 +0100 Subject: [PATCH 1/6] Remove redundant trait parameter --- src/lib.rs | 14 +++++------ src/linker/fb_32.rs | 24 +++++++++---------- src/linker/fb_64.rs | 18 +++++++------- src/linker/mod.rs | 56 +++++++++++++++++++++---------------------- src/linker/simd_32.rs | 24 +++++++++---------- src/linker/simd_64.rs | 18 +++++++------- src/test.rs | 4 ++-- 7 files changed, 79 insertions(+), 79 deletions(-) diff --git a/src/lib.rs b/src/lib.rs index c6ceade..118bcb7 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -72,26 +72,26 @@ use crate::linker::{Parser, ParserNeg, ParserPos}; /// Parses slice of digits, and checks first '-' char for signed integers. #[inline] -pub fn parse + ParserPos>(s: &[u8]) -> Result { +pub fn parse(s: &[u8]) -> Result { T::atoi_simd_parse(s) } /// Parses positive integer. #[inline] -pub fn parse_pos>(s: &[u8]) -> Result { +pub fn parse_pos(s: &[u8]) -> Result { T::atoi_simd_parse_pos(s) } /// Parses negative integer. Slice must not contain '-' sign. #[inline] -pub fn parse_neg>(s: &[u8]) -> Result { +pub fn parse_neg(s: &[u8]) -> Result { T::atoi_simd_parse_neg(s) } /// Parses slice of digits until it reaches invalid character, and checks first '-' char for signed integers. /// Returns parsed value and parsed size of the slice. #[inline] -pub fn parse_until_invalid + ParserPos>( +pub fn parse_until_invalid( s: &[u8], ) -> Result<(T, usize), AtoiSimdError> { T::atoi_simd_parse_until_invalid(s) @@ -100,14 +100,14 @@ pub fn parse_until_invalid + ParserPos>( /// Parses positive integer until it reaches invalid character. /// Returns parsed value and parsed size of the slice. #[inline] -pub fn parse_until_invalid_pos>(s: &[u8]) -> Result<(T, usize), AtoiSimdError> { +pub fn parse_until_invalid_pos(s: &[u8]) -> Result<(T, usize), AtoiSimdError> { T::atoi_simd_parse_until_invalid_pos(s) } /// Parses negative integer until it reaches invalid character. Slice must not contain '-' sign. /// Returns parsed value and parsed size of the slice. #[inline] -pub fn parse_until_invalid_neg>(s: &[u8]) -> Result<(T, usize), AtoiSimdError> { +pub fn parse_until_invalid_neg(s: &[u8]) -> Result<(T, usize), AtoiSimdError> { T::atoi_simd_parse_until_invalid_neg(s) } @@ -116,6 +116,6 @@ pub fn parse_until_invalid_neg>(s: &[u8]) -> Result<(T, usize), /// Skips '+' char and extra zeroes at the beginning. /// It's slower than `parse()`. #[inline] -pub fn parse_skipped + ParserPos>(s: &[u8]) -> Result { +pub fn parse_skipped(s: &[u8]) -> Result { T::atoi_simd_parse_skipped(s) } diff --git a/src/linker/fb_32.rs b/src/linker/fb_32.rs index efee603..75d7097 100644 --- a/src/linker/fb_32.rs +++ b/src/linker/fb_32.rs @@ -1,7 +1,7 @@ use super::*; use crate::fallback::*; -impl ParserPos for u8 { +impl ParserPos for u8 { #[inline(always)] fn atoi_simd_parse_pos(s: &[u8]) -> Result { parse_fb_checked_pos::<{ u8::MAX as u64 }>(s).map(|v| v as u8) @@ -13,7 +13,7 @@ impl ParserPos for u8 { } } -impl ParserPos for i8 { +impl ParserPos for i8 { #[inline(always)] fn atoi_simd_parse_pos(s: &[u8]) -> Result { parse_fb_checked_pos::<{ i8::MAX as u64 }>(s).map(|v| v as i8) @@ -25,7 +25,7 @@ impl ParserPos for i8 { } } -impl ParserNeg for i8 { +impl ParserNeg for i8 { #[inline(always)] fn atoi_simd_parse_neg(s: &[u8]) -> Result { parse_fb_checked_neg::<{ i8::MIN as i64 }>(s).map(|v| v as i8) @@ -37,7 +37,7 @@ impl ParserNeg for i8 { } } -impl ParserPos for u16 { +impl ParserPos for u16 { #[inline(always)] fn atoi_simd_parse_pos(s: &[u8]) -> Result { parse_fb_checked_pos::<{ u16::MAX as u64 }>(s).map(|v| v as u16) @@ -49,7 +49,7 @@ impl ParserPos for u16 { } } -impl ParserPos for i16 { +impl ParserPos for i16 { #[inline(always)] fn atoi_simd_parse_pos(s: &[u8]) -> Result { parse_fb_checked_pos::<{ i16::MAX as u64 }>(s).map(|v| v as i16) @@ -61,7 +61,7 @@ impl ParserPos for i16 { } } -impl ParserNeg for i16 { +impl ParserNeg for i16 { #[inline(always)] fn atoi_simd_parse_neg(s: &[u8]) -> Result { parse_fb_checked_neg::<{ i16::MIN as i64 }>(s).map(|v| v as i16) @@ -73,7 +73,7 @@ impl ParserNeg for i16 { } } -impl ParserPos for u32 { +impl ParserPos for u32 { #[inline(always)] fn atoi_simd_parse_pos(s: &[u8]) -> Result { parse_fb_checked_pos::<{ u32::MAX as u64 }>(s).map(|v| v as u32) @@ -85,7 +85,7 @@ impl ParserPos for u32 { } } -impl ParserPos for i32 { +impl ParserPos for i32 { #[inline(always)] fn atoi_simd_parse_pos(s: &[u8]) -> Result { parse_fb_checked_pos::<{ i32::MAX as u64 }>(s).map(|v| v as i32) @@ -97,7 +97,7 @@ impl ParserPos for i32 { } } -impl ParserNeg for i32 { +impl ParserNeg for i32 { #[inline(always)] fn atoi_simd_parse_neg(s: &[u8]) -> Result { parse_fb_checked_neg::<{ i32::MIN as i64 }>(s).map(|v| v as i32) @@ -110,7 +110,7 @@ impl ParserNeg for i32 { } #[cfg(target_pointer_width = "32")] -impl ParserPos for usize { +impl ParserPos for usize { #[inline(always)] fn atoi_simd_parse_pos(s: &[u8]) -> Result { parse_fb_checked_pos::<{ u32::MAX as u64 }>(s).map(|v| v as usize) @@ -123,7 +123,7 @@ impl ParserPos for usize { } #[cfg(target_pointer_width = "32")] -impl ParserPos for isize { +impl ParserPos for isize { #[inline(always)] fn atoi_simd_parse_pos(s: &[u8]) -> Result { parse_fb_checked_pos::<{ i32::MAX as u64 }>(s).map(|v| v as isize) @@ -136,7 +136,7 @@ impl ParserPos for isize { } #[cfg(target_pointer_width = "32")] -impl ParserNeg for isize { +impl ParserNeg for isize { #[inline(always)] fn atoi_simd_parse_neg(s: &[u8]) -> Result { parse_fb_checked_neg::<{ i32::MIN as i64 }>(s).map(|v| v as isize) diff --git a/src/linker/fb_64.rs b/src/linker/fb_64.rs index 17d6b99..f2a4b9e 100644 --- a/src/linker/fb_64.rs +++ b/src/linker/fb_64.rs @@ -2,7 +2,7 @@ use super::*; use crate::fallback::*; #[cfg(target_pointer_width = "64")] -impl ParserPos for usize { +impl ParserPos for usize { #[inline(always)] fn atoi_simd_parse_pos(s: &[u8]) -> Result { parse_fb_checked_64_pos::<{ u64::MAX }, 4>(s).map(|v| v as usize) @@ -15,7 +15,7 @@ impl ParserPos for usize { } #[cfg(target_pointer_width = "64")] -impl ParserPos for isize { +impl ParserPos for isize { #[inline(always)] fn atoi_simd_parse_pos(s: &[u8]) -> Result { parse_fb_checked_64_pos::<{ i64::MAX as u64 }, 3>(s).map(|v| v as isize) @@ -28,7 +28,7 @@ impl ParserPos for isize { } #[cfg(target_pointer_width = "64")] -impl ParserNeg for isize { +impl ParserNeg for isize { #[inline(always)] fn atoi_simd_parse_neg(s: &[u8]) -> Result { parse_fb_checked_64_neg(s).map(|v| v as isize) @@ -40,7 +40,7 @@ impl ParserNeg for isize { } } -impl ParserPos for u64 { +impl ParserPos for u64 { #[inline(always)] fn atoi_simd_parse_pos(s: &[u8]) -> Result { parse_fb_checked_64_pos::<{ u64::MAX }, 4>(s) @@ -52,7 +52,7 @@ impl ParserPos for u64 { } } -impl ParserPos for i64 { +impl ParserPos for i64 { #[inline(always)] fn atoi_simd_parse_pos(s: &[u8]) -> Result { parse_fb_checked_64_pos::<{ i64::MAX as u64 }, 3>(s).map(|v| v as i64) @@ -64,7 +64,7 @@ impl ParserPos for i64 { } } -impl ParserNeg for i64 { +impl ParserNeg for i64 { #[inline(always)] fn atoi_simd_parse_neg(s: &[u8]) -> Result { parse_fb_checked_64_neg(s) @@ -76,7 +76,7 @@ impl ParserNeg for i64 { } } -impl ParserPos for u128 { +impl ParserPos for u128 { #[inline(always)] fn atoi_simd_parse_pos(s: &[u8]) -> Result { parse_fb_checked_128_pos::<{ u128::MAX }>(s) @@ -88,7 +88,7 @@ impl ParserPos for u128 { } } -impl ParserPos for i128 { +impl ParserPos for i128 { #[inline(always)] fn atoi_simd_parse_pos(s: &[u8]) -> Result { parse_fb_checked_128_pos::<{ i128::MAX as u128 }>(s).map(|v| v as i128) @@ -100,7 +100,7 @@ impl ParserPos for i128 { } } -impl ParserNeg for i128 { +impl ParserNeg for i128 { #[inline(always)] fn atoi_simd_parse_neg(s: &[u8]) -> Result { parse_fb_checked_128_neg(s) diff --git a/src/linker/mod.rs b/src/linker/mod.rs index 0483836..d86db0d 100644 --- a/src/linker/mod.rs +++ b/src/linker/mod.rs @@ -46,29 +46,29 @@ mod fb_64; use crate::{safe_unchecked::SliceGetter, AtoiSimdError}; -pub trait ParserPos: Sized { - fn atoi_simd_parse_pos(s: &[u8]) -> Result; - fn atoi_simd_parse_until_invalid_pos(s: &[u8]) -> Result<(T, usize), AtoiSimdError>; +pub trait ParserPos: Sized { + fn atoi_simd_parse_pos(s: &[u8]) -> Result; + fn atoi_simd_parse_until_invalid_pos(s: &[u8]) -> Result<(Self, usize), AtoiSimdError>; } -pub trait ParserNeg: Sized { - fn atoi_simd_parse_neg(s: &[u8]) -> Result; - fn atoi_simd_parse_until_invalid_neg(s: &[u8]) -> Result<(T, usize), AtoiSimdError>; +pub trait ParserNeg: Sized { + fn atoi_simd_parse_neg(s: &[u8]) -> Result; + fn atoi_simd_parse_until_invalid_neg(s: &[u8]) -> Result<(Self, usize), AtoiSimdError>; } -pub trait Parser>: Sized { +pub trait Parser: ParserPos { #[inline(always)] - fn atoi_simd_parse(s: &[u8]) -> Result { - T::atoi_simd_parse_pos(s) + fn atoi_simd_parse(s: &[u8]) -> Result { + Self::atoi_simd_parse_pos(s) } #[inline(always)] - fn atoi_simd_parse_until_invalid(s: &[u8]) -> Result<(T, usize), AtoiSimdError> { - T::atoi_simd_parse_until_invalid_pos(s) + fn atoi_simd_parse_until_invalid(s: &[u8]) -> Result<(Self, usize), AtoiSimdError> { + Self::atoi_simd_parse_until_invalid_pos(s) } #[inline(always)] - fn atoi_simd_parse_skipped(s: &[u8]) -> Result { + fn atoi_simd_parse_skipped(s: &[u8]) -> Result { let mut i = 0; if *s.first().ok_or(AtoiSimdError::Empty)? == b'+' { i = 1; @@ -78,12 +78,12 @@ pub trait Parser>: Sized { i += 1; } - T::atoi_simd_parse_pos(s.get_safe_unchecked(i..)) + Self::atoi_simd_parse_pos(s.get_safe_unchecked(i..)) } } #[inline(always)] -fn atoi_simd_parse_signed + ParserNeg>(s: &[u8]) -> Result { +fn atoi_simd_parse_signed(s: &[u8]) -> Result { if *s.first().ok_or(AtoiSimdError::Empty)? == b'-' { T::atoi_simd_parse_neg(s.get_safe_unchecked(1..)) } else { @@ -92,7 +92,7 @@ fn atoi_simd_parse_signed + ParserNeg>(s: &[u8]) -> Result + ParserNeg>( +fn atoi_simd_parse_until_invalid_signed( s: &[u8], ) -> Result<(T, usize), AtoiSimdError> { if *s.first().ok_or(AtoiSimdError::Empty)? == b'-' { @@ -103,7 +103,7 @@ fn atoi_simd_parse_until_invalid_signed + ParserNeg>( } #[inline(always)] -fn atoi_simd_parse_skipped_signed + ParserNeg>( +fn atoi_simd_parse_skipped_signed( s: &[u8], ) -> Result { let mut neg = false; @@ -128,12 +128,12 @@ fn atoi_simd_parse_skipped_signed + ParserNeg>( } } -impl Parser for u8 {} -impl Parser for u16 {} -impl Parser for u32 {} -impl Parser for usize {} -impl Parser for u64 {} -impl Parser for u128 {} +impl Parser for u8 {} +impl Parser for u16 {} +impl Parser for u32 {} +impl Parser for usize {} +impl Parser for u64 {} +impl Parser for u128 {} macro_rules! impl_signed { () => { @@ -154,21 +154,21 @@ macro_rules! impl_signed { }; } -impl Parser for i8 { +impl Parser for i8 { impl_signed!(); } -impl Parser for i16 { +impl Parser for i16 { impl_signed!(); } -impl Parser for i32 { +impl Parser for i32 { impl_signed!(); } -impl Parser for isize { +impl Parser for isize { impl_signed!(); } -impl Parser for i64 { +impl Parser for i64 { impl_signed!(); } -impl Parser for i128 { +impl Parser for i128 { impl_signed!(); } diff --git a/src/linker/simd_32.rs b/src/linker/simd_32.rs index a69c873..5abcddc 100644 --- a/src/linker/simd_32.rs +++ b/src/linker/simd_32.rs @@ -1,7 +1,7 @@ use super::*; use crate::simd::shared_32::*; -impl ParserPos for u8 { +impl ParserPos for u8 { #[inline(always)] fn atoi_simd_parse_pos(s: &[u8]) -> Result { parse_simd_checked::<{ u8::MAX as u64 }>(s).map(|v| v as u8) @@ -13,7 +13,7 @@ impl ParserPos for u8 { } } -impl ParserPos for i8 { +impl ParserPos for i8 { #[inline(always)] fn atoi_simd_parse_pos(s: &[u8]) -> Result { parse_simd_checked::<{ i8::MAX as u64 }>(s).map(|v| v as i8) @@ -25,7 +25,7 @@ impl ParserPos for i8 { } } -impl ParserNeg for i8 { +impl ParserNeg for i8 { #[inline(always)] fn atoi_simd_parse_neg(s: &[u8]) -> Result { parse_simd_checked_neg::<{ i8::MIN as i64 }>(s).map(|v| v as i8) @@ -37,7 +37,7 @@ impl ParserNeg for i8 { } } -impl ParserPos for u16 { +impl ParserPos for u16 { #[inline(always)] fn atoi_simd_parse_pos(s: &[u8]) -> Result { parse_simd_checked::<{ u16::MAX as u64 }>(s).map(|v| v as u16) @@ -49,7 +49,7 @@ impl ParserPos for u16 { } } -impl ParserPos for i16 { +impl ParserPos for i16 { #[inline(always)] fn atoi_simd_parse_pos(s: &[u8]) -> Result { parse_simd_checked::<{ i16::MAX as u64 }>(s).map(|v| v as i16) @@ -61,7 +61,7 @@ impl ParserPos for i16 { } } -impl ParserNeg for i16 { +impl ParserNeg for i16 { #[inline(always)] fn atoi_simd_parse_neg(s: &[u8]) -> Result { parse_simd_checked_neg::<{ i16::MIN as i64 }>(s).map(|v| v as i16) @@ -73,7 +73,7 @@ impl ParserNeg for i16 { } } -impl ParserPos for u32 { +impl ParserPos for u32 { #[inline(always)] fn atoi_simd_parse_pos(s: &[u8]) -> Result { parse_simd_checked::<{ u32::MAX as u64 }>(s).map(|v| v as u32) @@ -85,7 +85,7 @@ impl ParserPos for u32 { } } -impl ParserPos for i32 { +impl ParserPos for i32 { #[inline(always)] fn atoi_simd_parse_pos(s: &[u8]) -> Result { parse_simd_checked::<{ i32::MAX as u64 }>(s).map(|v| v as i32) @@ -97,7 +97,7 @@ impl ParserPos for i32 { } } -impl ParserNeg for i32 { +impl ParserNeg for i32 { #[inline(always)] fn atoi_simd_parse_neg(s: &[u8]) -> Result { parse_simd_checked_neg::<{ i32::MIN as i64 }>(s).map(|v| v as i32) @@ -110,7 +110,7 @@ impl ParserNeg for i32 { } #[cfg(target_pointer_width = "32")] -impl ParserPos for usize { +impl ParserPos for usize { #[inline(always)] fn atoi_simd_parse_pos(s: &[u8]) -> Result { parse_simd_checked::<{ u32::MAX as u64 }>(s).map(|v| v as usize) @@ -123,7 +123,7 @@ impl ParserPos for usize { } #[cfg(target_pointer_width = "32")] -impl ParserPos for isize { +impl ParserPos for isize { #[inline(always)] fn atoi_simd_parse_pos(s: &[u8]) -> Result { parse_simd_checked::<{ i32::MAX as u64 }>(s).map(|v| v as isize) @@ -136,7 +136,7 @@ impl ParserPos for isize { } #[cfg(target_pointer_width = "32")] -impl ParserNeg for isize { +impl ParserNeg for isize { #[inline(always)] fn atoi_simd_parse_neg(s: &[u8]) -> Result { parse_simd_checked_neg::<{ i32::MIN as i64 }>(s).map(|v| v as isize) diff --git a/src/linker/simd_64.rs b/src/linker/simd_64.rs index 8823183..d56f320 100644 --- a/src/linker/simd_64.rs +++ b/src/linker/simd_64.rs @@ -2,7 +2,7 @@ use super::*; use crate::simd::shared_64::*; #[cfg(target_pointer_width = "64")] -impl ParserPos for usize { +impl ParserPos for usize { #[inline(always)] fn atoi_simd_parse_pos(s: &[u8]) -> Result { parse_simd_checked_u64(s).map(|v| v as usize) @@ -15,7 +15,7 @@ impl ParserPos for usize { } #[cfg(target_pointer_width = "64")] -impl ParserPos for isize { +impl ParserPos for isize { #[inline(always)] fn atoi_simd_parse_pos(s: &[u8]) -> Result { parse_simd_checked_i64(s).map(|v| v as isize) @@ -28,7 +28,7 @@ impl ParserPos for isize { } #[cfg(target_pointer_width = "64")] -impl ParserNeg for isize { +impl ParserNeg for isize { #[inline(always)] fn atoi_simd_parse_neg(s: &[u8]) -> Result { parse_simd_checked_i64_neg(s).map(|v| v as isize) @@ -40,7 +40,7 @@ impl ParserNeg for isize { } } -impl ParserPos for u64 { +impl ParserPos for u64 { #[inline(always)] fn atoi_simd_parse_pos(s: &[u8]) -> Result { parse_simd_checked_u64(s) @@ -52,7 +52,7 @@ impl ParserPos for u64 { } } -impl ParserPos for i64 { +impl ParserPos for i64 { #[inline(always)] fn atoi_simd_parse_pos(s: &[u8]) -> Result { parse_simd_checked_i64(s) @@ -64,7 +64,7 @@ impl ParserPos for i64 { } } -impl ParserNeg for i64 { +impl ParserNeg for i64 { #[inline(always)] fn atoi_simd_parse_neg(s: &[u8]) -> Result { parse_simd_checked_i64_neg(s) @@ -76,7 +76,7 @@ impl ParserNeg for i64 { } } -impl ParserPos for u128 { +impl ParserPos for u128 { #[inline(always)] fn atoi_simd_parse_pos(s: &[u8]) -> Result { parse_simd_checked_u128(s) @@ -88,7 +88,7 @@ impl ParserPos for u128 { } } -impl ParserPos for i128 { +impl ParserPos for i128 { #[inline(always)] fn atoi_simd_parse_pos(s: &[u8]) -> Result { parse_simd_checked_i128(s) @@ -100,7 +100,7 @@ impl ParserPos for i128 { } } -impl ParserNeg for i128 { +impl ParserNeg for i128 { #[inline(always)] fn atoi_simd_parse_neg(s: &[u8]) -> Result { parse_simd_checked_i128_neg(s) diff --git a/src/test.rs b/src/test.rs index 96b5984..03f7368 100644 --- a/src/test.rs +++ b/src/test.rs @@ -87,7 +87,7 @@ fn test_each_position_until_invalid( } fn parse_tester< - T: Copy + Debug + PartialEq + FromStr + Parser + ParserPos, + T: Copy + Debug + PartialEq + FromStr + Parser + ParserPos, const LEN: usize, const LEN_NEG: usize, I, @@ -118,7 +118,7 @@ fn parse_tester< } fn parse_until_invalid_tester< - T: Copy + Debug + PartialEq + FromStr + Parser + ParserPos, + T: Copy + Debug + PartialEq + FromStr + Parser + ParserPos, const LEN: usize, const LEN_NEG: usize, I, From 790d6b91b3221ca80d7e4f8cbd354b76dec8ecd2 Mon Sep 17 00:00:00 2001 From: Frank Steffahn Date: Thu, 28 Dec 2023 01:28:57 +0100 Subject: [PATCH 2/6] Rename parsing traits --- src/lib.rs | 16 ++++++++-------- src/linker/fb_32.rs | 24 ++++++++++++------------ src/linker/fb_64.rs | 18 +++++++++--------- src/linker/mod.rs | 36 ++++++++++++++++++------------------ src/linker/simd_32.rs | 24 ++++++++++++------------ src/linker/simd_64.rs | 18 +++++++++--------- src/test.rs | 4 ++-- 7 files changed, 70 insertions(+), 70 deletions(-) diff --git a/src/lib.rs b/src/lib.rs index 118bcb7..1dd4cc5 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -68,30 +68,30 @@ mod simd; mod test; pub use crate::error::AtoiSimdError; -use crate::linker::{Parser, ParserNeg, ParserPos}; +use crate::linker::{Parse, ParseNeg, ParsePos}; /// Parses slice of digits, and checks first '-' char for signed integers. #[inline] -pub fn parse(s: &[u8]) -> Result { +pub fn parse(s: &[u8]) -> Result { T::atoi_simd_parse(s) } /// Parses positive integer. #[inline] -pub fn parse_pos(s: &[u8]) -> Result { +pub fn parse_pos(s: &[u8]) -> Result { T::atoi_simd_parse_pos(s) } /// Parses negative integer. Slice must not contain '-' sign. #[inline] -pub fn parse_neg(s: &[u8]) -> Result { +pub fn parse_neg(s: &[u8]) -> Result { T::atoi_simd_parse_neg(s) } /// Parses slice of digits until it reaches invalid character, and checks first '-' char for signed integers. /// Returns parsed value and parsed size of the slice. #[inline] -pub fn parse_until_invalid( +pub fn parse_until_invalid( s: &[u8], ) -> Result<(T, usize), AtoiSimdError> { T::atoi_simd_parse_until_invalid(s) @@ -100,14 +100,14 @@ pub fn parse_until_invalid( /// Parses positive integer until it reaches invalid character. /// Returns parsed value and parsed size of the slice. #[inline] -pub fn parse_until_invalid_pos(s: &[u8]) -> Result<(T, usize), AtoiSimdError> { +pub fn parse_until_invalid_pos(s: &[u8]) -> Result<(T, usize), AtoiSimdError> { T::atoi_simd_parse_until_invalid_pos(s) } /// Parses negative integer until it reaches invalid character. Slice must not contain '-' sign. /// Returns parsed value and parsed size of the slice. #[inline] -pub fn parse_until_invalid_neg(s: &[u8]) -> Result<(T, usize), AtoiSimdError> { +pub fn parse_until_invalid_neg(s: &[u8]) -> Result<(T, usize), AtoiSimdError> { T::atoi_simd_parse_until_invalid_neg(s) } @@ -116,6 +116,6 @@ pub fn parse_until_invalid_neg(s: &[u8]) -> Result<(T, usize), Ato /// Skips '+' char and extra zeroes at the beginning. /// It's slower than `parse()`. #[inline] -pub fn parse_skipped(s: &[u8]) -> Result { +pub fn parse_skipped(s: &[u8]) -> Result { T::atoi_simd_parse_skipped(s) } diff --git a/src/linker/fb_32.rs b/src/linker/fb_32.rs index 75d7097..18f6c87 100644 --- a/src/linker/fb_32.rs +++ b/src/linker/fb_32.rs @@ -1,7 +1,7 @@ use super::*; use crate::fallback::*; -impl ParserPos for u8 { +impl ParsePos for u8 { #[inline(always)] fn atoi_simd_parse_pos(s: &[u8]) -> Result { parse_fb_checked_pos::<{ u8::MAX as u64 }>(s).map(|v| v as u8) @@ -13,7 +13,7 @@ impl ParserPos for u8 { } } -impl ParserPos for i8 { +impl ParsePos for i8 { #[inline(always)] fn atoi_simd_parse_pos(s: &[u8]) -> Result { parse_fb_checked_pos::<{ i8::MAX as u64 }>(s).map(|v| v as i8) @@ -25,7 +25,7 @@ impl ParserPos for i8 { } } -impl ParserNeg for i8 { +impl ParseNeg for i8 { #[inline(always)] fn atoi_simd_parse_neg(s: &[u8]) -> Result { parse_fb_checked_neg::<{ i8::MIN as i64 }>(s).map(|v| v as i8) @@ -37,7 +37,7 @@ impl ParserNeg for i8 { } } -impl ParserPos for u16 { +impl ParsePos for u16 { #[inline(always)] fn atoi_simd_parse_pos(s: &[u8]) -> Result { parse_fb_checked_pos::<{ u16::MAX as u64 }>(s).map(|v| v as u16) @@ -49,7 +49,7 @@ impl ParserPos for u16 { } } -impl ParserPos for i16 { +impl ParsePos for i16 { #[inline(always)] fn atoi_simd_parse_pos(s: &[u8]) -> Result { parse_fb_checked_pos::<{ i16::MAX as u64 }>(s).map(|v| v as i16) @@ -61,7 +61,7 @@ impl ParserPos for i16 { } } -impl ParserNeg for i16 { +impl ParseNeg for i16 { #[inline(always)] fn atoi_simd_parse_neg(s: &[u8]) -> Result { parse_fb_checked_neg::<{ i16::MIN as i64 }>(s).map(|v| v as i16) @@ -73,7 +73,7 @@ impl ParserNeg for i16 { } } -impl ParserPos for u32 { +impl ParsePos for u32 { #[inline(always)] fn atoi_simd_parse_pos(s: &[u8]) -> Result { parse_fb_checked_pos::<{ u32::MAX as u64 }>(s).map(|v| v as u32) @@ -85,7 +85,7 @@ impl ParserPos for u32 { } } -impl ParserPos for i32 { +impl ParsePos for i32 { #[inline(always)] fn atoi_simd_parse_pos(s: &[u8]) -> Result { parse_fb_checked_pos::<{ i32::MAX as u64 }>(s).map(|v| v as i32) @@ -97,7 +97,7 @@ impl ParserPos for i32 { } } -impl ParserNeg for i32 { +impl ParseNeg for i32 { #[inline(always)] fn atoi_simd_parse_neg(s: &[u8]) -> Result { parse_fb_checked_neg::<{ i32::MIN as i64 }>(s).map(|v| v as i32) @@ -110,7 +110,7 @@ impl ParserNeg for i32 { } #[cfg(target_pointer_width = "32")] -impl ParserPos for usize { +impl ParsePos for usize { #[inline(always)] fn atoi_simd_parse_pos(s: &[u8]) -> Result { parse_fb_checked_pos::<{ u32::MAX as u64 }>(s).map(|v| v as usize) @@ -123,7 +123,7 @@ impl ParserPos for usize { } #[cfg(target_pointer_width = "32")] -impl ParserPos for isize { +impl ParsePos for isize { #[inline(always)] fn atoi_simd_parse_pos(s: &[u8]) -> Result { parse_fb_checked_pos::<{ i32::MAX as u64 }>(s).map(|v| v as isize) @@ -136,7 +136,7 @@ impl ParserPos for isize { } #[cfg(target_pointer_width = "32")] -impl ParserNeg for isize { +impl ParseNeg for isize { #[inline(always)] fn atoi_simd_parse_neg(s: &[u8]) -> Result { parse_fb_checked_neg::<{ i32::MIN as i64 }>(s).map(|v| v as isize) diff --git a/src/linker/fb_64.rs b/src/linker/fb_64.rs index f2a4b9e..2b26a11 100644 --- a/src/linker/fb_64.rs +++ b/src/linker/fb_64.rs @@ -2,7 +2,7 @@ use super::*; use crate::fallback::*; #[cfg(target_pointer_width = "64")] -impl ParserPos for usize { +impl ParsePos for usize { #[inline(always)] fn atoi_simd_parse_pos(s: &[u8]) -> Result { parse_fb_checked_64_pos::<{ u64::MAX }, 4>(s).map(|v| v as usize) @@ -15,7 +15,7 @@ impl ParserPos for usize { } #[cfg(target_pointer_width = "64")] -impl ParserPos for isize { +impl ParsePos for isize { #[inline(always)] fn atoi_simd_parse_pos(s: &[u8]) -> Result { parse_fb_checked_64_pos::<{ i64::MAX as u64 }, 3>(s).map(|v| v as isize) @@ -28,7 +28,7 @@ impl ParserPos for isize { } #[cfg(target_pointer_width = "64")] -impl ParserNeg for isize { +impl ParseNeg for isize { #[inline(always)] fn atoi_simd_parse_neg(s: &[u8]) -> Result { parse_fb_checked_64_neg(s).map(|v| v as isize) @@ -40,7 +40,7 @@ impl ParserNeg for isize { } } -impl ParserPos for u64 { +impl ParsePos for u64 { #[inline(always)] fn atoi_simd_parse_pos(s: &[u8]) -> Result { parse_fb_checked_64_pos::<{ u64::MAX }, 4>(s) @@ -52,7 +52,7 @@ impl ParserPos for u64 { } } -impl ParserPos for i64 { +impl ParsePos for i64 { #[inline(always)] fn atoi_simd_parse_pos(s: &[u8]) -> Result { parse_fb_checked_64_pos::<{ i64::MAX as u64 }, 3>(s).map(|v| v as i64) @@ -64,7 +64,7 @@ impl ParserPos for i64 { } } -impl ParserNeg for i64 { +impl ParseNeg for i64 { #[inline(always)] fn atoi_simd_parse_neg(s: &[u8]) -> Result { parse_fb_checked_64_neg(s) @@ -76,7 +76,7 @@ impl ParserNeg for i64 { } } -impl ParserPos for u128 { +impl ParsePos for u128 { #[inline(always)] fn atoi_simd_parse_pos(s: &[u8]) -> Result { parse_fb_checked_128_pos::<{ u128::MAX }>(s) @@ -88,7 +88,7 @@ impl ParserPos for u128 { } } -impl ParserPos for i128 { +impl ParsePos for i128 { #[inline(always)] fn atoi_simd_parse_pos(s: &[u8]) -> Result { parse_fb_checked_128_pos::<{ i128::MAX as u128 }>(s).map(|v| v as i128) @@ -100,7 +100,7 @@ impl ParserPos for i128 { } } -impl ParserNeg for i128 { +impl ParseNeg for i128 { #[inline(always)] fn atoi_simd_parse_neg(s: &[u8]) -> Result { parse_fb_checked_128_neg(s) diff --git a/src/linker/mod.rs b/src/linker/mod.rs index d86db0d..88ab879 100644 --- a/src/linker/mod.rs +++ b/src/linker/mod.rs @@ -46,17 +46,17 @@ mod fb_64; use crate::{safe_unchecked::SliceGetter, AtoiSimdError}; -pub trait ParserPos: Sized { +pub trait ParsePos: Sized { fn atoi_simd_parse_pos(s: &[u8]) -> Result; fn atoi_simd_parse_until_invalid_pos(s: &[u8]) -> Result<(Self, usize), AtoiSimdError>; } -pub trait ParserNeg: Sized { +pub trait ParseNeg: Sized { fn atoi_simd_parse_neg(s: &[u8]) -> Result; fn atoi_simd_parse_until_invalid_neg(s: &[u8]) -> Result<(Self, usize), AtoiSimdError>; } -pub trait Parser: ParserPos { +pub trait Parse: ParsePos { #[inline(always)] fn atoi_simd_parse(s: &[u8]) -> Result { Self::atoi_simd_parse_pos(s) @@ -83,7 +83,7 @@ pub trait Parser: ParserPos { } #[inline(always)] -fn atoi_simd_parse_signed(s: &[u8]) -> Result { +fn atoi_simd_parse_signed(s: &[u8]) -> Result { if *s.first().ok_or(AtoiSimdError::Empty)? == b'-' { T::atoi_simd_parse_neg(s.get_safe_unchecked(1..)) } else { @@ -92,7 +92,7 @@ fn atoi_simd_parse_signed(s: &[u8]) -> Result( +fn atoi_simd_parse_until_invalid_signed( s: &[u8], ) -> Result<(T, usize), AtoiSimdError> { if *s.first().ok_or(AtoiSimdError::Empty)? == b'-' { @@ -103,7 +103,7 @@ fn atoi_simd_parse_until_invalid_signed( } #[inline(always)] -fn atoi_simd_parse_skipped_signed( +fn atoi_simd_parse_skipped_signed( s: &[u8], ) -> Result { let mut neg = false; @@ -128,12 +128,12 @@ fn atoi_simd_parse_skipped_signed( } } -impl Parser for u8 {} -impl Parser for u16 {} -impl Parser for u32 {} -impl Parser for usize {} -impl Parser for u64 {} -impl Parser for u128 {} +impl Parse for u8 {} +impl Parse for u16 {} +impl Parse for u32 {} +impl Parse for usize {} +impl Parse for u64 {} +impl Parse for u128 {} macro_rules! impl_signed { () => { @@ -154,21 +154,21 @@ macro_rules! impl_signed { }; } -impl Parser for i8 { +impl Parse for i8 { impl_signed!(); } -impl Parser for i16 { +impl Parse for i16 { impl_signed!(); } -impl Parser for i32 { +impl Parse for i32 { impl_signed!(); } -impl Parser for isize { +impl Parse for isize { impl_signed!(); } -impl Parser for i64 { +impl Parse for i64 { impl_signed!(); } -impl Parser for i128 { +impl Parse for i128 { impl_signed!(); } diff --git a/src/linker/simd_32.rs b/src/linker/simd_32.rs index 5abcddc..60bb6a1 100644 --- a/src/linker/simd_32.rs +++ b/src/linker/simd_32.rs @@ -1,7 +1,7 @@ use super::*; use crate::simd::shared_32::*; -impl ParserPos for u8 { +impl ParsePos for u8 { #[inline(always)] fn atoi_simd_parse_pos(s: &[u8]) -> Result { parse_simd_checked::<{ u8::MAX as u64 }>(s).map(|v| v as u8) @@ -13,7 +13,7 @@ impl ParserPos for u8 { } } -impl ParserPos for i8 { +impl ParsePos for i8 { #[inline(always)] fn atoi_simd_parse_pos(s: &[u8]) -> Result { parse_simd_checked::<{ i8::MAX as u64 }>(s).map(|v| v as i8) @@ -25,7 +25,7 @@ impl ParserPos for i8 { } } -impl ParserNeg for i8 { +impl ParseNeg for i8 { #[inline(always)] fn atoi_simd_parse_neg(s: &[u8]) -> Result { parse_simd_checked_neg::<{ i8::MIN as i64 }>(s).map(|v| v as i8) @@ -37,7 +37,7 @@ impl ParserNeg for i8 { } } -impl ParserPos for u16 { +impl ParsePos for u16 { #[inline(always)] fn atoi_simd_parse_pos(s: &[u8]) -> Result { parse_simd_checked::<{ u16::MAX as u64 }>(s).map(|v| v as u16) @@ -49,7 +49,7 @@ impl ParserPos for u16 { } } -impl ParserPos for i16 { +impl ParsePos for i16 { #[inline(always)] fn atoi_simd_parse_pos(s: &[u8]) -> Result { parse_simd_checked::<{ i16::MAX as u64 }>(s).map(|v| v as i16) @@ -61,7 +61,7 @@ impl ParserPos for i16 { } } -impl ParserNeg for i16 { +impl ParseNeg for i16 { #[inline(always)] fn atoi_simd_parse_neg(s: &[u8]) -> Result { parse_simd_checked_neg::<{ i16::MIN as i64 }>(s).map(|v| v as i16) @@ -73,7 +73,7 @@ impl ParserNeg for i16 { } } -impl ParserPos for u32 { +impl ParsePos for u32 { #[inline(always)] fn atoi_simd_parse_pos(s: &[u8]) -> Result { parse_simd_checked::<{ u32::MAX as u64 }>(s).map(|v| v as u32) @@ -85,7 +85,7 @@ impl ParserPos for u32 { } } -impl ParserPos for i32 { +impl ParsePos for i32 { #[inline(always)] fn atoi_simd_parse_pos(s: &[u8]) -> Result { parse_simd_checked::<{ i32::MAX as u64 }>(s).map(|v| v as i32) @@ -97,7 +97,7 @@ impl ParserPos for i32 { } } -impl ParserNeg for i32 { +impl ParseNeg for i32 { #[inline(always)] fn atoi_simd_parse_neg(s: &[u8]) -> Result { parse_simd_checked_neg::<{ i32::MIN as i64 }>(s).map(|v| v as i32) @@ -110,7 +110,7 @@ impl ParserNeg for i32 { } #[cfg(target_pointer_width = "32")] -impl ParserPos for usize { +impl ParsePos for usize { #[inline(always)] fn atoi_simd_parse_pos(s: &[u8]) -> Result { parse_simd_checked::<{ u32::MAX as u64 }>(s).map(|v| v as usize) @@ -123,7 +123,7 @@ impl ParserPos for usize { } #[cfg(target_pointer_width = "32")] -impl ParserPos for isize { +impl ParsePos for isize { #[inline(always)] fn atoi_simd_parse_pos(s: &[u8]) -> Result { parse_simd_checked::<{ i32::MAX as u64 }>(s).map(|v| v as isize) @@ -136,7 +136,7 @@ impl ParserPos for isize { } #[cfg(target_pointer_width = "32")] -impl ParserNeg for isize { +impl ParseNeg for isize { #[inline(always)] fn atoi_simd_parse_neg(s: &[u8]) -> Result { parse_simd_checked_neg::<{ i32::MIN as i64 }>(s).map(|v| v as isize) diff --git a/src/linker/simd_64.rs b/src/linker/simd_64.rs index d56f320..0360fc7 100644 --- a/src/linker/simd_64.rs +++ b/src/linker/simd_64.rs @@ -2,7 +2,7 @@ use super::*; use crate::simd::shared_64::*; #[cfg(target_pointer_width = "64")] -impl ParserPos for usize { +impl ParsePos for usize { #[inline(always)] fn atoi_simd_parse_pos(s: &[u8]) -> Result { parse_simd_checked_u64(s).map(|v| v as usize) @@ -15,7 +15,7 @@ impl ParserPos for usize { } #[cfg(target_pointer_width = "64")] -impl ParserPos for isize { +impl ParsePos for isize { #[inline(always)] fn atoi_simd_parse_pos(s: &[u8]) -> Result { parse_simd_checked_i64(s).map(|v| v as isize) @@ -28,7 +28,7 @@ impl ParserPos for isize { } #[cfg(target_pointer_width = "64")] -impl ParserNeg for isize { +impl ParseNeg for isize { #[inline(always)] fn atoi_simd_parse_neg(s: &[u8]) -> Result { parse_simd_checked_i64_neg(s).map(|v| v as isize) @@ -40,7 +40,7 @@ impl ParserNeg for isize { } } -impl ParserPos for u64 { +impl ParsePos for u64 { #[inline(always)] fn atoi_simd_parse_pos(s: &[u8]) -> Result { parse_simd_checked_u64(s) @@ -52,7 +52,7 @@ impl ParserPos for u64 { } } -impl ParserPos for i64 { +impl ParsePos for i64 { #[inline(always)] fn atoi_simd_parse_pos(s: &[u8]) -> Result { parse_simd_checked_i64(s) @@ -64,7 +64,7 @@ impl ParserPos for i64 { } } -impl ParserNeg for i64 { +impl ParseNeg for i64 { #[inline(always)] fn atoi_simd_parse_neg(s: &[u8]) -> Result { parse_simd_checked_i64_neg(s) @@ -76,7 +76,7 @@ impl ParserNeg for i64 { } } -impl ParserPos for u128 { +impl ParsePos for u128 { #[inline(always)] fn atoi_simd_parse_pos(s: &[u8]) -> Result { parse_simd_checked_u128(s) @@ -88,7 +88,7 @@ impl ParserPos for u128 { } } -impl ParserPos for i128 { +impl ParsePos for i128 { #[inline(always)] fn atoi_simd_parse_pos(s: &[u8]) -> Result { parse_simd_checked_i128(s) @@ -100,7 +100,7 @@ impl ParserPos for i128 { } } -impl ParserNeg for i128 { +impl ParseNeg for i128 { #[inline(always)] fn atoi_simd_parse_neg(s: &[u8]) -> Result { parse_simd_checked_i128_neg(s) diff --git a/src/test.rs b/src/test.rs index 03f7368..38bfa25 100644 --- a/src/test.rs +++ b/src/test.rs @@ -87,7 +87,7 @@ fn test_each_position_until_invalid( } fn parse_tester< - T: Copy + Debug + PartialEq + FromStr + Parser + ParserPos, + T: Copy + Debug + PartialEq + FromStr + Parse + ParsePos, const LEN: usize, const LEN_NEG: usize, I, @@ -118,7 +118,7 @@ fn parse_tester< } fn parse_until_invalid_tester< - T: Copy + Debug + PartialEq + FromStr + Parser + ParserPos, + T: Copy + Debug + PartialEq + FromStr + Parse + ParsePos, const LEN: usize, const LEN_NEG: usize, I, From 5cd4e97abd622f3983ebfe0c628df7689d8fd566 Mon Sep 17 00:00:00 2001 From: Frank Steffahn Date: Thu, 28 Dec 2023 01:32:18 +0100 Subject: [PATCH 3/6] Minimize trait bounds on publicly visible API, after ParsePos is now a supertrait of Parse --- src/lib.rs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/lib.rs b/src/lib.rs index 1dd4cc5..4add6e0 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -72,7 +72,7 @@ use crate::linker::{Parse, ParseNeg, ParsePos}; /// Parses slice of digits, and checks first '-' char for signed integers. #[inline] -pub fn parse(s: &[u8]) -> Result { +pub fn parse(s: &[u8]) -> Result { T::atoi_simd_parse(s) } @@ -91,7 +91,7 @@ pub fn parse_neg(s: &[u8]) -> Result { /// Parses slice of digits until it reaches invalid character, and checks first '-' char for signed integers. /// Returns parsed value and parsed size of the slice. #[inline] -pub fn parse_until_invalid( +pub fn parse_until_invalid( s: &[u8], ) -> Result<(T, usize), AtoiSimdError> { T::atoi_simd_parse_until_invalid(s) @@ -116,6 +116,6 @@ pub fn parse_until_invalid_neg(s: &[u8]) -> Result<(T, usize), Atoi /// Skips '+' char and extra zeroes at the beginning. /// It's slower than `parse()`. #[inline] -pub fn parse_skipped(s: &[u8]) -> Result { +pub fn parse_skipped(s: &[u8]) -> Result { T::atoi_simd_parse_skipped(s) } From d32c171dba02dae20942fe926d81130f81a34362 Mon Sep 17 00:00:00 2001 From: Frank Steffahn Date: Thu, 28 Dec 2023 01:34:58 +0100 Subject: [PATCH 4/6] Remove usage of ParsePos in publicly visible API to simplify - Parse and ParsePos were implemented for the same types, anyways. --- src/lib.rs | 6 +++--- src/test.rs | 4 ++-- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/src/lib.rs b/src/lib.rs index 4add6e0..6c7121f 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -68,7 +68,7 @@ mod simd; mod test; pub use crate::error::AtoiSimdError; -use crate::linker::{Parse, ParseNeg, ParsePos}; +use crate::linker::{Parse, ParseNeg}; /// Parses slice of digits, and checks first '-' char for signed integers. #[inline] @@ -78,7 +78,7 @@ pub fn parse(s: &[u8]) -> Result { /// Parses positive integer. #[inline] -pub fn parse_pos(s: &[u8]) -> Result { +pub fn parse_pos(s: &[u8]) -> Result { T::atoi_simd_parse_pos(s) } @@ -100,7 +100,7 @@ pub fn parse_until_invalid( /// Parses positive integer until it reaches invalid character. /// Returns parsed value and parsed size of the slice. #[inline] -pub fn parse_until_invalid_pos(s: &[u8]) -> Result<(T, usize), AtoiSimdError> { +pub fn parse_until_invalid_pos(s: &[u8]) -> Result<(T, usize), AtoiSimdError> { T::atoi_simd_parse_until_invalid_pos(s) } diff --git a/src/test.rs b/src/test.rs index 38bfa25..eb3d567 100644 --- a/src/test.rs +++ b/src/test.rs @@ -87,7 +87,7 @@ fn test_each_position_until_invalid( } fn parse_tester< - T: Copy + Debug + PartialEq + FromStr + Parse + ParsePos, + T: Copy + Debug + PartialEq + FromStr + Parse, const LEN: usize, const LEN_NEG: usize, I, @@ -118,7 +118,7 @@ fn parse_tester< } fn parse_until_invalid_tester< - T: Copy + Debug + PartialEq + FromStr + Parse + ParsePos, + T: Copy + Debug + PartialEq + FromStr + Parse, const LEN: usize, const LEN_NEG: usize, I, From fd1d53797c60b81fceff2d370d21706e49d070f8 Mon Sep 17 00:00:00 2001 From: Frank Steffahn Date: Thu, 28 Dec 2023 01:41:04 +0100 Subject: [PATCH 5/6] Make macro for signed implementation a bit more neat --- src/linker/mod.rs | 53 +++++++++++++++++------------------------------ 1 file changed, 19 insertions(+), 34 deletions(-) diff --git a/src/linker/mod.rs b/src/linker/mod.rs index 88ab879..b9f0afa 100644 --- a/src/linker/mod.rs +++ b/src/linker/mod.rs @@ -135,40 +135,25 @@ impl Parse for usize {} impl Parse for u64 {} impl Parse for u128 {} -macro_rules! impl_signed { - () => { - #[inline(always)] - fn atoi_simd_parse(s: &[u8]) -> Result { - atoi_simd_parse_signed(s) +macro_rules! parse_impl_signed { + ($($t:ty)*) => {$( + impl Parse for $t { + #[inline(always)] + fn atoi_simd_parse(s: &[u8]) -> Result { + atoi_simd_parse_signed(s) + } + + #[inline(always)] + fn atoi_simd_parse_until_invalid(s: &[u8]) -> Result<(Self, usize), AtoiSimdError> { + atoi_simd_parse_until_invalid_signed(s) + } + + #[inline(always)] + fn atoi_simd_parse_skipped(s: &[u8]) -> Result { + atoi_simd_parse_skipped_signed(s) + } } - - #[inline(always)] - fn atoi_simd_parse_until_invalid(s: &[u8]) -> Result<(Self, usize), AtoiSimdError> { - atoi_simd_parse_until_invalid_signed(s) - } - - #[inline(always)] - fn atoi_simd_parse_skipped(s: &[u8]) -> Result { - atoi_simd_parse_skipped_signed(s) - } - }; + )*}; } -impl Parse for i8 { - impl_signed!(); -} -impl Parse for i16 { - impl_signed!(); -} -impl Parse for i32 { - impl_signed!(); -} -impl Parse for isize { - impl_signed!(); -} -impl Parse for i64 { - impl_signed!(); -} -impl Parse for i128 { - impl_signed!(); -} +parse_impl_signed!(i8 i16 i32 isize i64 i128); From f854498ae67e0b2f6ef1b74d05b5211a247b4284 Mon Sep 17 00:00:00 2001 From: Frank Steffahn Date: Thu, 28 Dec 2023 02:24:45 +0100 Subject: [PATCH 6/6] Format --- src/lib.rs | 4 +--- src/linker/mod.rs | 4 +--- 2 files changed, 2 insertions(+), 6 deletions(-) diff --git a/src/lib.rs b/src/lib.rs index 6c7121f..0eef094 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -91,9 +91,7 @@ pub fn parse_neg(s: &[u8]) -> Result { /// Parses slice of digits until it reaches invalid character, and checks first '-' char for signed integers. /// Returns parsed value and parsed size of the slice. #[inline] -pub fn parse_until_invalid( - s: &[u8], -) -> Result<(T, usize), AtoiSimdError> { +pub fn parse_until_invalid(s: &[u8]) -> Result<(T, usize), AtoiSimdError> { T::atoi_simd_parse_until_invalid(s) } diff --git a/src/linker/mod.rs b/src/linker/mod.rs index b9f0afa..ec0f5ff 100644 --- a/src/linker/mod.rs +++ b/src/linker/mod.rs @@ -103,9 +103,7 @@ fn atoi_simd_parse_until_invalid_signed( } #[inline(always)] -fn atoi_simd_parse_skipped_signed( - s: &[u8], -) -> Result { +fn atoi_simd_parse_skipped_signed(s: &[u8]) -> Result { let mut neg = false; let mut i = match *s.first().ok_or(AtoiSimdError::Empty)? { b'+' => 1,