From 9cc4dff49912dbaa37ea3e40749c82a9574a9c4a Mon Sep 17 00:00:00 2001 From: ddoktorski <45050160+ddoktorski@users.noreply.github.com> Date: Wed, 25 Sep 2024 17:05:36 +0200 Subject: [PATCH] Improve performance by buffering I/O operations (#57) --- rust-toolchain.toml | 3 +++ src/main.rs | 7 +++++-- 2 files changed, 8 insertions(+), 2 deletions(-) create mode 100644 rust-toolchain.toml diff --git a/rust-toolchain.toml b/rust-toolchain.toml new file mode 100644 index 0000000..8749391 --- /dev/null +++ b/rust-toolchain.toml @@ -0,0 +1,3 @@ +[toolchain] +channel = "1.79.0" +components = ["rustfmt", "clippy"] diff --git a/src/main.rs b/src/main.rs index 82ddc0a..5dbffbc 100644 --- a/src/main.rs +++ b/src/main.rs @@ -3,6 +3,7 @@ use clap::{Parser, Subcommand}; use console::style; use serde_json::{to_writer, Value}; use std::fs::File; +use std::io::{BufReader, BufWriter}; use std::path::PathBuf; mod commands; @@ -33,8 +34,9 @@ fn print_error_message(error: &Error) { fn read_json(file_path: PathBuf) -> Result { let sierra_file = File::open(file_path).context("Unable to open json file")?; + let sierra_file_reader = BufReader::new(sierra_file); - serde_json::from_reader(sierra_file).context("Unable to read json file") + serde_json::from_reader(sierra_file_reader).context("Unable to read json file") } fn output_casm(output_json: &Value, output_file_path: Option) -> Result<()> { @@ -42,8 +44,9 @@ fn output_casm(output_json: &Value, output_file_path: Option) -> Result Some(output_path) => { let casm_file = File::create(output_path).context("Unable to open/create casm json file")?; + let casm_file_writer = BufWriter::new(casm_file); - to_writer(casm_file, &output_json).context("Unable to save casm json file")?; + to_writer(casm_file_writer, &output_json).context("Unable to save casm json file")?; } None => { println!("{}", serde_json::to_string(&output_json)?);