From 741ca1af1e1c08aacb633d174f555926dd456900 Mon Sep 17 00:00:00 2001 From: Jordan Mackie Date: Wed, 8 Feb 2023 21:44:18 +0000 Subject: [PATCH] =?UTF-8?q?Use=20BufReader=20and=20BufWriter=20?= =?UTF-8?q?=F0=9F=A4=A6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- crates/ditto-make/src/compile.rs | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/crates/ditto-make/src/compile.rs b/crates/ditto-make/src/compile.rs index 753811e21..80ee8bb6b 100644 --- a/crates/ditto-make/src/compile.rs +++ b/crates/ditto-make/src/compile.rs @@ -128,7 +128,7 @@ fn run_ast(build_dir: &str, inputs: Vec, outputs: Vec) -> Result let path = Path::new(&input); match full_extension(path) { Some(common::EXTENSION_DITTO) => { - let mut file = File::open(path).into_diagnostic()?; + let mut file = std::io::BufReader::new(File::open(path).into_diagnostic()?); let mut contents = String::new(); file.read_to_string(&mut contents).into_diagnostic()?; ditto_input = Some((path.to_string_lossy().into_owned(), contents)); @@ -219,14 +219,17 @@ fn run_ast(build_dir: &str, inputs: Vec, outputs: Vec) -> Result match full_extension(path) { Some(common::EXTENSION_AST) => { let file = File::create(path).into_diagnostic()?; - common::serialize(file, &(&ditto_input_name, &ast))?; + let writer = std::io::BufWriter::new(file); + common::serialize(writer, &(&ditto_input_name, &ast))?; } Some(common::EXTENSION_AST_EXPORTS) => { let file = File::create(path).into_diagnostic()?; - common::serialize(file, &(&ast.module_name, &ast.exports))?; + let writer = std::io::BufWriter::new(file); + common::serialize(writer, &(&ast.module_name, &ast.exports))?; } Some(common::EXTENSION_CHECKER_WARNINGS) => { let file = File::create(path).into_diagnostic()?; + let writer = std::io::BufWriter::new(file); let warnings_bundle = if warnings.is_empty() { None } else { @@ -236,7 +239,7 @@ fn run_ast(build_dir: &str, inputs: Vec, outputs: Vec) -> Result warnings: warnings.clone(), }) }; - common::serialize(file, &warnings_bundle)?; + common::serialize(writer, &warnings_bundle)?; print_warnings = false; } other => panic!("unexpected output extension: {:#?}", other), @@ -336,7 +339,7 @@ fn run_js(inputs: Vec, outputs: Vec) -> Result<()> { js::codegen(&codegen_config, ast) }; - let mut js_file = File::create(&js_output_path).into_diagnostic()?; + let mut js_file = std::io::BufWriter::new(File::create(&js_output_path).into_diagnostic()?); js_file.write_all(js.as_bytes()).into_diagnostic()?; Ok(()) @@ -372,7 +375,8 @@ fn run_package_json(input: &str, output: &str) -> Result<()> { } let file = File::create(output).into_diagnostic()?; - return serde_json::to_writer(file, &object).into_diagnostic(); + let writer = std::io::BufWriter::new(file); + return serde_json::to_writer(writer, &object).into_diagnostic(); type Object = Map; fn merge_objects(mut lhs: Object, mut rhs: Object) -> Object {