Skip to content

Commit

Permalink
Make a minor improvement
Browse files Browse the repository at this point in the history
  • Loading branch information
sonmarcho committed Oct 2, 2024
1 parent e595921 commit 18e3a2b
Showing 1 changed file with 8 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -361,7 +361,7 @@ impl<'tcx, 'ctx> TranslateCtx<'tcx, 'ctx> {
}

/// Return a map from source file name to file content.
fn read_source_files(&mut self) -> HashMap<FileName, String> {
fn read_source_files(&mut self) -> HashMap<FileName, Arc<String>> {
// Retrieve the source map
let source_map = self.tcx.sess.source_map();

Expand All @@ -377,7 +377,7 @@ impl<'tcx, 'ctx> TranslateCtx<'tcx, 'ctx> {
let filename = self.translate_filename(&filename);

// Retrieve the content
file.src.as_ref().map(|src| (filename, src.deref().clone()))
file.src.as_ref().map(|src| (filename, src.clone()))
})
.collect()
}
Expand Down Expand Up @@ -477,11 +477,16 @@ pub fn translate<'tcx, 'ctx>(options: &CliOpts, tcx: TyCtxt<'tcx>) -> TransformC

// Read the source files
let source_files = ctx.read_source_files();
use std::ops::Deref;
ctx.translated.file_id_to_content = ctx
.translated
.id_to_file
.iter_indexed()
.filter_map(|(id, filename)| (source_files.get(filename).map(|file| (id, file.clone()))))
.filter_map(|(id, filename)| {
source_files
.get(filename)
.map(|file| (id, file.deref().clone()))
})
.collect();

// Return the context, dropping the hax state and rustc `tcx`.
Expand Down

0 comments on commit 18e3a2b

Please sign in to comment.