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 {
368368
369369 fn source_text ( & mut self , span : Span ) -> String {
370370 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.
371375 let ( & last_char_index, & last_byte_offset) = self
372376 . char_index_to_byte_offset
373377 . range ( ..=lo_char)
374378 . next_back ( )
375379 . unwrap_or ( ( & 0 , & 0 ) ) ;
380+
376381 let lo_byte = if last_char_index == lo_char {
377382 last_byte_offset
378383 } else {
@@ -387,6 +392,7 @@ impl FileInfo {
387392 . insert ( lo_char, total_byte_offset) ;
388393 total_byte_offset
389394 } ;
395+
390396 let trunc_lo = & self . source_text [ lo_byte..] ;
391397 let char_len = ( span. hi - span. lo ) as usize ;
392398 let source_text = match trunc_lo. char_indices ( ) . nth ( char_len) {
@@ -441,6 +447,7 @@ impl SourceMap {
441447 source_text : src. to_owned ( ) ,
442448 span,
443449 lines,
450+ // Populated lazily by source_text().
444451 char_index_to_byte_offset : BTreeMap :: new ( ) ,
445452 } ) ;
446453
You can’t perform that action at this time.
0 commit comments