Use buffered read and write for better performance
This commit is contained in:
@@ -32,21 +32,21 @@ const WINDOWS_LINEFEED: &'static str = "\r\n";
|
||||
const C_DECLARATIONS: FileDeclarations = FileDeclarations{include: "", var_type: "char"};
|
||||
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> {
|
||||
let mut byte_line_count = 1;
|
||||
let mut bytes = input.bytes();
|
||||
fn output_bytes(input: Input, output: &mut Output, line_feed: &str) -> Result<(), std::io::Error> {
|
||||
let mut byte_line_count = 0;
|
||||
|
||||
if let Some(byte) = bytes.next() {
|
||||
write!(output, "\t{:#04X}", byte?)?;
|
||||
write!(output, "\t")?;
|
||||
for byte in input.bytes() {
|
||||
if byte_line_count > 0 {
|
||||
write!(output, ", ")?;
|
||||
}
|
||||
|
||||
for byte in bytes {
|
||||
write!(output, ", {:#04X}", byte?)?;
|
||||
byte_line_count += 1;
|
||||
write!(output, "{:#04X}", byte?)?;
|
||||
byte_line_count += 1;
|
||||
|
||||
if byte_line_count >= 16 {
|
||||
write!(output, "{}\t", line_feed)?;
|
||||
byte_line_count = 0;
|
||||
}
|
||||
if byte_line_count >= 16 {
|
||||
write!(output, ",{}\t", line_feed)?;
|
||||
byte_line_count = 0;
|
||||
}
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user