@@ -211,8 +211,7 @@ impl CodeMap {
211
211
}
212
212
}
213
213
214
- /// Creates a new filemap without setting its line information. If you don't
215
- /// intend to set the line information yourself, you should use new_filemap_and_lines.
214
+ /// Creates a new filemap.
216
215
/// This does not ensure that only one FileMap exists per file name.
217
216
pub fn new_filemap ( & self , filename : FileName , src : String ) -> Lrc < FileMap > {
218
217
let start_pos = self . next_start_pos ( ) ;
@@ -247,22 +246,6 @@ impl CodeMap {
247
246
filemap
248
247
}
249
248
250
- /// Creates a new filemap and sets its line information.
251
- /// This does not ensure that only one FileMap exists per file name.
252
- pub fn new_filemap_and_lines ( & self , filename : & Path , src : & str ) -> Lrc < FileMap > {
253
- let fm = self . new_filemap ( filename. to_owned ( ) . into ( ) , src. to_owned ( ) ) ;
254
- let mut byte_pos: u32 = fm. start_pos . 0 ;
255
- for line in src. lines ( ) {
256
- // register the start of this line
257
- fm. next_line ( BytePos ( byte_pos) ) ;
258
-
259
- // update byte_pos to include this line and the \n at the end
260
- byte_pos += line. len ( ) as u32 + 1 ;
261
- }
262
- fm
263
- }
264
-
265
-
266
249
/// Allocates a new FileMap representing a source file from an external
267
250
/// crate. The source code of such an "imported filemap" is not available,
268
251
/// but we still know enough to generate accurate debuginfo location
@@ -305,9 +288,9 @@ impl CodeMap {
305
288
external_src : Lock :: new ( ExternalSource :: AbsentOk ) ,
306
289
start_pos,
307
290
end_pos,
308
- lines : Lock :: new ( file_local_lines) ,
309
- multibyte_chars : Lock :: new ( file_local_multibyte_chars) ,
310
- non_narrow_chars : Lock :: new ( file_local_non_narrow_chars) ,
291
+ lines : file_local_lines,
292
+ multibyte_chars : file_local_multibyte_chars,
293
+ non_narrow_chars : file_local_non_narrow_chars,
311
294
name_hash,
312
295
} ) ;
313
296
@@ -345,21 +328,22 @@ impl CodeMap {
345
328
match self . lookup_line ( pos) {
346
329
Ok ( FileMapAndLine { fm : f, line : a } ) => {
347
330
let line = a + 1 ; // Line numbers start at 1
348
- let linebpos = ( * f. lines . borrow ( ) ) [ a] ;
331
+ let linebpos = f. lines [ a] ;
349
332
let linechpos = self . bytepos_to_file_charpos ( linebpos) ;
350
333
let col = chpos - linechpos;
351
334
352
335
let col_display = {
353
- let non_narrow_chars = f. non_narrow_chars . borrow ( ) ;
354
- let start_width_idx = non_narrow_chars
336
+ let start_width_idx = f
337
+ . non_narrow_chars
355
338
. binary_search_by_key ( & linebpos, |x| x. pos ( ) )
356
339
. unwrap_or_else ( |x| x) ;
357
- let end_width_idx = non_narrow_chars
340
+ let end_width_idx = f
341
+ . non_narrow_chars
358
342
. binary_search_by_key ( & pos, |x| x. pos ( ) )
359
343
. unwrap_or_else ( |x| x) ;
360
344
let special_chars = end_width_idx - start_width_idx;
361
- let non_narrow: usize =
362
- non_narrow_chars[ start_width_idx..end_width_idx]
345
+ let non_narrow: usize = f
346
+ . non_narrow_chars [ start_width_idx..end_width_idx]
363
347
. into_iter ( )
364
348
. map ( |x| x. width ( ) )
365
349
. sum ( ) ;
@@ -380,12 +364,12 @@ impl CodeMap {
380
364
}
381
365
Err ( f) => {
382
366
let col_display = {
383
- let non_narrow_chars = f. non_narrow_chars . borrow ( ) ;
384
- let end_width_idx = non_narrow_chars
367
+ let end_width_idx = f
368
+ . non_narrow_chars
385
369
. binary_search_by_key ( & pos, |x| x. pos ( ) )
386
370
. unwrap_or_else ( |x| x) ;
387
- let non_narrow: usize =
388
- non_narrow_chars[ 0 ..end_width_idx]
371
+ let non_narrow: usize = f
372
+ . non_narrow_chars [ 0 ..end_width_idx]
389
373
. into_iter ( )
390
374
. map ( |x| x. width ( ) )
391
375
. sum ( ) ;
@@ -830,7 +814,7 @@ impl CodeMap {
830
814
// The number of extra bytes due to multibyte chars in the FileMap
831
815
let mut total_extra_bytes = 0 ;
832
816
833
- for mbc in map. multibyte_chars . borrow ( ) . iter ( ) {
817
+ for mbc in map. multibyte_chars . iter ( ) {
834
818
debug ! ( "{}-byte char at {:?}" , mbc. bytes, mbc. pos) ;
835
819
if mbc. pos < bpos {
836
820
// every character is at least one byte, so we only
@@ -1124,7 +1108,7 @@ mod tests {
1124
1108
let cm = CodeMap :: new ( FilePathMapping :: empty ( ) ) ;
1125
1109
let inputtext = "aaaaa\n bbbbBB\n CCC\n DDDDDddddd\n eee\n " ;
1126
1110
let selection = " \n ~~\n ~~~\n ~~~~~ \n \n " ;
1127
- cm. new_filemap_and_lines ( Path :: new ( "blork.rs" ) , inputtext) ;
1111
+ cm. new_filemap ( Path :: new ( "blork.rs" ) . to_owned ( ) . into ( ) , inputtext. to_string ( ) ) ;
1128
1112
let span = span_from_selection ( inputtext, selection) ;
1129
1113
1130
1114
// check that we are extracting the text we thought we were extracting
@@ -1167,7 +1151,7 @@ mod tests {
1167
1151
let inputtext = "bbbb BB\n cc CCC\n " ;
1168
1152
let selection1 = " ~~\n \n " ;
1169
1153
let selection2 = " \n ~~~\n " ;
1170
- cm. new_filemap_and_lines ( Path :: new ( "blork.rs" ) , inputtext) ;
1154
+ cm. new_filemap ( Path :: new ( "blork.rs" ) . to_owned ( ) . into ( ) , inputtext. to_owned ( ) ) ;
1171
1155
let span1 = span_from_selection ( inputtext, selection1) ;
1172
1156
let span2 = span_from_selection ( inputtext, selection2) ;
1173
1157
0 commit comments