Use buffered read and write for better performance
This commit is contained in:
parent
15c9ff3408
commit
0ccb7476d1
|
@ -33,22 +33,22 @@ const C_DECLARATIONS: FileDeclarations = FileDeclarations{include: "", var_typ
|
||||||
const CPP_DECLARATIONS: FileDeclarations = FileDeclarations{include: "#include <stdint.h>", var_type: "uint8_t"};
|
const CPP_DECLARATIONS: FileDeclarations = FileDeclarations{include: "#include <stdint.h>", var_type: "uint8_t"};
|
||||||
|
|
||||||
fn output_bytes(input: Input, output: &mut Output, line_feed: &str) -> Result<(), std::io::Error> {
|
fn output_bytes(input: Input, output: &mut Output, line_feed: &str) -> Result<(), std::io::Error> {
|
||||||
let mut byte_line_count = 1;
|
let mut byte_line_count = 0;
|
||||||
let mut bytes = input.bytes();
|
|
||||||
|
|
||||||
if let Some(byte) = bytes.next() {
|
write!(output, "\t")?;
|
||||||
write!(output, "\t{:#04X}", byte?)?;
|
for byte in input.bytes() {
|
||||||
|
if byte_line_count > 0 {
|
||||||
|
write!(output, ", ")?;
|
||||||
|
}
|
||||||
|
|
||||||
for byte in bytes {
|
write!(output, "{:#04X}", byte?)?;
|
||||||
write!(output, ", {:#04X}", byte?)?;
|
|
||||||
byte_line_count += 1;
|
byte_line_count += 1;
|
||||||
|
|
||||||
if byte_line_count >= 16 {
|
if byte_line_count >= 16 {
|
||||||
write!(output, "{}\t", line_feed)?;
|
write!(output, ",{}\t", line_feed)?;
|
||||||
byte_line_count = 0;
|
byte_line_count = 0;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
|
@ -76,15 +76,15 @@ impl std::convert::From<std::io::Error> for Error {
|
||||||
|
|
||||||
pub fn open_output(output_file: Option<PathBuf>) -> Result<Output, Error> {
|
pub fn open_output(output_file: Option<PathBuf>) -> Result<Output, Error> {
|
||||||
match output_file {
|
match output_file {
|
||||||
Some(output_path) => Ok(Box::new(std::fs::File::create(output_path)?)),
|
Some(output_path) => Ok(Box::new(std::io::BufWriter::new(std::fs::File::create(output_path)?))),
|
||||||
None => Ok(Box::new(std::io::stdout())),
|
None => Ok(Box::new(std::io::BufWriter::new(std::io::stdout()))),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn open_input(input_file: Option<PathBuf>) -> Result<Input, Error> {
|
pub fn open_input(input_file: Option<PathBuf>) -> Result<Input, Error> {
|
||||||
match input_file {
|
match input_file {
|
||||||
Some(input_path) => Ok(Box::new(std::fs::File::open(input_path)?)),
|
Some(input_path) => Ok(Box::new(std::io::BufReader::new(std::fs::File::open(input_path)?))),
|
||||||
None => Ok(Box::new(std::io::stdin())),
|
None => Ok(Box::new(std::io::BufReader::new(std::io::stdin()))),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue