Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update to use APIs up to MSRV #206

Merged
merged 1 commit into from
Mar 19, 2025
Merged
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 build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -99,11 +99,11 @@ struct Version (u32, u32, u32);

impl Version {
fn parse(s: &str) -> Result<Version, String> {
if !s.starts_with("rustc ") {
return Err(format!("unrecognized version string: {}", s));
}
let s = s.trim_start_matches("rustc ");
let s = match s.strip_prefix("rustc ") {
Some(s) => s,
None => return Err(format!("unrecognized version string: {}", s)),
};

let mut iter = s
.split('.')
.take(3)
Expand Down
2 changes: 1 addition & 1 deletion src/iter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -52,11 +52,11 @@
pub unsafe fn peek_ahead(&self, n: usize) -> Option<u8> {
debug_assert!(n <= self.len());
// SAFETY: by preconditions
let p = unsafe { self.cursor.add(n) };

Check warning on line 55 in src/iter.rs

View workflow job for this annotation

GitHub Actions / msrv (x64)

unnecessary `unsafe` block
if p < self.end {
// SAFETY: by preconditions, if this is not `self.end`,
// then it is safe to dereference
Some(unsafe { *p })

Check warning on line 59 in src/iter.rs

View workflow job for this annotation

GitHub Actions / msrv (x64)

unnecessary `unsafe` block

Check warning on line 59 in src/iter.rs

View workflow job for this annotation

GitHub Actions / msrv (aarch64)

unnecessary `unsafe` block
} else {
None
}
Expand All @@ -64,7 +64,7 @@

#[inline]
pub fn peek_n<'b: 'a, U: TryFrom<&'a [u8]>>(&'b self, n: usize) -> Option<U> {
// TODO: once we bump MSRC, use const generics to allow only [u8; N] reads
// TODO: once we bump MSRV, use const generics to allow only [u8; N] reads
// TODO: drop `n` arg in favour of const
// let n = core::mem::size_of::<U>();
self.as_ref().get(..n)?.try_into().ok()
Expand Down
17 changes: 6 additions & 11 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -757,21 +757,16 @@ pub const EMPTY_HEADER: Header<'static> = Header { name: "", value: b"" };
// WARNING: Exported for internal benchmarks, not fit for public consumption
pub fn parse_version(bytes: &mut Bytes) -> Result<u8> {
if let Some(eight) = bytes.peek_n::<[u8; 8]>(8) {
// NOTE: should be const once MSRV >= 1.44
let h10: u64 = u64::from_ne_bytes(*b"HTTP/1.0");
let h11: u64 = u64::from_ne_bytes(*b"HTTP/1.1");
const H10: u64 = u64::from_ne_bytes(*b"HTTP/1.0");
const H11: u64 = u64::from_ne_bytes(*b"HTTP/1.1");
// SAFETY: peek_n(8) before ensure within bounds
unsafe {
bytes.advance(8);
}
let block = u64::from_ne_bytes(eight);
// NOTE: should be match once h10 & h11 are consts
return if block == h10 {
Ok(Status::Complete(0))
} else if block == h11 {
Ok(Status::Complete(1))
} else {
Err(Error::Version)
return match u64::from_ne_bytes(eight) {
H10 => Ok(Status::Complete(0)),
H11 => Ok(Status::Complete(1)),
_ => Err(Error::Version),
};
}

Expand Down
12 changes: 4 additions & 8 deletions src/simd/avx2.rs
Original file line number Diff line number Diff line change
Expand Up @@ -74,10 +74,8 @@ unsafe fn match_url_char_32_avx(buf: &[u8]) -> usize {
// Simply, we're converting a vector value to scalar value here.
let res = _mm256_movemask_epi8(bit) as u32;

// Count trailing zeros to find the first encountered invalid character.
// Bitwise NOT is required once again to flip truthiness.
// TODO: use .trailing_ones() once MSRV >= 1.46
(!res).trailing_zeros() as usize
// Count trailing ones to find the first encountered invalid character.
res.trailing_ones() as usize
}

#[target_feature(enable = "avx2")]
Expand Down Expand Up @@ -138,10 +136,8 @@ unsafe fn match_header_value_char_32_avx(buf: &[u8]) -> usize {
// Creates a scalar value from vector value.
let res = _mm256_movemask_epi8(bit) as u32;

// Count trailing zeros to find the first encountered invalid character.
// Bitwise NOT is required once again to flip truthiness.
// TODO: use .trailing_ones() once MSRV >= 1.46
(!res).trailing_zeros() as usize
// Count trailing ones to find the first encountered invalid character.
res.trailing_ones() as usize
}

#[test]
Expand Down
6 changes: 2 additions & 4 deletions src/simd/sse42.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,7 @@ unsafe fn match_url_char_16_sse(buf: &[u8]) -> usize {
let bit = _mm_andnot_si128(del, low);
let res = _mm_movemask_epi8(bit) as u16;

// TODO: use .trailing_ones() once MSRV >= 1.46
(!res).trailing_zeros() as usize
res.trailing_ones() as usize
}

#[target_feature(enable = "sse4.2")]
Expand Down Expand Up @@ -79,8 +78,7 @@ unsafe fn match_header_value_char_16_sse(buf: &[u8]) -> usize {
let bit = _mm_andnot_si128(del, _mm_or_si128(low, tab));
let res = _mm_movemask_epi8(bit) as u16;

// TODO: use .trailing_ones() once MSRV >= 1.46
(!res).trailing_zeros() as usize
res.trailing_ones() as usize
}

#[test]
Expand Down
3 changes: 1 addition & 2 deletions src/simd/swar.rs
Original file line number Diff line number Diff line change
Expand Up @@ -103,10 +103,9 @@ fn match_block(f: impl Fn(u8) -> bool, block: ByteBlock) -> usize {
BLOCK_SIZE
}

// A const alternative to u64::from_ne_bytes to avoid bumping MSRV (1.36 => 1.44)
// creates a u64 whose bytes are each equal to b
const fn uniform_block(b: u8) -> usize {
(b as u64 * 0x01_01_01_01_01_01_01_01 /* [1_u8; 8] */) as usize
usize::from_ne_bytes([b; BLOCK_SIZE])
}

// A byte-wise range-check on an entire word/block,
Expand Down
Loading