diff options
| author | León Orell Valerian Liehr <me@fmease.dev> | 2025-02-25 13:32:53 +0100 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2025-02-25 13:32:53 +0100 |
| commit | da31d840def341dbda62f90fde91002df9102e54 (patch) | |
| tree | 025cc00944639bfc938d3713a7a15713fee00856 | |
| parent | fb31487fdb2f28c9368a6ea887709ad7575ec070 (diff) | |
| parent | 62f5a5501f70f544689423a7c1b8a5113bed1924 (diff) | |
| download | rust-da31d840def341dbda62f90fde91002df9102e54.tar.gz rust-da31d840def341dbda62f90fde91002df9102e54.zip | |
Rollup merge of #137360 - real-eren:rustc_span/use-chunks-exact, r=Noratrieb
Use `as_chunks` in `analyze_source_file_sse2` Follow-up to #136460. Uses a slightly cleaner method of iterating over chunks of bytes.
| -rw-r--r-- | compiler/rustc_span/src/analyze_source_file.rs | 11 | ||||
| -rw-r--r-- | compiler/rustc_span/src/lib.rs | 1 |
2 files changed, 5 insertions, 7 deletions
diff --git a/compiler/rustc_span/src/analyze_source_file.rs b/compiler/rustc_span/src/analyze_source_file.rs index a39bb884faa..141d261b5f0 100644 --- a/compiler/rustc_span/src/analyze_source_file.rs +++ b/compiler/rustc_span/src/analyze_source_file.rs @@ -68,9 +68,7 @@ cfg_match! { const CHUNK_SIZE: usize = 16; - let src_bytes = src.as_bytes(); - - let chunk_count = src.len() / CHUNK_SIZE; + let (chunks, tail) = src.as_bytes().as_chunks::<CHUNK_SIZE>(); // This variable keeps track of where we should start decoding a // chunk. If a multi-byte character spans across chunk boundaries, @@ -78,11 +76,10 @@ cfg_match! { // handled it. let mut intra_chunk_offset = 0; - for chunk_index in 0..chunk_count { - let ptr = src_bytes.as_ptr() as *const __m128i; + for (chunk_index, chunk) in chunks.iter().enumerate() { // We don't know if the pointer is aligned to 16 bytes, so we // use `loadu`, which supports unaligned loading. - let chunk = unsafe { _mm_loadu_si128(ptr.add(chunk_index)) }; + let chunk = unsafe { _mm_loadu_si128(chunk.as_ptr() as *const __m128i) }; // For character in the chunk, see if its byte value is < 0, which // indicates that it's part of a UTF-8 char. @@ -123,7 +120,7 @@ cfg_match! { } // There might still be a tail left to analyze - let tail_start = chunk_count * CHUNK_SIZE + intra_chunk_offset; + let tail_start = src.len() - tail.len() + intra_chunk_offset; if tail_start < src.len() { analyze_source_file_generic( &src[tail_start..], diff --git a/compiler/rustc_span/src/lib.rs b/compiler/rustc_span/src/lib.rs index c09669d959c..bca9323a50d 100644 --- a/compiler/rustc_span/src/lib.rs +++ b/compiler/rustc_span/src/lib.rs @@ -31,6 +31,7 @@ #![feature(round_char_boundary)] #![feature(rustc_attrs)] #![feature(rustdoc_internals)] +#![feature(slice_as_chunks)] #![warn(unreachable_pub)] // tidy-alphabetical-end |
