From 79f583ed6622be591886f99974766a3aeda39182 Mon Sep 17 00:00:00 2001 From: Edwin Cheng Date: Wed, 24 Mar 2021 03:47:08 +0800 Subject: Improve message usage in proc-macro Reuse storage for the buffer send to child process of proc-macro. --- crates/proc_macro_srv/src/cli.rs | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) (limited to 'crates/proc_macro_srv/src') diff --git a/crates/proc_macro_srv/src/cli.rs b/crates/proc_macro_srv/src/cli.rs index d428b9567..bc48f1c43 100644 --- a/crates/proc_macro_srv/src/cli.rs +++ b/crates/proc_macro_srv/src/cli.rs @@ -6,8 +6,9 @@ use std::io; pub fn run() -> io::Result<()> { let mut srv = ProcMacroSrv::default(); + let mut buf = String::new(); - while let Some(req) = read_request()? { + while let Some(req) = read_request(&mut buf)? { let res = match req { msg::Request::ListMacro(task) => srv.list_macros(&task).map(msg::Response::ListMacro), msg::Request::ExpansionMacro(task) => { @@ -30,8 +31,8 @@ pub fn run() -> io::Result<()> { Ok(()) } -fn read_request() -> io::Result> { - msg::Request::read(&mut io::stdin().lock()) +fn read_request(buf: &mut String) -> io::Result> { + msg::Request::read(&mut io::stdin().lock(), buf) } fn write_response(msg: msg::Response) -> io::Result<()> { -- cgit v1.2.3