4
4
use crate :: builder_spirv:: BuilderSpirv ;
5
5
use crate :: custom_insts:: { self , CustomInst } ;
6
6
use either:: Either ;
7
- use itertools:: Itertools ;
8
7
use rspirv:: dr:: { Instruction , Module , Operand } ;
9
8
use rspirv:: spirv:: { Decoration , Op , Word } ;
10
9
use rustc_data_structures:: fx:: FxIndexMap ;
@@ -14,7 +13,6 @@ use rustc_span::{FileName, SourceFile};
14
13
use smallvec:: SmallVec ;
15
14
use std:: borrow:: Cow ;
16
15
use std:: marker:: PhantomData ;
17
- use std:: ops:: Range ;
18
16
use std:: path:: PathBuf ;
19
17
use std:: { fmt, iter, slice, str} ;
20
18
@@ -495,61 +493,18 @@ impl<'a> SpanRegenerator<'a> {
495
493
// called with `line`/`col` values that are near eachother - thankfully,
496
494
// this code should only be hit on the error reporting path anyway.
497
495
let line_col_to_bpos = |line : u32 , col : u32 | {
498
- let line_bpos_range = file. line_bounds ( line. checked_sub ( 1 ) ? as usize ) ;
499
-
500
- // Find the special cases (`MultiByteChar`s/`NonNarrowChar`s) in the line.
501
- let multibyte_chars = {
502
- let find = |bpos| {
503
- file. multibyte_chars
504
- . binary_search_by_key ( & file. relative_position ( bpos) , |mbc| mbc. pos )
505
- . unwrap_or_else ( |x| x)
506
- } ;
507
- let Range { start, end } = line_bpos_range;
508
- file. multibyte_chars [ find ( start) ..find ( end) ] . iter ( )
509
- } ;
510
- let non_narrow_chars = {
511
- let find = |bpos| {
512
- file. non_narrow_chars
513
- . binary_search_by_key ( & file. relative_position ( bpos) , |nnc| nnc. pos ( ) )
514
- . unwrap_or_else ( |x| x)
515
- } ;
516
- let Range { start, end } = line_bpos_range;
517
- file. non_narrow_chars [ find ( start) ..find ( end) ] . iter ( )
518
- } ;
519
- let mut special_chars = multibyte_chars
520
- . merge_join_by ( non_narrow_chars, |mbc, nnc| mbc. pos . cmp ( & nnc. pos ( ) ) )
521
- . peekable ( ) ;
522
-
523
- // Increment the `BytePos` until we reach the right `col_display`, using
524
- // `MultiByteChar`s/`NonNarrowChar`s to track non-trivial contributions
525
- // (this may look inefficient, but lines tend to be short, and `rustc`
526
- // itself is even worse than this, when it comes to `BytePos` lookups).
496
+ let line_idx_in_file = line. checked_sub ( 1 ) ? as usize ;
497
+ let line_bpos_range = file. line_bounds ( line_idx_in_file) ;
498
+ let line_contents = file. get_line ( line_idx_in_file) ?;
499
+
500
+ // Increment the `BytePos` until we reach the right `col_display`.
527
501
let ( mut cur_bpos, mut cur_col_display) = ( line_bpos_range. start , 0 ) ;
502
+ let mut line_chars = line_contents. chars ( ) ;
528
503
while cur_bpos < line_bpos_range. end && cur_col_display < col {
529
- let next_special_bpos = special_chars
530
- . peek ( )
531
- . map ( |special| {
532
- special
533
- . as_ref ( )
534
- . map_any ( |mbc| mbc. pos , |nnc| nnc. pos ( ) )
535
- . reduce ( |x, _| x)
536
- } )
537
- . map ( |rel_bpos| file. absolute_position ( rel_bpos) ) ;
538
-
539
- // Batch trivial chars (i.e. chars 1:1 wrt `BytePos` vs `col_display`).
540
- let following_trivial_chars =
541
- next_special_bpos. unwrap_or ( line_bpos_range. end ) . 0 - cur_bpos. 0 ;
542
- if following_trivial_chars > 0 {
543
- let wanted_trivial_chars = following_trivial_chars. min ( col - cur_col_display) ;
544
- cur_bpos. 0 += wanted_trivial_chars;
545
- cur_col_display += wanted_trivial_chars;
546
- continue ;
547
- }
548
-
549
- // Add a special char's `BytePos` and `col_display` contributions.
550
- let mbc_nnc = special_chars. next ( ) . unwrap ( ) ;
551
- cur_bpos. 0 += mbc_nnc. as_ref ( ) . left ( ) . map_or ( 1 , |mbc| mbc. bytes as u32 ) ;
552
- cur_col_display += mbc_nnc. as_ref ( ) . right ( ) . map_or ( 1 , |nnc| nnc. width ( ) as u32 ) ;
504
+ // Add each char's `BytePos` and `col_display` contributions.
505
+ let ch = line_chars. next ( ) ?;
506
+ cur_bpos. 0 += ch. len_utf8 ( ) as u32 ;
507
+ cur_col_display += rustc_span:: char_width ( ch) as u32 ;
553
508
}
554
509
Some ( cur_bpos)
555
510
} ;
0 commit comments