File tree Expand file tree Collapse file tree 1 file changed +7
-0
lines changed Expand file tree Collapse file tree 1 file changed +7
-0
lines changed Original file line number Diff line number Diff line change @@ -368,11 +368,16 @@ impl FileInfo {
368
368
369
369
fn source_text ( & mut self , span : Span ) -> String {
370
370
let lo_char = ( span. lo - self . span . lo ) as usize ;
371
+
372
+ // Look up offset of the largest already-computed char index that is
373
+ // less than or equal to the current requested one. We resume counting
374
+ // chars from that point.
371
375
let ( & last_char_index, & last_byte_offset) = self
372
376
. char_index_to_byte_offset
373
377
. range ( ..=lo_char)
374
378
. next_back ( )
375
379
. unwrap_or ( ( & 0 , & 0 ) ) ;
380
+
376
381
let lo_byte = if last_char_index == lo_char {
377
382
last_byte_offset
378
383
} else {
@@ -387,6 +392,7 @@ impl FileInfo {
387
392
. insert ( lo_char, total_byte_offset) ;
388
393
total_byte_offset
389
394
} ;
395
+
390
396
let trunc_lo = & self . source_text [ lo_byte..] ;
391
397
let char_len = ( span. hi - span. lo ) as usize ;
392
398
let source_text = match trunc_lo. char_indices ( ) . nth ( char_len) {
@@ -441,6 +447,7 @@ impl SourceMap {
441
447
source_text : src. to_owned ( ) ,
442
448
span,
443
449
lines,
450
+ // Populated lazily by source_text().
444
451
char_index_to_byte_offset : BTreeMap :: new ( ) ,
445
452
} ) ;
446
453
You can’t perform that action at this time.
0 commit comments