Skip to content

Commit 93fcf1c

Browse files
committed
Use mmap for proc macro libs
1 parent 69f0cb6 commit 93fcf1c

File tree

3 files changed

+17
-2
lines changed

3 files changed

+17
-2
lines changed

Cargo.lock

Lines changed: 11 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

crates/ra_proc_macro_srv/Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ ra_mbe = { path = "../ra_mbe" }
1414
ra_proc_macro = { path = "../ra_proc_macro" }
1515
goblin = "0.2.1"
1616
libloading = "0.6.0"
17+
memmap = "0.7"
1718
test_utils = { path = "../test_utils" }
1819

1920
[dev-dependencies]

crates/ra_proc_macro_srv/src/dylib.rs

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,12 @@
11
//! Handles dynamic library loading for proc macro
22
33
use crate::{proc_macro::bridge, rustc_server::TokenStream};
4+
use std::fs::File;
45
use std::path::Path;
56

67
use goblin::{mach::Mach, Object};
78
use libloading::Library;
9+
use memmap::Mmap;
810
use ra_proc_macro::ProcMacroKind;
911

1012
use std::io::Error as IoError;
@@ -21,7 +23,8 @@ fn is_derive_registrar_symbol(symbol: &str) -> bool {
2123
}
2224

2325
fn find_registrar_symbol(file: &Path) -> Result<Option<String>, IoError> {
24-
let buffer = std::fs::read(file)?;
26+
let file = File::open(file)?;
27+
let buffer = unsafe { Mmap::map(&file)? };
2528
let object = Object::parse(&buffer).map_err(invalid_data_err)?;
2629

2730
match object {
@@ -55,7 +58,7 @@ fn find_registrar_symbol(file: &Path) -> Result<Option<String>, IoError> {
5558
&s.name
5659
}
5760
})
58-
.find(|s| is_derive_registrar_symbol(&s))
61+
.find(|s| is_derive_registrar_symbol(s))
5962
.map(|s| s.to_string());
6063
Ok(name)
6164
}

0 commit comments

Comments
 (0)