From 93fcf1c133f1a473ac598e4811e88ee91d979510 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lauren=C8=9Biu=20Nicola?= Date: Fri, 17 Apr 2020 10:47:15 +0300 Subject: Use mmap for proc macro libs --- crates/ra_proc_macro_srv/Cargo.toml | 1 + crates/ra_proc_macro_srv/src/dylib.rs | 7 +++++-- 2 files changed, 6 insertions(+), 2 deletions(-) (limited to 'crates/ra_proc_macro_srv') diff --git a/crates/ra_proc_macro_srv/Cargo.toml b/crates/ra_proc_macro_srv/Cargo.toml index 1e0f50339..ac2d156dc 100644 --- a/crates/ra_proc_macro_srv/Cargo.toml +++ b/crates/ra_proc_macro_srv/Cargo.toml @@ -14,6 +14,7 @@ ra_mbe = { path = "../ra_mbe" } ra_proc_macro = { path = "../ra_proc_macro" } goblin = "0.2.1" libloading = "0.6.0" +memmap = "0.7" test_utils = { path = "../test_utils" } [dev-dependencies] diff --git a/crates/ra_proc_macro_srv/src/dylib.rs b/crates/ra_proc_macro_srv/src/dylib.rs index 7d6e5d323..16bd7466e 100644 --- a/crates/ra_proc_macro_srv/src/dylib.rs +++ b/crates/ra_proc_macro_srv/src/dylib.rs @@ -1,10 +1,12 @@ //! Handles dynamic library loading for proc macro use crate::{proc_macro::bridge, rustc_server::TokenStream}; +use std::fs::File; use std::path::Path; use goblin::{mach::Mach, Object}; use libloading::Library; +use memmap::Mmap; use ra_proc_macro::ProcMacroKind; use std::io::Error as IoError; @@ -21,7 +23,8 @@ fn is_derive_registrar_symbol(symbol: &str) -> bool { } fn find_registrar_symbol(file: &Path) -> Result, IoError> { - let buffer = std::fs::read(file)?; + let file = File::open(file)?; + let buffer = unsafe { Mmap::map(&file)? }; let object = Object::parse(&buffer).map_err(invalid_data_err)?; match object { @@ -55,7 +58,7 @@ fn find_registrar_symbol(file: &Path) -> Result, IoError> { &s.name } }) - .find(|s| is_derive_registrar_symbol(&s)) + .find(|s| is_derive_registrar_symbol(s)) .map(|s| s.to_string()); Ok(name) } -- cgit v1.2.3