From 71eb49c318c3e7c25a6306414298d78accd164df Mon Sep 17 00:00:00 2001 From: Michael Goulet Date: Sun, 14 Jul 2024 13:25:06 -0400 Subject: [PATCH] fmt --- .../rustc_span/src/analyze_source_file.rs | 91 ++++++++++--------- 1 file changed, 49 insertions(+), 42 deletions(-) diff --git a/compiler/rustc_span/src/analyze_source_file.rs b/compiler/rustc_span/src/analyze_source_file.rs index 7da7dc610ecf1..80c5c3bf1b5a7 100644 --- a/compiler/rustc_span/src/analyze_source_file.rs +++ b/compiler/rustc_span/src/analyze_source_file.rs @@ -35,25 +35,25 @@ pub fn analyze_source_file( cfg_match! { cfg(any(target_arch = "x86", target_arch = "x86_64")) => { - fn analyze_source_file_dispatch(src: &str, - lines: &mut Vec, - multi_byte_chars: &mut Vec, - non_narrow_chars: &mut Vec) { + fn analyze_source_file_dispatch( + src: &str, + lines: &mut Vec, + multi_byte_chars: &mut Vec, + non_narrow_chars: &mut Vec, + ) { if is_x86_feature_detected!("sse2") { unsafe { - analyze_source_file_sse2(src, - lines, - multi_byte_chars, - non_narrow_chars); + analyze_source_file_sse2(src, lines, multi_byte_chars, non_narrow_chars); } } else { - analyze_source_file_generic(src, - src.len(), - RelativeBytePos::from_u32(0), - lines, - multi_byte_chars, - non_narrow_chars); - + analyze_source_file_generic( + src, + src.len(), + RelativeBytePos::from_u32(0), + lines, + multi_byte_chars, + non_narrow_chars, + ); } } @@ -62,10 +62,12 @@ cfg_match! { /// function falls back to the generic implementation. Otherwise it uses /// SSE2 intrinsics to quickly find all newlines. #[target_feature(enable = "sse2")] - unsafe fn analyze_source_file_sse2(src: &str, - lines: &mut Vec, - multi_byte_chars: &mut Vec, - non_narrow_chars: &mut Vec) { + unsafe fn analyze_source_file_sse2( + src: &str, + lines: &mut Vec, + multi_byte_chars: &mut Vec, + non_narrow_chars: &mut Vec, + ) { #[cfg(target_arch = "x86")] use std::arch::x86::*; #[cfg(target_arch = "x86_64")] @@ -83,7 +85,7 @@ cfg_match! { // handled it. let mut intra_chunk_offset = 0; - for chunk_index in 0 .. chunk_count { + for chunk_index in 0..chunk_count { let ptr = src_bytes.as_ptr() as *const __m128i; // We don't know if the pointer is aligned to 16 bytes, so we // use `loadu`, which supports unaligned loading. @@ -126,7 +128,7 @@ cfg_match! { if index >= CHUNK_SIZE as u32 { // We have arrived at the end of the chunk. - break + break; } lines.push(RelativeBytePos(index) + output_offset); @@ -137,14 +139,14 @@ cfg_match! { // We are done for this chunk. All control characters were // newlines and we took care of those. - continue + continue; } else { // Some of the control characters are not newlines, // fall through to the slow path below. } } else { // No control characters, nothing to record for this chunk - continue + continue; } } @@ -152,43 +154,48 @@ cfg_match! { // There are control chars in here, fallback to generic decoding. let scan_start = chunk_index * CHUNK_SIZE + intra_chunk_offset; intra_chunk_offset = analyze_source_file_generic( - &src[scan_start .. ], + &src[scan_start..], CHUNK_SIZE - intra_chunk_offset, RelativeBytePos::from_usize(scan_start), lines, multi_byte_chars, - non_narrow_chars + non_narrow_chars, ); } // There might still be a tail left to analyze let tail_start = chunk_count * CHUNK_SIZE + intra_chunk_offset; if tail_start < src.len() { - analyze_source_file_generic(&src[tail_start ..], - src.len() - tail_start, - RelativeBytePos::from_usize(tail_start), - lines, - multi_byte_chars, - non_narrow_chars); + analyze_source_file_generic( + &src[tail_start..], + src.len() - tail_start, + RelativeBytePos::from_usize(tail_start), + lines, + multi_byte_chars, + non_narrow_chars, + ); } } } _ => { // The target (or compiler version) does not support SSE2 ... - fn analyze_source_file_dispatch(src: &str, - lines: &mut Vec, - multi_byte_chars: &mut Vec, - non_narrow_chars: &mut Vec) { - analyze_source_file_generic(src, - src.len(), - RelativeBytePos::from_u32(0), - lines, - multi_byte_chars, - non_narrow_chars); + fn analyze_source_file_dispatch( + src: &str, + lines: &mut Vec, + multi_byte_chars: &mut Vec, + non_narrow_chars: &mut Vec, + ) { + analyze_source_file_generic( + src, + src.len(), + RelativeBytePos::from_u32(0), + lines, + multi_byte_chars, + non_narrow_chars, + ); } } } - // `scan_len` determines the number of bytes in `src` to scan. Note that the // function can read past `scan_len` if a multi-byte character start within the // range but extends past it. The overflow is returned by the function.