Skip to content

Commit

Permalink
Improve performance by buffering I/O operations (#57)
Browse files Browse the repository at this point in the history
  • Loading branch information
ddoktorski authored Sep 25, 2024
1 parent fd6cab4 commit 9cc4dff
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 2 deletions.
3 changes: 3 additions & 0 deletions rust-toolchain.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
[toolchain]
channel = "1.79.0"
components = ["rustfmt", "clippy"]
7 changes: 5 additions & 2 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -33,17 +34,19 @@ fn print_error_message(error: &Error) {

fn read_json(file_path: PathBuf) -> Result<Value> {
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<PathBuf>) -> Result<()> {
match output_file_path {
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)?);
Expand Down

0 comments on commit 9cc4dff

Please sign in to comment.