|
12 | 12 | use std::io::{self, BorrowedBuf, Read};
|
13 | 13 | use std::{fs, path};
|
14 | 14 |
|
| 15 | +use rustc_data_structures::fx::StdEntry; |
15 | 16 | use rustc_data_structures::sync::{IntoDynSyncSend, MappedReadGuard, ReadGuard, RwLock};
|
16 | 17 | use rustc_data_structures::unhash::UnhashMap;
|
17 | 18 | use rustc_macros::{Decodable, Encodable};
|
@@ -282,20 +283,24 @@ impl SourceMap {
|
282 | 283 | mut file: SourceFile,
|
283 | 284 | ) -> Result<Arc<SourceFile>, OffsetOverflowError> {
|
284 | 285 | let mut files = self.files.borrow_mut();
|
| 286 | + let SourceMapFiles { source_files, stable_id_to_source_file } = &mut *files; |
| 287 | + let file = match stable_id_to_source_file.entry(file_id) { |
| 288 | + StdEntry::Occupied(o) => o.into_mut(), |
| 289 | + StdEntry::Vacant(v) => { |
| 290 | + file.start_pos = BytePos(if let Some(last_file) = source_files.last() { |
| 291 | + // Add one so there is some space between files. This lets us distinguish |
| 292 | + // positions in the `SourceMap`, even in the presence of zero-length files. |
| 293 | + last_file.end_position().0.checked_add(1).ok_or(OffsetOverflowError)? |
| 294 | + } else { |
| 295 | + 0 |
| 296 | + }); |
285 | 297 |
|
286 |
| - file.start_pos = BytePos(if let Some(last_file) = files.source_files.last() { |
287 |
| - // Add one so there is some space between files. This lets us distinguish |
288 |
| - // positions in the `SourceMap`, even in the presence of zero-length files. |
289 |
| - last_file.end_position().0.checked_add(1).ok_or(OffsetOverflowError)? |
290 |
| - } else { |
291 |
| - 0 |
292 |
| - }); |
293 |
| - |
294 |
| - let file = Arc::new(file); |
295 |
| - files.source_files.push(Arc::clone(&file)); |
296 |
| - files.stable_id_to_source_file.insert(file_id, Arc::clone(&file)); |
297 |
| - |
298 |
| - Ok(file) |
| 298 | + let file = Arc::new(file); |
| 299 | + source_files.push(file.clone()); |
| 300 | + v.insert(file) |
| 301 | + } |
| 302 | + }; |
| 303 | + Ok(Arc::clone(file)) |
299 | 304 | }
|
300 | 305 |
|
301 | 306 | /// Creates a new `SourceFile`.
|
|
0 commit comments